Need help with simple script

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

Need help with simple script

Postby Rideg » Tue Dec 15, 2009 5:30 pm

Hello. i've just beggining to understand how to script simple codes but I need help with binding a varaible to a object. I created a varable (scene.my.position) and want a box that is fixated on the moving "car", to show the value of scene.my.position. Please help me

//Rideg
Image
make sure to check out my work.
User avatar
Rideg
 
Posts: 948
Joined: Tue Dec 15, 2009 5:17 pm
Location: Östersund, Sweden

Re: Need help with simple script

Postby KarateBrot » Tue Dec 15, 2009 6:06 pm

Ok you nearly completed it.
So now that you created scene.my.position, fixate the box to the car and make a circle next to the box. now attach the circle wit a hinge somewhere but not in the center. make the hinge a motor with +inf strength and a speed of 600rpm. the circle should now collide very often with the circle when you playback the simulation.
now go to the scripting menu of the box. you can see a line with "onCollide =" where you type in:
Code: Select all
(e) => { scene.my.position = e.pos }


So now every time the circle collides with the box the position of the collision event will be stored to scene.my.position.
Image
User avatar
KarateBrot
 
Posts: 825
Joined: Mon Aug 31, 2009 7:32 pm
Location: Germany

Re: Need help with simple script

Postby Rideg » Tue Dec 15, 2009 6:14 pm

thank you;)
Image
make sure to check out my work.
User avatar
Rideg
 
Posts: 948
Joined: Tue Dec 15, 2009 5:17 pm
Location: Östersund, Sweden

Re: Need help with simple script

Postby standardtoaster » Tue Dec 15, 2009 6:21 pm

Another way to do it is using the text variable in the box. Find the text part of the script menu of the box and put:
Code: Select all
{scene.my.position}

That will be constantly updated with scene.my.position and you don't have to make it collide with anything!
User avatar
standardtoaster
 
Posts: 606
Joined: Mon Aug 31, 2009 7:57 pm


Return to Thyme scripting

Who is online

Users browsing this forum: No registered users and 3 guests