How do I read only the speed on x-axis?

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

How do I read only the speed on x-axis?

Postby RpT » Sat Jun 22, 2013 10:37 am

Hi guys, I've been trying to make a new kind of suspension for cars and I need to determine the speed on only just one axis so that, then I can calculate the overall speed.
So my question is how to "extract" only the first variable from the velocity[x,y] of an object?
Thank you electronicboy and Xray for answering me!
Last edited by RpT on Tue Aug 27, 2013 6:46 pm, edited 1 time in total.
Țăranul se uită la pământ și pământul la țăran..dacă are pământ, dacă nu, atunci nu!

:lol:
RpT
 
Posts: 11
Joined: Sun Oct 02, 2011 4:45 pm

Re: How do I read only the speed on x-axis?

Postby electronicboy » Sat Jun 22, 2013 12:08 pm

Arrays are done so that the first value is position 0, so, x - 0 and y - 1.

An example:
Scene.my.a = [1, 2, 3,]

Reading: scene.my.a(0) = 1
Reading: scene.my.a(1) = 2
When asking for help, READ THE STICKIES!
electronicboy
 
Posts: 1694
Joined: Mon Aug 31, 2009 6:18 pm

Re: How do I read only the speed on x-axis?

Postby Xray » Tue Jun 25, 2013 12:56 am

RpT wrote:So my question is how to "extract" only the first variable from the velocity[x,y] of an object?


For your specific example, it would be velocity(0)

The code would look something like this: scene.my.velX = velocity(0).

Unfortunately, you can only read an array element using an index. You cannot write to a single array element. For example, you CANNOT do velocity(0) = scene.my.velX. Many of us Thyme scripters have been begging for this fix for a long time, but it seems to fall on deaf ears. :x
User avatar
Xray
 
Posts: 501
Joined: Sun Jun 17, 2012 6:12 am
Location: USA


Return to Thyme scripting

Who is online

Users browsing this forum: No registered users and 3 guests