Page 1 of 1

Script help! Please help, my scripts become values?

PostPosted: Sun Dec 20, 2009 3:06 pm
by Rrobba
Ok, what happens is my scripts become the values that they are worth. Exampe:

I type 'scene.my.speed = 0.0' in the console.

Then I type '(e)=>{scene.my.speed = 2.5}' in the on-collide section of a polygon.

Then, I make a vehicle, and type 'scene.my.speed' in the motor speed section of the hinge, so that the speed of the vehicle is equal to the value of the variable 'scene.my.speed'.

So, the speed of the vehicle is 0.0 at the start, and should become 2.5 when the polygon collides. But this doesn't happen. Instead, when I type 'scene.my.speed' in the motor speed section, the motor speed becomes 0.0, and is no longer scene.my.speed, so it doesn't change to 2.5 when the polygon collides. Why does this happen? And more importantly, how can I fix this?

Re: Script help! Please help, my scripts become values?

PostPosted: Sun Dec 20, 2009 3:08 pm
by KarateBrot
Put the code into { } brackets. they tell that your variable is a variable and not only a constant.

Code: Select all
{scene.my.speed}

Re: Script help! Please help, my scripts become values?

PostPosted: Sun Dec 20, 2009 6:05 pm
by Rrobba
KarateBrot wrote:Put the code into { } brackets. they tell that your variable is a variable and not only a constant.

Code: Select all
{scene.my.speed}


Thanks!

Re: Script help! Please help, my scripts become values?

PostPosted: Sun Dec 20, 2009 11:39 pm
by KarateBrot
No problem :thumbup:

You can also do this with variables so they update themselves without a need of onCollide or Lasers. For example
Code: Select all
scene.my.difference = { 3 - scene.my.number }

If you change scene.my.number scene.my.difference changes automatically according to scene.my.number. if scene.my.number is 10 scene.my.difference will be automatically -7