Constantly updating a value, having issues

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

Constantly updating a value, having issues

Postby grantypoo » Thu May 26, 2016 3:14 am

I have an array that is constantly updating. I'm got an object that in poststep says scene.my.vel = vel

So when the object is stopped moving horizontally, scene.my.vel[0] is 0
When it is moving horizontally, scene.my.vel[0] = something greater than 0

I have a text block where the text part of the script is simply scene.my.vel[0] and so I can see that nonstop the scene.my.vel[0] is changing.

However, I cant see to do an if/then statement off it. Am I putting it in the wrong spot?

On a thruster, I have scene.my.leftt as the thrust amount in the scripting menu.

On my object, in post step, I want to say (e)=>{scene.my.vel[0] > 1 ? {scene.my.leftt= 5} : {scene.my.leftt = 10}

In english, it's stating if the horizontal velocity is greater than 1, then left thrust should be set to 5, else to 10.

It's not working... the code compiles and goes in, but scene.my.leftt never changes from 6, which is just a value I typed in to the console at some point just making sure it worked.

Any idea?
grantypoo
 
Posts: 36
Joined: Sat Apr 30, 2016 1:46 am

Re: Constantly updating a value, having issues

Postby grantypoo » Fri May 27, 2016 12:48 am

Is there an issue with updating a value based off an array?

I made a simple { scene.my.leftt > 5 ? 3 : 5 } set of code on a hinge's bend target, and it works just fine. Currently scene.my.leftt = 6, so it changes the bend target to 3.

If I change scene.my.velocity to be in the place of scene.my.leftt, the code doesnt compile and boom, it reverts back to last know good value on the bend target.

scene.my.velocity is the horizontal velocity of an object, btw. I have in post step on a block the line {scene.my.velocity = vel[0]}. Seems like if I read from an array, it will not work... what gives? I can do text on a block with the code block for text stating "Horizontal velocity" + {scene.my.velocity} and it works just fine and is nonstop updating the value. So I know the value is good, but I cant seem to do a bend target or a thruster off it.
grantypoo
 
Posts: 36
Joined: Sat Apr 30, 2016 1:46 am

Re: Constantly updating a value, having issues

Postby grantypoo » Sat May 28, 2016 9:48 pm

[scene]133012[/scene]

Can you download this scene and see if you can help me? This is just a sample that hopefully explains the problem and it sets up the scene so you can play with the values easily without having to set it all up yourself.

End goal, make the left thrust take an action based off what scene.my.velocity[0] is reporting back.

scene.my.velocity is set on the red rectangle, it is on poststep and says {Scene.my.velocity = vel}, so very simple.
grantypoo
 
Posts: 36
Joined: Sat Apr 30, 2016 1:46 am

Re: Constantly updating a value, having issues

Postby grantypoo » Mon May 30, 2016 10:07 pm

Well, no replies, so either no one is reading these threads anymore which is highly likely just from gauging the activity level on the forum...

I figured out the solution by downloading a ton of other scenes on Algobox and hoping I'd eventually find what I was looking for. Man, it's hard to find code sometimes on someone elses scenes, I wish there was a way to list out everything being done to go through it more easily.

What I ended up needing to do was not use square brackets around the array number, so for instance scene.my.vel = vel[0] doesnt work for things like thrusters, although it does for a text box. However, using parenthesis does work. So in the end, I've changed all my square brackets over to ( ) and it updates my thrusters on the fly, which is what I needed.

scene.my.vel = vel(0) works great.
grantypoo
 
Posts: 36
Joined: Sat Apr 30, 2016 1:46 am


Return to Thyme scripting

Who is online

Users browsing this forum: No registered users and 4 guests