How do I call a variable by its dynamic name

Get help using Construct 2

Post » Thu Dec 01, 2016 1:20 pm

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)'?
Last edited by luizvneto on Thu Dec 01, 2016 3:12 pm, edited 1 time in total.
B
3
Posts: 2
Reputation: 179

Post » Thu Dec 01, 2016 1:29 pm

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 case.at(casenumber) is.
New to Construct ? Where to start

Image Image

Image Image

Please attach a capx to any help request or bug report !
Moderator
B
284
S
109
G
91
Posts: 7,317
Reputation: 87,483

Post » Thu Dec 01, 2016 3:11 pm

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 case.at(casenumber) to set the frame to the number of case(casenumber)?

Thanks a lot, friend
B
3
Posts: 2
Reputation: 179

Post » Thu Dec 01, 2016 3:39 pm

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 case.at(casenumber), factoring the use of casenumber, if it makes sense.
New to Construct ? Where to start

Image Image

Image Image

Please attach a capx to any help request or bug report !
Moderator
B
284
S
109
G
91
Posts: 7,317
Reputation: 87,483


Return to How do I....?

Who is online

Users browsing this forum: mrkaio, Zav and 2 guests