Arrays

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

Arrays

Postby LShome » Wed Nov 17, 2010 7:03 pm

I need help.

I desperate when I was trying to assume a value to an array.
What I did was this:

console

scene.my.bar = [0,0,0,0]

when I try to access value 0 of the array it outputs 0
scene.my.bar(0)
0


now, when I try to assume value numer 0 a new value it gives me an error:
scene.my.bar(0) = 1
[...]Bad placement of '1'[...]


do i have to do this:
scene.my.bar = [1,scene.my.bar(1),scene.my.bar(2),scene.my.bar(3)]
[1,0,0,0]



or i just do it wrong?


thanks.

I dont need this for just 4 values.. I just dont want to change this for 16 different lasers:

e.geom.color == [1,1,1,1] ? { scene.my.bar = [scene.my.bar(0),1,scene.my.bar

(2),scene.my.bar(3),scene.my.bar(4),scene.my.bar(5),scene.my.bar(6),scene.my.bar

(7),scene.my.bar(8),scene.my.bar(9),scene.my.bar(10),scene.my.bar(11),scene.my.bar

(12),scene.my.bar(13),scene.my.bar(14),scene.my.bar(15)] } : { e.geom.color == [0,0,0,1]

? { scene.my.bar = [scene.my.bar(0),0,scene.my.bar(2),scene.my.bar(3),scene.my.bar

(4),scene.my.bar(5),scene.my.bar(6),scene.my.bar(7),scene.my.bar(8),scene.my.bar

(9),scene.my.bar(10),scene.my.bar(11),scene.my.bar(12),scene.my.bar(13),scene.my.bar

(14),scene.my.bar(15)] } : { scene.my.bar = [scene.my.bar(0),2,scene.my.bar

(2),scene.my.bar(3),scene.my.bar(4),scene.my.bar(5),scene.my.bar(6),scene.my.bar

(7),scene.my.bar(8),scene.my.bar(9),scene.my.bar(10),scene.my.bar(11),scene.my.bar

(12),scene.my.bar(13),scene.my.bar(14),scene.my.bar(15)] }}
LShome
 
Posts: 5
Joined: Thu Nov 19, 2009 10:06 pm

Re: Arrays

Postby Kilinich » Thu Nov 18, 2010 10:37 am

You can use something like this:

scene.my.bar = scene.my.bar * [0, 1, 1, 1] + [newValue, 0, 0, 0]

declare it as finction and it will makes you code shorter
Dream of Algodoo as game development engine...
User avatar
Kilinich
[Best bug reporter 2010]
 
Posts: 2098
Joined: Mon Aug 31, 2009 8:27 pm
Location: South Russia

Re: Arrays

Postby LShome » Thu Nov 18, 2010 5:11 pm

please explain D=
LShome
 
Posts: 5
Joined: Thu Nov 19, 2009 10:06 pm

Re: Arrays

Postby Kilinich » Fri Nov 19, 2010 5:36 pm

[1,2] * [0,1] = [0,2]
[0,2] + [3,0] = [3,2]
Dream of Algodoo as game development engine...
User avatar
Kilinich
[Best bug reporter 2010]
 
Posts: 2098
Joined: Mon Aug 31, 2009 8:27 pm
Location: South Russia

Re: Arrays

Postby tatt61880 » Fri Nov 19, 2010 5:53 pm

More generally,
[a, b] * [c, d] returns [a*c, b*d]
[a, b] + [c, d] returns [a+c, b+d]
[a, b] * c returns [a*c, b*c]
a * [b, c] returns [a*b, a*c]
NOTE: I'm not an Algoryx member.
Hi, Algodoo lovers. Have you read next topic? Featured scenes suggestions
To translators: English.cfg changelog will be useful (even for me).
User avatar
tatt61880
[Most Helpful Person 2010]
 
Posts: 1150
Joined: Mon Aug 31, 2009 5:45 pm
Location: Tokyo, Japan


Return to Thyme scripting

Who is online

Users browsing this forum: No registered users and 0 guests