Method for changing the value of a variable in an array

I created one text object “NewText” and assigned the variable “ID”.
Then I moved the object to the scene and duplicated it 4 times.
For each object on the scene, I changed the value of the “ID” variable.

I have created an array “Array” and a global variable “Index”. There are 4 child variables with different values in the array.

The text on the scene will display values from the array depending on the variable “ID” of the “NewText” object. The global variable “Index” will change depending on the key pressed by the user.

If the “Up” key is pressed - subtract 1 from “Index”
If the “Down” key is pressed - add 1 for “Index”
(and the “Arrow” object, which I did not specify, changes position).

Yes, this is the mechanics of selecting an option using the keyboard, not the mouse.

Then I created a list of events:

When the user clicks on the “Left” button, the value of the child variable is subtracted depending on the global variable “Index”.
And for this, I have to specify a specific element from the array.

Is it possible to change the value without specifying a specific element from the array?

You have Array[3]
3 is number
How about you make number var for your text object
And now you can Change the variable Array[NewText.NumberVariable]

And now you would only manipulate value of your NewText object NumberVariable to change what it display

I mean you change text to this for each text object Array[NewText.NumberVariable]

And now with up or down you change NewText NumberVariable

1 Like

Excuse me, can I see a visual example in the form of a list of events?

Now i am not sure i understand what you want to achieve
I was sure you want to have something like

You have 4 text objects
When text object is selected and up or down pressed you change text of that text object but not of any other text object
And that is what i gonna describe below

Look at your screenshot

On top you have action change text to Array[NewText.ID]
You are changing text of each object to whatever ID var have your text object

My most stupid idea is to add to each text object another number var let’s call it Shift

And now you would change text to Array[NewText.ID+Shift]
For each object Shift variable should be set to 0 in variable window

But now when pressing up or down when text object is selected you change its Shift variable and it will display different text

In case you meant something else like you want by pressing up or down shift actual text that is displayed for each object

FOR EXAMPLE

You have

10
20
30

You press up and now you have

20
30
10

So they moved one position up (position is the same but text changed)

But 10 from going higher which it can since it was top most text
Instead was teleported to the bottom

Then all you need is one global or scene number var again lets call it Shift
And change text to Array[Shift]

Where in separate event you need to make
Condition
Up key is pressed
Trigger once

Action
Change variable Shift SUBTRACT 1
Change variable Shift SET TO mod(Shift,4)

And another for pressing down

Condition
Down key is pressed
Trigger once

Action
Change variable Shift ADD 1
Change variable Shift SET TO mod(Shift,4)

This mod expression circles number around whatever you put in expression so if we put there 4 it will go 0 1 2 3 0 1 2 3 0 1 2 3
If we put there 2 it would go 0 1 0 1 0 1 0 1
If we put there 7 then it will be 0 1 2 3 4 5 6 0 1 2 3 4 5 6

Cause it accounts 0 as number so maximum number it will go will always be -1 what you specified

If you meant something else you need to provide screenshot how it looks in your game before you press up and after you press up
Like make changes manually and just screenshot them
So it is easier to deduce what you have in mind

1 Like

Method for changing the value of a variable in an array

I recorded a detailed video and posted it on Youtube.

Selector is just some number variable i added to bullet (in your case it would be your arrow object)

All text objects have ID vars same as yours
Starting from this one the one above have 0
And two below have 2 and 3

My array is same as yours i believe

And my events

Right now position of bullet will cycle around so if you press up while on top most position you will move bullet to the bottom
And vice versa if you press down on bottom most position

If you want to prevent that and just want to stop on top most and bottom most positions then

At this point all i need to do is just create new duplicate text object and give it +1 ID var from highest i had so far so since i had 3 this i would give it 4

Where i just would need to add now child to MenuArray and i would have new menu position
And i would not need to modify events to expand my menu list
Just new text object with incremented ID var and new child in array

1 Like

I thought that when selecting an array, it is impossible to write the expression “MenuArray[BMText.ID]”

I thought I should definitely select a certain element from the array or add a variable because it doesn’t exist.

Thank you for your help, your method works.

1 Like