How to combine strings into a value?

0 favourites
  • 3 posts
From the Asset Store
This collection of music is the beautiful performance of rather small strings ensemble (8 first violins, 6 second violin
  • I have an object with an instance variable which is a number. I need to set it to a value which is obtained from combining two strings together.

    The first string is obtained by checking another instance variable in the object, called "owner". The variable "owner" in this case is set to "FRA".

    The second string is just called "_hue_red".

    So by combining "FRA" and "_hue_red" I should get "FRA_hue_red", which is the name of a global variable. However, it just ends up as a string and it doesn't get converted into a number.

    The problem here is that I can't figure out how to convert it into a number. I've looked around google but I couldn't figure it out from there either.

    I tried using integers like this: int(object.owner & "_hue_red") but it didn't work.

    I probably explained my question pretty poorly, but that's mostly because I suck at explaining things. Thanks in advance.

  • Unfortunately, it's not possible to access variables by their string name. So the only option for you is to add a bunch of events like this:

    If var_name="FRA_hue_red" then Set Result=FRA_hue_red
    Else
    If var_name="FRA_hue_blue" then Set Result=FRA_hue_blue
    Else
    If var_name="FRA_hue_green" then Set Result=FRA_hue_green
    etc..
    

    Another solution is to use a dictionary instead of global variables. With dictionary you can easily access keys by name - Dictionary.Get("FRA_hue_red")

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Ah, that's sad. Thanks for the help though!

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