Set value (by name)?

Get help using Construct 2

Post » Fri May 18, 2012 4:48 pm

Hey there,

I'm trying to access a variable by using a string and not by selecting it in the list. Something like the "Go to layout (by name)"

For example, I have a clickable object with a local variable "target"
If target = "my_layout_name", I can have a script to load the layout with this name.

But if target = "my_variable_name", I cannot find a way to set the value of the global variable with the name "my_variable_name".

Hope that makes sense!
Thanks =)
B
5
Posts: 11
Reputation: 422

Post » Fri May 18, 2012 6:35 pm

You'd probably want to use an array for this, instead of individual variables. Then you can just reference an index.
B
90
S
30
G
24
Posts: 3,189
Reputation: 32,400

Post » Mon May 21, 2012 8:51 am

Oh, thanks! =)
I'm surprised there isn't a more convenient way to do it. If I access the variables with numbers (array index), my script will become really hard to read :o
B
5
Posts: 11
Reputation: 422

Post » Mon May 21, 2012 9:04 am

@Ezhaac

r91 has dictionary plugin. It's a 1d hash table.
B
97
S
22
G
176
Posts: 4,109
Reputation: 103,021

Post » Mon May 21, 2012 10:22 am

Nice =)
Can't wait to get my hands on the next release.
B
5
Posts: 11
Reputation: 422

Post » Tue May 22, 2012 4:55 am

Out of curiosity, why do you need to be able to access your variables using a string? That can get messy - especially when you decide to change a variable name. Perhaps there is a more elegant solution that we could figure out, if you don't mind mentioning the specific problem.
Image
B
10
S
3
G
2
Posts: 196
Reputation: 2,053

Post » Tue May 22, 2012 5:10 am

@Ezhaac

r91 had released.
B
97
S
22
G
176
Posts: 4,109
Reputation: 103,021

Post » Tue May 22, 2012 8:54 am

@Dalal
I'm working on a kind of point & clic game, using multiple photos as screens. I'll use a layout for each photo with an include pointing on a unique event sheet.
On each layout, there are clickable object (for example: a mecanisme that can be activated, a door that can be used to go elsewhere, etc). Each object is a sprite which can have 1 or 2 instance variable called "target" and "flag".
The "target" variable is the name of the layout that will be open when the player clic on the thing, and "flag" is the name of the boolean variable that is triggered. (if the object is a simple door and not a mecanism, it doesn't have a "flag" variable)

The idea behind this structure is to have one master event sheet used by all my layouts, allowing me to simply position the clickable object on the scenes, without having to duplicate code each time.
It may not be the best solution but I haven't programmed for several years, now, so, that's the best I've found yet :D

@Rexrainbow
I cannot find the r91. Is there some other download page for beta releases?
http://www.scirra.com/store/free-html5-game-engine
B
5
Posts: 11
Reputation: 422

Post » Tue May 22, 2012 9:16 am

@Ezhaac


http://www.scirra.com/construct2/releases/r91

Yes, it's a beta release.
B
97
S
22
G
176
Posts: 4,109
Reputation: 103,021

Post » Tue May 22, 2012 9:35 am

Thanks!
B
5
Posts: 11
Reputation: 422

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 32 guests