Best practice for using local variables in loops?

0 favourites
  • 3 posts
From the Asset Store
"Easy Local Notifications" enhances games with customizable local notifications.
  • What is the best form in Construct to accomplish the following?

    • Enter a subevent
    • Create a local variable for this scope, and initialize to the value of a global constant
    • Execute a loop, modifying the value of the local variable
    • After termination of the loop, reset the local variable to the value of the constant
    • Run a second loop that makes use of the local variable
    • Exit subevent

    I'm not allowed to supply the constant as the initializing value--only numeric literals are permitted it seems. And I'm not sure of the "proper" way to execute an action modifying the local variable before a loop begins (or after a loop exits, or between loops). The best I could come up with is to insert a couple of System > Every Tick rows, as per the sample code below. It works, but it feels kludgy, especially in the context below where this is "run once" code at the start of the layout, and not something that actually runs every tick. Do any experienced folks have some wisdom to share?

  • Simply remove the condition "On every tick" from event #2, but keep the event itself.

    So in your event #2 you should have an empty box on the left and "System Set..." action on the right.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thank you! I did not pick up from the docs/tutorials that I can have an action without an explicit condition in the same row.

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