Using Variables inside of Variables

0 favourites
  • 3 posts
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • 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?

  • 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 etc

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Kosiam - ah, of course! I can't believe I didn't think of that. Thanks!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)