Quick Array Question about Push

Get help using Construct 2

Post » Thu Nov 24, 2016 1:27 am

I understand Pop and Push.
I am having trouble understanding how to choose the bottom Y when trying to change values.

I have a 2,1,1 Array. It is used to pre-select random numbers to prevent reloading to so the player can't cheat in the game. The game has to currently keep track of two random numbers.


X0, X1


What I would like to do is add a Function that will add a row to the bottom and change it.
I will also have a Function that Pops the top row, I already know how to do this though.

After adding a row to the bottom how do I then change the bottom row.

X0, X1
X0, X1

Do I have to use a variable to keep track of the bottom row, or is there another way of just changing the bottom row?

In the Parameters for Push I am not understanding what "Value" means. If I have two values on the axis why is it only asking for one?
B
68
S
37
G
13
Posts: 241
Reputation: 12,785

Post » Thu Nov 24, 2016 1:36 am

The bottom of the array index is Array.Width-1.
Array.Push
Array.SetAt(Array.Width-1,0) = XXX
Array.SetAt(Array.Width-1,1) = YYY
ImageImageImage
B
71
S
22
G
258
Posts: 3,791
Reputation: 143,198

Post » Thu Nov 24, 2016 1:56 am

Thanks I got it.

Basically the same I do with objects to figure things out like that.

;)
B
68
S
37
G
13
Posts: 241
Reputation: 12,785

Post » Thu Nov 24, 2016 2:06 am

While we are on the topic I have another question.

Is there a difference in using instance variables to store in data over using an Array?

To me using an array seems like it would be worst because instead of just having the info it has to look for it.
B
68
S
37
G
13
Posts: 241
Reputation: 12,785

Post » Thu Nov 24, 2016 2:39 am

It really depends on what you are doing. There's no one answer.
ImageImageImage
B
71
S
22
G
258
Posts: 3,791
Reputation: 143,198

Post » Sat Nov 26, 2016 12:21 pm

Unconnected wrote:To me using an array seems like it would be worst because instead of just having the info it has to look for it.


But you can´t create some new instance variable in runtime while you can insert new data into an array whenever.
B
10
S
4
G
4
Posts: 25
Reputation: 3,194

Post » Sat Nov 26, 2016 1:27 pm

If I have an object that has an instance variable then it should have it already. There is no need to create a variable during runtime.

I suppose if an instance variable won't be interacted with for a long time it is best to use an Array.
If it will be interacted with often it is better to be a variable.
B
68
S
37
G
13
Posts: 241
Reputation: 12,785


Return to How do I....?

Who is online

Users browsing this forum: psicodelicow3, SEGamestudio and 3 guests