Array cell access [help needed].

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

Re: Array cell access [help needed].

Postby KarateBrot » Mon Oct 26, 2009 2:43 pm

savask wrote:Yes, immibis was right. This is cause of for-loop limit.
Can you show me some examples of using your for-function?


okay sorry i thought you mean the number of cells you can use in an array like you said above

@immibis:
what's the "max" variable for?
Image
User avatar
KarateBrot
 
Posts: 825
Joined: Mon Aug 31, 2009 7:32 pm
Location: Germany

Re: Array cell access [help needed].

Postby savask » Mon Oct 26, 2009 3:41 pm

You wasn't far from the truth ;)
I "couldn't use" more than 50 cells, because I couldn't make more than 50 cells in the loop :)
User avatar
savask
 
Posts: 162
Joined: Mon Oct 12, 2009 2:53 pm
Location: Russia, Siberia

Re: Array cell access [help needed].

Postby KarateBrot » Mon Oct 26, 2009 3:54 pm

oh that explains a lot :D
Image
User avatar
KarateBrot
 
Posts: 825
Joined: Mon Aug 31, 2009 7:32 pm
Location: Germany

Re: Array cell access [help needed].

Postby savask » Mon Oct 26, 2009 4:03 pm

Some questions :P
Should I write this function in the console?
Will it be saved in the phz file?
User avatar
savask
 
Posts: 162
Joined: Mon Oct 12, 2009 2:53 pm
Location: Russia, Siberia

Re: Array cell access [help needed].

Postby KarateBrot » Mon Oct 26, 2009 4:24 pm

yes if you write any variable/function with "scene.my." in front of it it will be saved to your .phz file. and yes, functions normally are typed into the console :thumbup:
Image
User avatar
KarateBrot
 
Posts: 825
Joined: Mon Aug 31, 2009 7:32 pm
Location: Germany

Re: Array cell access [help needed].

Postby savask » Mon Oct 26, 2009 4:26 pm

Ok, thanks!
Now we should wait for immibis answer...
User avatar
savask
 
Posts: 162
Joined: Mon Oct 12, 2009 2:53 pm
Location: Russia, Siberia

Re: Array cell access [help needed].

Postby immibis » Tue Oct 27, 2009 5:39 am

Just use Scene.my.for2 instead of for. For example, instead of:
Code: Select all
for(1000, (i)=>{do some stuff})

write
Code: Select all
Scene.my.for2(1000, (i)=>{do some stuff})
Thymechanic
immibis
 
Posts: 87
Joined: Wed Sep 30, 2009 12:24 am

Re: Array cell access [help needed].

Postby savask » Tue Oct 27, 2009 9:37 am

Thank you!
It is very good that your function use the same syntax as default for-loop :thumbup:
User avatar
savask
 
Posts: 162
Joined: Mon Oct 12, 2009 2:53 pm
Location: Russia, Siberia

Re: Array cell access [help needed].

Postby KarateBrot » Tue Oct 27, 2009 1:28 pm

the for2 function is nice and works but whenever i use scene.my.for2 in complex functions it doesn't work. algodoo freezes and windows has to force it to close. any ideas?
Image
User avatar
KarateBrot
 
Posts: 825
Joined: Mon Aug 31, 2009 7:32 pm
Location: Germany

Re: Array cell access [help needed].

Postby savask » Tue Oct 27, 2009 1:50 pm

It works fine for me, but may be my scripts isn't so complex as yours.
User avatar
savask
 
Posts: 162
Joined: Mon Oct 12, 2009 2:53 pm
Location: Russia, Siberia

Re: Array cell access [help needed].

Postby KarateBrot » Tue Oct 27, 2009 2:05 pm

i don't know what's wrong. maybe it's because i have a spawn script in the for2 function (which should normally work)
Image
User avatar
KarateBrot
 
Posts: 825
Joined: Mon Aug 31, 2009 7:32 pm
Location: Germany

Re: Array cell access [help needed].

Postby savask » Tue Oct 27, 2009 3:13 pm

Can you show the script?
User avatar
savask
 
Posts: 162
Joined: Mon Oct 12, 2009 2:53 pm
Location: Russia, Siberia

Re: Array cell access [help needed].

Postby KarateBrot » Tue Oct 27, 2009 9:48 pm

Code: Select all
Scene.my.ln = (x) => { (x^0.001 - 1) / 0.001 };

scene.my.physicsstuff = (g,m,v,a,d,x) => { big physics formula here };

scene.my.q = (x) =>
{
   n := math.tofloat(x);
   scene.my.for2(n, (i)=> {
      scene.addcircle({
         radius := 0.005;
         color := [1,1,1,1];
         pos := [i/10, scene.my.physicsstuff(9.8,2,10,math.pi/4,2.5,i/10)]
      })
   })
};


