0
Answered

Trying to display contents of List Variable / problems adding to list variable

Phazorknight 3 months ago in Game Creator updated by Marti (Lead Developer) 3 months ago 2

Hey everyone,
I'm having some problems with variables updating in my project.

My main goal is: 
I wanna have a list of items that gets added to after the player interacts with certain objects. 
Think of it like a shopping cart you can add to and you have a list of items of what you put in your shopping cart.

I tried adding a List Variable with GameObjects, but I don't know how to display the GameObjects name in the UI, plus it might be tricky to localize, so next I thought I use strings.

I tried adding strings from local or global variables, but neither show up in my variable selection screen, when I use the Add variable to list variable action.
Am I missing something / doing something wrong?

Here's my setup that shows two global variables in case it helps, when I click the selector under the "Global Variable" field in the inspector, none of my global variables show up.

Unity version:
2019.4.0f1
Game Creator version:
1.1.9

Just wanted to add, if I use a different variable action, like "assign string to variable", the global variables show up as expected, am I using the List Variable wrong?

Answered

This is one of these problems that might be more easily resolved using a custom code snippet rather than Actions. However, you can still get away with this my using the Loop List Variables Action. If your List Variables is of type Game Object, it will execute an Action for each of the List Variable values.


For example, if your list variable has "game object A" and "game object B" as its elements, executing an Action that uses the "Debug Name" action set as Invoker, will print the name of "game object A" and "game object B" afterwards.

You could use this to instantiate a UI image for reach element inside your List Variable and display it in a Canvas. Hope this helps!