How do I call a variable by its dynamic name

0 favourites
  • 4 posts
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • Sounds complicated at first, but let's try...

    I have in my project 6 variables:

    case1 = 0 or 1

    case2 = 0 or 1

    case3 = 0 or 1

    case4 = 0 or 1

    case5 = 0 or 1

    casenumber, = from 1 to 5

    Those 'caseX' variables represent the status (on or off) of that particular case, I could use matrix but that's not my issue (I think). I want to call "caseX' based on the number provided in "casenumber". is there a function like 'valueOf("case" & casenumber)'?

  • You need to use an array (matrix as you call it).

    Variable names are fixed and you cannot call it the way you would describe in your message in C2.

    Having 5 cells in your array will allow you to set and check what the is.

  • Understood..

    With the results of caseX being 0 or 1, I need to use this number to set a frame 0 or frame 1, corresponding to caseX, of course, to an animation...

    So in the action 'set frame' of this animation, could I use to set the frame to the number of case(casenumber)?

    Thanks a lot, friend

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You indeed can.

    Moreover in the case of animations which are strings you set arbitrarily, you could very well name your set of animations "Anim0", "Anim1", "Anim2", ...

    And setting the animation to play to be "Anim" & SomeVariable ( for example casenumber) and then use the action set frame to be, factoring the use of casenumber, if it makes sense.

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