How do I bring another variable in to another variable?

0 favourites
  • 5 posts
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • Hello!

    I've managed to bring a variable in to a string using the & symbol, but how do I do the same for a numeric instance variable?

    I took a wild guess with Hero.guardAttack&currentEnemyType&OneLand but I have no clue how to do this properly.

  • When you do number1&number2, it performs a Boolean AND operation on them, and the result will be either 0 or 1.

    If you need to make a string, use "" & number1 & number2

    Also, you might probably want to separate numbers with a comma or some other character:

    "" & number1 & "," & number2

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Hi dop2000,

    Thanks for the response but I'm not sure I was really being clear on what I was after.

    I have a set of enemy types and have a method that determines which one the player is up against. That is stored in the variable currentEnemyType. Eg:

    var: currentEnemyType ...Goon ...Brute ...Mage ...Boss ...etc

    What I'm trying to do is get the type of enemy inserted in to the name of an instance variable on the player sprite. Taking Goon as an example:

    Player.attackGoonOneLand

    And against a Brute it would say:

    Player.attackBruteOneLand

    So I'm trying to insert the variable of currentEnemyType in to that instance variable:

    Player.attack**currentEnemyType**OneLand

    But I'm just not sure what to replace those asterisks with.

    Dunno if this makes a difference, but the instance variable is a Number.

  • This is not possible with events. You should be able to access variables by string name using scripting. I think it should be something like:

    runtime.objects.ObjName.getFirstInstance().instVars["varName"]

    Another option is to use a Dictionary instead of instance variables. In this case you can access dictionary key like this:

    Dictionary.Get("attack" & enemyType" & "OneLand")

  • Looks like I need to do some reading up on Dictionaries. Thanks so much!

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