How do I use FOR variable?

Get help using Construct 2

Post » Sat Apr 26, 2014 3:38 pm

Lets say I want to do this:

Code: Select all
for(var i = 0; i < 10; i++)
{
  print(i);
}


How do I do it on Construct2? I need the I in the ACTION side to set object positions!
B
6
Posts: 18
Reputation: 592

Post » Sat Apr 26, 2014 3:42 pm

for "myloop" 1 to 10 -- set text loopindex("myloop")
August 2015 - I misplaced a lot of links - I will try to find backups and repost. If You find a post that interests please reply to post with @rampackwobble and I will get a nudge!

If you find my posts useful please consider donating something to a local charity or to the http://www.mndassociation.org/
B
64
S
34
G
47
Posts: 1,194
Reputation: 30,892

Post » Sat Apr 26, 2014 3:45 pm

DarkSlash wrote:Lets say I want to do this:

Code: Select all
for(var i = 0; i < 10; i++)
{
  print(i);
}


How do I do it on Construct2? I need the I in the ACTION side to set object positions!


The way to do it is I think to do a for loop condition, and using the loopindex expression in the action.

"loopindex
Get the index (number of repeats so far) in any currently running loop.

loopindex(name)
Get the index (number of repeats so far) of the loop with the given name. Useful for getting indices in nested loops."
Game design is all about decomposing the core of your game so it becomes simple instructions.
B
54
S
22
G
18
Posts: 2,123
Reputation: 17,150

Post » Sat Apr 26, 2014 3:53 pm

Thanks! It worked perfect! :)
B
6
Posts: 18
Reputation: 592

Post » Sun Apr 27, 2014 11:23 pm

And can I do something like this?

Code: Select all
for(var col = 0; col < 10; col++)
{
    counter = 0;

    for(var row = 0; row< 15; row++)
    {
        if(myArray(col,row) == 0) { counter++; }
    }

    if(counter == 0) { DO SOMETHING }
}
B
6
Posts: 18
Reputation: 592

Post » Sun Apr 27, 2014 11:37 pm

Iterating over the full size of the array.
You do not have the required permissions to view the files attached to this post.
ImageImageImage
B
71
S
22
G
257
Posts: 3,788
Reputation: 142,692

Post » Mon Apr 28, 2014 12:18 am

How do you make those "steps" in the conditions?
B
6
Posts: 18
Reputation: 592

Post » Mon Apr 28, 2014 12:20 am

Those are sub-events.
ImageImageImage
B
71
S
22
G
257
Posts: 3,788
Reputation: 142,692

Post » Mon Apr 28, 2014 4:42 pm

Thanks!
B
6
Posts: 18
Reputation: 592


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 10 guests