Chance

About advanced scenes, and the Thyme scripting language used in Algodoo.

Chance

Postby Dadasas » Thu Jan 28, 2010 4:08 am

Is it possible to say IN ONE with no other items oncollide script?
(e)=>{ {50% ? {color = [1,1,1,1]} 50% ? {color = [1,0,0,1]}}}

Thanks
User avatar
Dadasas
 
Posts: 46
Joined: Tue Sep 01, 2009 2:03 am

Re: Chance

Postby KarateBrot » Thu Jan 28, 2010 4:13 am

the function consists of IF ? THEN : ELSE without exceptions. You can't just type IF ? THEN
But You can just type empty brackets so it's like there's no ELSE. For example
Code: Select all
velocity == 50 ? {blahblah} : { }


And if you're asking about the percent thing in the IF part:
There needs to be something to compare so algodoo knows to which variable the 50% belongs to. if it's alone without anything else it just doesn't make any sense.
The only thing where a variable doesn't need an equation in the IF part is a boolean variable. any equation in the IF part gets translated to boolean. it says if the equation is "true" or "false". if there's already a boolean value it doesn't need an equation anymore.

For example if you've got a variable crazy = true you can do this:
Code: Select all
crazy ? { do crazy stuff } : { do boring stuff }

because crazy is true algodoo will do crazy stuff. if crazy was false it would have done boring stuff.
Image
User avatar
KarateBrot
 
Posts: 825
Joined: Mon Aug 31, 2009 7:32 pm
Location: Germany

Re: Chance

Postby Dadasas » Thu Jan 28, 2010 4:14 pm

I know I typed it wrong, but is there a simple way to make it a 100 to 0.001% chance of some thing happening in one script?
User avatar
Dadasas
 
Posts: 46
Joined: Tue Sep 01, 2009 2:03 am

Re: Chance

Postby KarateBrot » Thu Jan 28, 2010 7:57 pm

I don't think you can do it with built in stuff but I already have got an idea how to do it. I just need to do some tests to proof if it will be the correct chance.

Edit:
Alright. It seems to work.
Code: Select all
scene.my.memory = 17;

scene.my.random = (min, max)=> { x := scene.my.memory; m := 1249 * 373; x = x ^ 2 % m; x == 0 ? {scene.my.memory = x + 1} : {scene.my.memory = x}; x * (max - min) / (1249 * 373.0) + min };

scene.my.chance = (x) => { scene.my.random(0,1) <= x ? {true} : {false} }

I once made a random function and that's perfect for this. Now if algodoo executes scene.my.chance it checks if a random number between 0 and 1 is less than or equal your desired chance. If it's less than or equal the output will be "true". Otherwise it will be "false".

Now you can use it this way for example with a chance of 0.25 (25%):
Code: Select all
scene.my.chance(0.25) ? { do this with a chance of 25% } : { do this with a chance of 75% }
Image
User avatar
KarateBrot
 
Posts: 825
Joined: Mon Aug 31, 2009 7:32 pm
Location: Germany

Re: Chance

Postby PlanckBanck » Thu Jan 28, 2010 10:24 pm

I would have spawned a circle, read that one`s color and use just the built in randomness instead of making an own function... but maths is fun!xD
The world is a gas-station, where you`re allowed to smoke. -Friedrich Dürrenmatt

I forgot 2/3 of my scripting knowledge T.T
User avatar
PlanckBanck
 
Posts: 48
Joined: Sun Nov 22, 2009 5:35 pm
Location: In the Bottoms of Berlin

Re: Chance

Postby KarateBrot » Fri Jan 29, 2010 2:26 pm

but then you have to build something that does this kind of thing. it's much faster to just copy and paste this function into the console and you're done. And it's freakin fast i discovered. for example if you type in scene.my.random(0,1); scene.my.random(0,1) in a row both numbers aren't the same
Image
User avatar
KarateBrot
 
Posts: 825
Joined: Mon Aug 31, 2009 7:32 pm
Location: Germany


Return to Thyme scripting

Who is online

Users browsing this forum: No registered users and 4 guests

cron