Jump to content

Coin Toss


diggerjohn4
 Share

You are about to reply to a thread that has been inactive for 4696 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

The basis for a simple coin toss game will be the llFrand function, with which you can generate a random number.  In this case, since you're looking foir either a 0 or a 1, you'll want to build around

integer Coin_Flip = llRound(llFrand(1.0));

 The rest of your script is just packaging.

Link to comment
Share on other sites

Good.  From there it's pretty easy.   :smileyhappy:

At least while you are testing, I suggest building a failsafe into your script to keep track of where the flipped coin went.  Physical objects have a way of vanishing in a flash if you zap them with too much force.  You can lose stuff quickly (and annoy your neighbors).  I like creating a simple homing routine on a two-second timer. If the coin is more than X meters away when the timer fires, the object goes non-physical and comes home.

Link to comment
Share on other sites

Ah yes, case in point.

What I need to do is keep this coin from going away.

I am trying to get it to go straight up and down.

So I need to restrict its natural parabola.

Not sure how just yet.

I assume that the homing device works off of llGetPos to get the current/initial postion and then using llSetPos to  put it

  back.

Link to comment
Share on other sites

It's not easy to make a physical object follow a predicatable path, so good luck getting it to go straight up and down. If you don't overdo the flip, though, it won't go far.

llSetPos has a 10m limit, so it's not much good for catching something that takes off halfway to the Moon.  You'll have to use WarpPos or PosJump.  Try something like

safe_posJump(vector target_pos){      vector start_pos = llGetPos();    llSetLinkPrimitiveParamsFast(!!llGetLinkNumber(), [PRIM_POSITION, <1.304382E+19, 1.304382E+19, 0.0>, PRIM_POSITION, target_pos, PRIM_POSITION, start_pos, PRIM_POSITION, target_pos]);    llResetScript();}vector Home;default{    state_entry()    {       llSetStatus(STATUS_PHYSICS,TRUE);       Home = llGetPos();    }        touch_start(integer num)    {        llSetTimerEvent(3.0);        llApplyRotationalImpulse(<0.0005,0.0005,0>,TRUE);     }        timer() // This is your safeguard, just in case the coin gets away.    {        if (llVecDist(llGetPos(),Home) > 10.0)        {            llSetStatus(STATUS_PHYSICS,FALSE);            safe_posJump(Home);        }    }}

 

  • Like 1
Link to comment
Share on other sites

  • 3 weeks later...

You can't predict which way the coin will land because that's all up to the physics of the toss.  You can use this idea to tell which end is up after the fact, though ......

default{    touch_start(integer total_number)    {        vector Up = llRot2Up(llGetRot());        if (Up.z > 0.0)        {            llSay(0, "heads");        }        else        {            llSay(0,"Tails");        }    }}

Instead of putting it in a touch_start event, you could trigger it with a timer a few seconds after the toss (so that it has time to bounce a few times and come to rest).  Record the result in a list or whatever you want to do.

Now, you could always use this as a way to bias the outcome, I suppose.  If the coin lands with tails, for example, you could script it to flip again gently one time, thus biasing the result toward heads.  If that's what you meant by "rigging" the coin, you never heard me suggest it.

Link to comment
Share on other sites

Yes of course.

Maybe what I could do is change the texture, once I know what side it has landed on, to reflect the

  the side I wanted it to be.

I want to try to hide the fact I am rigging the result of course as much as can be done.

Thank you ...

BTW, your by line troubles me but I get it.  You certainly are not dumb and I sincerely doubt you look it either.

Thanks again.

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 4696 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...