[Solved] Variable name as a string

Get help using Construct 2

Post » Fri Aug 17, 2012 5:15 pm

Hi!

I'd like to know if it was possible to consider variable names as strings, in order to make some operations easier and avoid duplicating conditions.

Sometimes like this:



This would allow to avoid duplicating conditions "if GunType=1" "if GunType=2" "if GunType=3" etc. (I don't have many GunType but still, it would be more... clean)


It worked with animations (anim1 anim2 anim3) since the animation name is already considered as a string, so I just had to change the number without converting the variable name into a string. It was extremely convenient, I must admit.

In the example above, I turned the variable name into a string with the str() function but... I didn't work (logically since I converted the variable itself, I suppose). How to "manipulate" a variable name like if it was a string? Is it possible?


Thanks in advance!

Rag' Ragtime2012-08-17 18:46:37
B
17
S
4
G
4
Posts: 137
Reputation: 3,767

Post » Fri Aug 17, 2012 5:40 pm

You can choose to Text when creating Global Variables, is this what you want?


Edit: Oh you meant variable "names" no values, my bet.shinkan2012-08-17 17:41:50
ImageImageImageImage
B
140
S
58
G
36
Posts: 2,547
Reputation: 31,170

Post » Fri Aug 17, 2012 5:55 pm

If you store the values in a dictionary you could do something like:
B
54
S
28
G
18
Posts: 1,520
Reputation: 25,020

Post » Fri Aug 17, 2012 6:11 pm

I love to use it for change weapons, for example.

Weapon instance have the variable called by "type" and it's set to be text. Also, you can make other variables like "damage" for each different damage you want, or simple increase it like you did for the weapon.

Inside the animations, I did them calling each one as weaponN, where the N is a ordinal number.

When the player change his weapon, for example, of the 1 to the 2, I just set it looping:

|Keyboard - "A" pressed:
|__set weapon.variable.type add +1;

|weapon - variable.type > 10:
|__weapon.variable.type = 1;

|system - every tick:
|__set weapon.animation to "weapon" & weapon.variable.type;
|__set weapon.variable.damage to weapon.variable.type;
TELLES08082012-08-17 18:12:27
ImageImageImageImageImageImage
B
93
S
19
G
12
Posts: 1,211
Reputation: 18,373

Post » Fri Aug 17, 2012 6:46 pm

Thanks all of you for your answers, I think I've found what I was looking for :)
B
17
S
4
G
4
Posts: 137
Reputation: 3,767


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 26 guests