refer to an array by a string?

0 favourites
  • 5 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 menu that consists of text.

    Based on the selection I want to fill an array with specific content (from other arrays)

    Is there a way to use the string names of the menu items to refer to a specific array?

    The only way I can think of is manually.

    If menuItem.name="Test1" then read from Test1.At(0)

    How would you do something like that?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Not really but the way you mentioned should only be one event anyway

  • Might or might not work depending on your application but it is also an option to have multiple instances of the same array object, or to put your different array objects into a family.

    You'll still need a condition to pick the relevant arrays somehow though, by IID, UID, or instance variable.

  • Thanks for the feedback!

    I had an idea which is using the string to look up an index in a 2D array.

    So the Menu item would show "apples" and in my array I have a list of the menu item strings running down the Y direction where I look for Array.IndexOf("apples")

    Now I ran into a different problem, though.

    When I try to refer to menuItem.text I get inconsistent results. (Which I posted in another thread)

    But it's probably hard to help without seeing the event sheet.

    Facts are: I have a text object "Talk" that I use to display values at runtime. Every time the menu items come to a halt I pick the middle menuitem by comparing X and set Talk.text = menuItem.text

    Now this works great for all instances of menuItem except for the original that created the others and the first of it's creations. (So they are the first two items in the menu)

    Talk remains empty when either of those two are picked.

    When instead of the "set" action I use the "append" action it works. When I append menuItem.text&"!" I get "apples!!" (while the other instances produce "apples!" as expected)

    This behaviour remains consistent going back and forth or in a circle in the menu..

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