calling variable with a string

0 favourites
  • 5 posts
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • Is it possible to call global variables by a string?

    Like if you have these global variables:

    orange_1

    orange_2

    orange_3

    and you wanted to be able to call the variables with a combination of the text strings:

    "orange"

    and

    "1"

    "2"

    "3"

    from my testing so far, the expression doesn't look for a variable with that name it just treats it as the base text/string. I didn't find any system expressions that allow you to use a string to find a variable. Am I missing something?

  • Nope.

    You can use those values contained in a variable however.

    Like if mygvariable= "orange_"&1

  • Thanks for the quick reply! I'll just go the longer route to make it happen.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • using dictionary, perhaps?

  • As far as placing var in text strings is rather straight forward but will require a bit of labor.

    var "Apple_Red" = 10

    Start of Layout > Set text for Textbox to "Have you collected all the apples?"

    If Yes_btn is clicked

    "Apple_Red" >= 8

    set Textbox to "Great now I can make that pie"

    "Apple_Red" < 8 then

    set Textbox to "Oops, You need to collect "& 8-"Apple_Red" & "Red Apples. Please look for them"

    So it can be done but you need to edit the string to have the variable in it instead of a string. '&' is what you use to bind two things together so all you need is to have "The text string" & variable & "last text string."

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