How do I do eval('variable name') ? Get Variable Value ?

Get help using Construct 2

Post » Wed Aug 26, 2015 6:58 am

Say I have a global variable called "Hello 2", and later on in a for loop I create the string call "Hello 2", how do I convert this string into the corresponding variable name and tell construct 2 there is a variable with the same name as the string supplied now give me its value ?
B
12
S
3
Posts: 288
Reputation: 1,694

Post » Wed Aug 26, 2015 3:17 pm

I don't know that this is possible in native C2, but you can probably write a plugin for it using the SDK or maybe even try using eval('xxxx') in the "Browser: Execute JavaScript" event.
https://www.ravenheart.ca/home
I don't check the forums much anymore, but I will receive an email for PMs.

"Someone once told me I bite off more than I can chew...

I told them I would rather choke on greatness than nibble on mediocrity."
B
23
S
6
G
1
Posts: 1,419
Reputation: 4,857

Post » Wed Aug 26, 2015 3:26 pm

The easiest way to accomplish that is to switch from global variables to a dictionary object. The dictionary can hold any number of variables and each of them is indexed by a string key. So you can do Dictionary("name") = newValue or Dictionary(variable) = newValue.
B
75
S
31
G
27
Posts: 1,015
Reputation: 20,765

Post » Thu Aug 27, 2015 6:05 am

Thank you, yes I do believe now that dictionary will have to be the way to go.
It is unorthodox though :)
To use the dictionary object just simply because one needs to use eval () :)
B
12
S
3
Posts: 288
Reputation: 1,694

Post » Thu Aug 27, 2015 2:11 pm

Well to be fair, there is no eval() function in Construct, so the "unorthodox" way is actually the ONLY way, making it not so unorthodox. :P
B
75
S
31
G
27
Posts: 1,015
Reputation: 20,765

Post » Thu Aug 27, 2015 5:16 pm

Awe, cute respond :) But I agree :)
B
12
S
3
Posts: 288
Reputation: 1,694


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 6 guests