Loops with variables as names

This forum is currently in read-only mode.
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • I have an event looking like this:

    <img src="http://ioj.com/u/get_file.php?id=838417&file=c2ee8i02v933.jpg">

    When i press space, shouldn't the sprite be destroyed? How is this working?

  • Why did you name loop by "Sprite.Value('whut')"? It wont affect anything but name of the loop.

    Edit: just add condition for "On loop" with "Sprite.Value('whut')=1 or something like that and it will work.

  • "For" loops are supposed to get STRING values for their names. If your variable is NUMERIC, you should do str( Sprite('whut') ) instead of Sprite('whut').

    Anyways that quite surprising idea to post loop with name depending on (changable!) private variable ^^.

  • The 'On loop' condition only works with a constant (ie. typed in) loop name. I thought I put in a warning in case the expression wasn't constant, but I guess somehow it got turned off. I could have allowed variable names, but it would reduce the algorithmic efficiency considerably. If you can't assume that every string is going to stay the same, every time you run 'On Loop', you have to check all other unrelated 'On loop' conditions to see if their name matches the loop being run, every iteration. This means if you have On loop "a", simply adding some events for loop "b" slows down loop "a"! However, in Construct, forcing a constant string name for the loop allows for an optimisation I've coded that keeps that painful inefficiency from occurring.

    Still, the 'start loop' loops are much, much slower than the condition loops (eg. 'For'). I wouldn't recommend you use them at all. They spread out the code to unrelated places in the event list as well. Condition loops keep everything tidy, and are much faster. The CPU cycle overhead per-iteration for the 'Repeat' system condition was about 9 cycles last time I measured it; it'll be hundreds of cycles for anything using 'start loop'.

    As for the condition loops, you should be able to get away with using a variable for the name, but I wouldn't recommend it. It'll only work so long as the variable stays the same for the duration of the loop. I can't see why it's necessary to ever do that though.

  • Right now i have a good reason for needing this in my engine, but that might be cause i don't know how to use the "for" loop. Is it documented somewhere, or can someone explain its use to me? I didn't understand much from the wiki.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • It repeats all its actions and subevents with a named loop and a range of loop indices. For example,

    + Start of layout

    -> Start loop "blah" 100 times

    + On loop "blah"

    -> Actions to do in the loop

    is identical to:

    + For "blah" from 1 to 100

    -> Actions to do in the loop

    Faster, fewer events, more compact, still dead easy If you don't need the loop index you can just use 'Repeat':

    + Repeat 100 times

    -> Actions to do in the loop

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)