[Help] "FOR" function

Post your tutorials here.

[Help] "FOR" function

Postby daniel1296 » Mon Mar 12, 2012 12:11 pm

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?
daniel1296
 
Posts: 15
Joined: Fri Dec 30, 2011 9:31 pm

Re: [Help] "FOR" function

Postby Kilinich » Mon Mar 12, 2012 12:39 pm

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);
Dream of Algodoo as game development engine...
User avatar
Kilinich
[Best bug reporter 2010]
 
Posts: 2047
Joined: Mon Aug 31, 2009 8:27 pm
Location: South Russia

Re: [Help] "FOR" function

Postby Kilinich » Mon Mar 12, 2012 12:40 pm

...and here it is post with extended for cycle example: viewtopic.php?f=13&t=5146&p=54364&hilit=xfor#p54364
Dream of Algodoo as game development engine...
User avatar
Kilinich
[Best bug reporter 2010]
 
Posts: 2047
Joined: Mon Aug 31, 2009 8:27 pm
Location: South Russia

Re: [Help] "FOR" function

Postby daniel1296 » Mon Mar 12, 2012 1:59 pm

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
daniel1296
 
Posts: 15
Joined: Fri Dec 30, 2011 9:31 pm

Re: [Help] "FOR" function

Postby Nxdt » Mon Mar 12, 2012 3:15 pm

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
User avatar
Nxdt
 
Posts: 1019
Joined: Mon Aug 31, 2009 6:32 pm
Location: Scotland!

Re: [Help] "FOR" function

Postby daniel1296 » Sat Mar 17, 2012 10:23 am

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)
daniel1296
 
Posts: 15
Joined: Fri Dec 30, 2011 9:31 pm

Re: [Help] "FOR" function

Postby Nxdt » Sat Mar 17, 2012 5:52 pm

Appear, as in become visible, like you can see it? Or spawn it once.
User avatar
Nxdt
 
Posts: 1019
Joined: Mon Aug 31, 2009 6:32 pm
Location: Scotland!

Re: [Help] "FOR" function

Postby daniel1296 » Sun Mar 18, 2012 8:55 am

Spawn it once
daniel1296
 
Posts: 15
Joined: Fri Dec 30, 2011 9:31 pm

Re: [Help] "FOR" function

Postby Nxdt » Sun Mar 18, 2012 6:13 pm

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.
User avatar
Nxdt
 
Posts: 1019
Joined: Mon Aug 31, 2009 6:32 pm
Location: Scotland!

Re: [Help] "FOR" function

Postby daniel1296 » Sun Mar 18, 2012 6:54 pm

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
daniel1296
 
Posts: 15
Joined: Fri Dec 30, 2011 9:31 pm

Re: [Help] "FOR" function

Postby Nxdt » Sun Mar 18, 2012 9:31 pm

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.
Attachments
HP Demo.phz
HP demo
(25.63 KiB) Downloaded 50 times
User avatar
Nxdt
 
Posts: 1019
Joined: Mon Aug 31, 2009 6:32 pm
Location: Scotland!

Re: [Help] "FOR" function

Postby daniel1296 » Mon Mar 19, 2012 7:31 pm

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)
daniel1296
 
Posts: 15
Joined: Fri Dec 30, 2011 9:31 pm


Return to Tutorials

Who is online

Users browsing this forum: No registered users and 1 guest

cron