Using Variables inside of Variables

Get help using Construct 2

Post » Thu Aug 01, 2013 6:50 pm

I'm wondering if there is a way to simplify tons of code by using multiple variables within a single variable. ie:

Global Variable - Weapon (text) = "Shotgun"
Global Variable - WeaponDamage (number) = 5

On bullet collision, set damage to int(str(Weapon)&"Damage").

Something like this could allow you to have 1 event for damage if you have multiple weapons that each have their own damage parameters.

However, it's not working for me, but is this something that could potentially work?
B
41
S
12
G
1
Posts: 540
Reputation: 4,188

Post » Thu Aug 01, 2013 7:10 pm

Place them in an array

array = DamTable
DamTable.at(0)=3 (weapon1 )
DamTable.at(1)=4 (weapon2 )
DamTable.at(2)=2 (weapon3 )

then you set weapon to appropriate value when equipped ( i.e. if shotgun is equipped and shotgun is weapon2 then set weapon=1

then the on bullet collison=
set damage to DamTable(weapon)

you could also keep track of weaponx names in the array via:
DamTable.at(0,1)="Assault Rifle"
DamTable.at(1,1)="Shotgun"
DamTable.at(2,1)="Knife"

This would also reflect addressing the damage as it would go from DamTable.at(0) to DamTable.at(0,0) etc

otherwise I don't believe you can use variables such as shotgun.name, shotgun.damage etcKosiam2013-08-01 19:12:17
B
5
S
1
Posts: 26
Reputation: 427

Post » Thu Aug 01, 2013 7:13 pm

@Kosiam - ah, of course! I can't believe I didn't think of that. Thanks!
B
41
S
12
G
1
Posts: 540
Reputation: 4,188


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 5 guests