I want to go through some text variables stored in groups of variables in Array Variables which i want to see using text object. I don’t even know where to start.
Imagine you have array variable called MyArray
It have 3 child vars
So they are
0
1
2
Since they don’t have names but instead index numbers you reference them with
MyArray[0]
MyArray[1]
MyArray[2]
What you also can do is
MyArray[SomeNumberVariable]
Where that number var can be object scene or global it does not matter as long as its number var
And now you can go with
Condition
Space key is pressed
Trigger once
Action
Chane SomeNumberVariable ADD 1
Chane SomeNumberVariable SET TO mod(SomeNumberVariable,3)
And when you hit space it will go 0 1 2 0 1 2 0 1 2 0 1 2 and so go on
You need there 3 since index numbers start from 0 so its accounted as number
0 = 1st
1 = 2nd
2 = 3rd
And so with that you are looping/cycling trough your array child vars
Going even deeper
Condition
Space key is pressed
Trigger once
Action
Chane SomeNumberVariable ADD 1
Chane SomeNumberVariable SET TO mod(SomeNumberVariable,VariableChildCount(MyArray))
And now you can add child vars left and right
And you don’t need to update that number in mod expression since it automatically set number to loop trough to how many child vars you have
I had problem with this so just to give you heads up
You have Structure var called MyStructure
With child var called MyArray
And you want to display value of child of MyArray
Then
MyStructure.MyArray[0]
Let’s imagine that 1st child at index 0 have its own child var
For example called SubChild
Then
MyStructure.MyArray[0]SubChild
Now you should have perfect understanding how to display them as you please
VERY useful for weapon list like even cycling trough weapons
Not to mention stats abilitlies skills and whatever else
I am saving the object variables in global Array variable and I want to see the text variable using text object
I tried doing as you said at least how much I can understand
Game is Structure variable and Barncreator is Array
Create number scene variable and call it Shift
NOW
1 - Shift
2 - mod(Shift,VariableChildCount(Game.BarnCreator))
3 - Game.BarnCreator[Shift]
3 - If above don’t work then ToString(Game.BarnCreator[Shift])
Now just so you are aware
Your 1st event from your last screenshot have condition Right key released
So duplicate that event
And in duplicate in condition you change from Right to Left
In action (1st action) you change Add to Subtract
Other thing you most likely DO NOT NEED but CAN do
I mean if your array is not LOOOOOOOOOONG
IS
Change text set to
ToString(Game.BarnCreator[0])+"
"+ToString(Game.BarnCreator[1])+"
"+ToString(Game.BarnCreator[2])+"
"+ToString(Game.BarnCreator[3])+"
"+ToString(Game.BarnCreator[4])+"
"+ToString(Game.BarnCreator[5])+"
"+ToString(Game.BarnCreator[6])+"
"+ToString(Game.BarnCreator[7])
But that i tell you that you CAN do it
Where it makes absolutely NO sense if you have A LOT child vars in array
Where just so you are aware how to make new line
ToString(Game.BarnCreator[0])+"HoldLeftShift And Press Enter
"+ToString(Game.BarnCreator[1])+"HoldLeftShift And Press Enter
"+ToString(Game.BarnCreator[2])+"HoldLeftShift And Press Enter
"+ToString(Game.BarnCreator[3])+"HoldLeftShift And Press Enter
"+ToString(Game.BarnCreator[4])+"HoldLeftShift And Press Enter
"+ToString(Game.BarnCreator[5])+"HoldLeftShift And Press Enter
"+
This is how you place multiple lines of text displaying different variables at once using ONE text object
But again stupid if you have a lot of child vars
You gonna flood your text object with them
Game.BarnCreator is an array. Adding 1 to it makes no sense, nor setting it to mod(…). That loses the array elements and changes Game.BarnCreator to a single number.
If you want to go through the elements in an array, use the “For each child variable (of a structure or array)
” event:
It might be easier as an array of structures.
Create an array variable with a single structure and a seperate variable with the same structure children. The name of the variables can be whatever but the children need to match.
I used List and Struct
The reason I added a structure to the array is so you can use the autocomplete list for the structure names. We’re going to remove the children before using the array. So, the structure values are meaningless.
This is the autocomplete. After you click a child name. You just need to change the index to a variable… mber or variable or any expression that returns a number.
The struct variable is used to add the structure to the array but also used with the for each child to get the values from each element. By default, for each child uses child. Just change that to the name of your structure variable. In my case, I used Struct.
These are my test events.
I had several text objects in the scene already. I gave them each a random number for testing instead of manually typing a different text.
Using for each object, It copies the position and text to a structure and then adds the structure to the array which was cleared before it started.
Then to add new text objects or get their values you then either use another for each object or choose the index with a number or variable or any expression that returns a number.
Instead of deleting the existing objects, I shifted them a little to the right. That was so I was able to verify that the right values were used.
My result.
So i did as you said and it is toggling through variables but one problem is that chosen variables i want to show are always after 5 variables how can i do it so it skips 0 1 2 3 4 and goes to 5 and then again skips 0 1 2 3 4 and keeps going like that.
You are right when I tried for the first time i was getting 0
I am going to read the wiki you linked
i see but i also need to save and because some objects have too many variables…
but I think it is a good solution for the variable that players can toggle through
Make condition
Shift is less than 5
Action
Change shift set to 5
IDKW you mean by too many variables. If you’re saving object variables, you can add variables 1 by one or if the objects use a variable that’s a structure that contains all of the other variables as children , you can save the entire structure a lot easier. It may involve using the Json format to save the structure as text but IDK your complete goal. So, I can’t comment any further because I’m already making a bit of a wild guess that might not apply.
i did it but it just does it once then not going again
Show me your events
zzzzzzzzzzzzzzzzzzzzzzz
1 - Leave it as it is
2 - CUT OUT both conditions and action and paste them to NEW separate event
In that new event you only need to need to add action on top Change variable Shift ADD 1
i think there might be a misunderstanding it is skipping the very first 5 variables and mine is doing that but as i said above i want it to keep skipping 5
variables
if there are 15 variables it goes to 5 10 15 And like that
OW MY GOD
Me love engrish
So instead of add 1
Add 5
BTW remove this