Page 1 of 1

[Help] "FOR" function

PostPosted: Mon Mar 12, 2012 12:11 pm
by daniel1296
hi, its me again :)
can anyone could tell me how "for" works on algodoo?? i want to ask just 2 time "if" function.. so how to it?

Re: [Help] "FOR" function

PostPosted: Mon Mar 12, 2012 12:39 pm
by Kilinich
Buil-in "for":
It's function for(n, what) with 2 arguments:
1) integer - number of iteration
2) function - function which you need to call few times with one argument - number of call

Example:

scene.my.show = (i) => {scene.addbox({pos := [i,0]; text := (""+ i)})};
for(5, scene.my.show);

Re: [Help] "FOR" function

PostPosted: Mon Mar 12, 2012 12:40 pm
by Kilinich
...and here it is post with extended for cycle example: viewtopic.php?f=13&t=5146&p=54364&hilit=xfor#p54364

Re: [Help] "FOR" function

PostPosted: Mon Mar 12, 2012 1:59 pm
by daniel1296
umm.. its not working to me. i did "scene.my.show = (i) => {_____};" in the console ("__" its addpolygon and a lot of things);
and in the polygon i did "for(2, scene.my.show)" and nothing happend... i tired this function without "for" and its working. help plz

Re: [Help] "FOR" function

PostPosted: Mon Mar 12, 2012 3:15 pm
by Nxdt
You need to write it in the oncollide(e)>{......} and onlaserhit(e)>{......} entry boxes of a geometry.
Console is used for creating scene.my variables most of the time

Re: [Help] "FOR" function

PostPosted: Sat Mar 17, 2012 10:23 am
by daniel1296
i want to do when box hit something a polygon will appear only once! You can upload a scene that does this?
(sorry for my english)

Re: [Help] "FOR" function

PostPosted: Sat Mar 17, 2012 5:52 pm
by Nxdt
Appear, as in become visible, like you can see it? Or spawn it once.

Re: [Help] "FOR" function

PostPosted: Sun Mar 18, 2012 8:55 am
by daniel1296
Spawn it once

Re: [Help] "FOR" function

PostPosted: Sun Mar 18, 2012 6:13 pm
by Nxdt
Oncollide code, make sure the code will delete the original objects (The one that has the code) script, so it can't spawn the polygon again.

Re: [Help] "FOR" function

PostPosted: Sun Mar 18, 2012 6:54 pm
by daniel1296
no.. cant do that. i build a beyblade game, and i want to do that when hp < 100 a special gem will spwan once. any idea?
Rating: rated 4.7
Filesize: 89.2 kB
Comments: 1
Ratings: 4
download

Re: [Help] "FOR" function

PostPosted: Sun Mar 18, 2012 9:31 pm
by Nxdt
I don't really understand why you would want to spawn a special "gem". If you want to make your beyblade faster or something, this can be done in the health bar script.

I assume you also need help with the health code.
Basically, create a "scene.my.hp1 = x" (x is just a number) variable, in the console, this will record the "Hp" of player 1 say. And everytime a collision happens it lowers the hp.

I did a little health example, it also spawns a gem once, and when the hp gets lower than 100.

Re: [Help] "FOR" function

PostPosted: Mon Mar 19, 2012 7:31 pm
by daniel1296
i have hp function.. u can download the scene and look. it is with a sin function..
and i found another way to do gem.. 10x a lot guys for helping.
(sorry for my bad english)