Getting a value from global var. based on a string.

0 favourites
  • 4 posts
From the Asset Store
Globals 2.0
$3.99 USD
Globals 2.0 stores and group variables. You can also load and save data (variables) from/to JSON files.
  • I want to add a value based on a global variables name matching the text in a text object.

    I have an object that has a text object on top that randomly picks 3 words. When a word is chosen i want it to add a value equal to the global variable of the same word.

    Something like global.word_obj.text would be nice but thats not a thing.

    I hope any of this makes sense.

  • This doesn't make too much sense. "When a word is chosen i want it to add a value equal to the global variable of the same word." ? Provide some examples.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Use a global Dictionary object.

  • Well before I could explain further I found my answer from the amazing Ashley who not only knew the answer but could interpret my terrible explanation. (I wish I could blame it on English as a second language, but it's not)

    Anyway here was my problem and solution for anyone who might have this situation.

    I have a customer who comes in to my restaurant and wants to order a random item from my menu.

    The item is randomly ordered and stored as a local variable.

    What I was having a problem with was using that "string" to access another variable that takes care of prices for each item. This is where Ashley saved the day.

    I set up a dictionary with each item as a "key" with the price as the value.

    Using the "add to value" I can use "Dictionary.Get(Test_customer.Order)" as my value.

    This works really well as I can easily update values for each item.

    Thanks Ashley!

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