With the normal for function it works but with the for2 function Algodoo crashes. It's weird.
Image
User avatar
KarateBrot
 
Posts: 825
Joined: Mon Aug 31, 2009 7:32 pm
Location: Germany

Re: Array cell access [help needed].

Postby savask » Wed Oct 28, 2009 10:00 am

I tried a spawn script in for2-loop and it works.
User avatar
savask
 
Posts: 162
Joined: Mon Oct 12, 2009 2:53 pm
Location: Russia, Siberia

Re: Array cell access [help needed].

Postby KarateBrot » Wed Oct 28, 2009 11:31 am

i know. normally it works.
Image
User avatar
KarateBrot
 
Posts: 825
Joined: Mon Aug 31, 2009 7:32 pm
Location: Germany

Re: Array cell access [help needed].

Postby savask » Wed Oct 28, 2009 11:49 am

But you said that Algodoo crashes, didn't you?
User avatar
savask
 
Posts: 162
Joined: Mon Oct 12, 2009 2:53 pm
Location: Russia, Siberia

Re: Array cell access [help needed].

Postby KarateBrot » Wed Oct 28, 2009 11:53 am

yes normally it works but this code above doesn't work. it only works with the normal for function.
Image
User avatar
KarateBrot
 
Posts: 825
Joined: Mon Aug 31, 2009 7:32 pm
Location: Germany

Re: Array cell access [help needed].

Postby savask » Wed Oct 28, 2009 12:49 pm

May be the problem with the n variable?
User avatar
savask
 
Posts: 162
Joined: Mon Oct 12, 2009 2:53 pm
Location: Russia, Siberia

Re: Array cell access [help needed].

Postby KarateBrot » Wed Oct 28, 2009 1:13 pm

Thanks, that's the error. I tested it with a simple code but the for2 function can't handle it with specific values

Code: Select all
Scene.my.test = (x) => { scene.my.for2(x, (i)=>{ print ((i+1) + " text lines") }) };


Not working
Scene.my.test(0)
Scene.my.test(1)

If you choose a value above 1 it's working. I tested it with scene.my.value(2), scene.my.value(10), scene.my.value(100) and scene.my.value(1000). They all work. Weird...
I'll write a PM to immibis.

[EDIT]
If you make x a float value it only works with scene.my.test(2). All other values don't work.
Code: Select all
Scene.my.test = (x) =>
{
   n := math.tofloat(x);
   scene.my.for2(n, (i)=>{ print ((i+1) + " text lines") })
};
Image
User avatar
KarateBrot
 
Posts: 825
Joined: Mon Aug 31, 2009 7:32 pm
Location: Germany

Re: Array cell access [help needed].

Postby savask » Wed Oct 28, 2009 1:25 pm

Yes, really, it don't work with 0 and 1.
So I have to use default "for" function :problem:
User avatar
savask
 
Posts: 162
Joined: Mon Oct 12, 2009 2:53 pm
Location: Russia, Siberia

Re: Array cell access [help needed].

Postby KarateBrot » Wed Oct 28, 2009 1:48 pm

I already let immibis know about this bug. I wrote a PM. Let's wait.
Image
User avatar
KarateBrot
 
Posts: 825
Joined: Mon Aug 31, 2009 7:32 pm
Location: Germany

Re: Array cell access [help needed].

Postby savask » Wed Oct 28, 2009 2:05 pm

Ok, I wish he will fix it.
User avatar
savask
 
Posts: 162
Joined: Mon Oct 12, 2009 2:53 pm
Location: Russia, Siberia

Re: Array cell access [help needed].

Postby immibis » Thu Oct 29, 2009 7:01 am

I've edited my original post here to the "Thyme math functions" thread: viewtopic.php?f=13&t=371&p=8695#p8695
Thymechanic
immibis
 
Posts: 87
Joined: Wed Sep 30, 2009 12:24 am

Re: Array cell access [help needed].

Postby savask » Thu Oct 29, 2009 1:16 pm

Ok, thanks!
User avatar
savask
 
Posts: 162
Joined: Mon Oct 12, 2009 2:53 pm
Location: Russia, Siberia

Re: Array cell access [help needed].

Postby KarateBrot » Thu Oct 29, 2009 6:58 pm

Very good! Now it's awesome
Image
User avatar
KarateBrot
 
Posts: 825
Joined: Mon Aug 31, 2009 7:32 pm
Location: Germany

Previous

Return to Thyme scripting

Who is online

Users browsing this forum: No registered users and 14 guests