How can I use an array to keep the score for many layouts?

Get help using Construct 2

Post » Tue Oct 06, 2015 4:15 am

I don't really understand arrays that much. All I know is, they allow information to be transfered between different layouts and event sheets, unlike global variables, which are limited to just the event sheet they are on. I am trying to keep the score going for the game as the player progresses through each layout/level. I use a text to display the score. When he gets to level 2, how do I tell it to use level 1's "Score" global variable's information and transfer it to level 2? And same for other levels, I would like to make level 3 use either level 1 or 2's "Score" global variable. I don't know how I would do that. I made separate score variables for each level. i.e. "Score" for layout 1/level 1, "Score 2" for layout 2/level 2, and so on. I tried setting "Score 2"s information to "Score" so it can keep the same score using an array. I don't know. This is how I tried doing it and it didnt work, but then again I don't really understand arrays. Does anyone know how to do this? I would greatly appreciate the help!
B
11
S
1
Posts: 27
Reputation: 583

Post » Tue Oct 06, 2015 7:41 am

Create an event sheet called variables. Now put all your variables into that sheet.
Now whenever you want to use a variable in an event sheet. Include the event sheet called global variables.

Arrays are the best for data, but totally overkill for something as simple as a variable. Dictionary is better suited as it acts like a variable, but again overkill.

Include your global variable event sheet into your level event sheets.
You think you can do these things, but you can't, Nemo!
Just keep reading.
Just keep learning.
B
65
S
16
G
9
Posts: 1,429
Reputation: 12,718

Post » Tue Oct 06, 2015 12:01 pm

SebastianOs wrote:I don't really understand arrays that much. All I know is, they allow information to be transfered between different layouts and event sheets, unlike global variables, which are limited to just the event sheet they are on.


are you sure?

Manual wrote:Global variables store their values between layouts. Events in any layout can access any global variable...


Event Variables

DUTOIT wrote:Arrays are the best for data, but totally overkill for something as simple as a variable....
Create an event sheet called variables. Now put all your variables into that sheet.


well...let's say ..I have the 100 levels in the game and want to know the Score for each level...
I think it's better to have one Array object than 100 Variables...(Level1_Score; Level2_Score;..Level77_Score..)
...but I could be wrong..
B
67
S
24
G
7
Posts: 1,518
Reputation: 11,072

Post » Tue Oct 06, 2015 12:28 pm

korbaach wrote:well...let's say ..I have the 100 levels in the game and want to know the Score for each level...
I think it's better to have one Array object than 100 Variables...(Level1_Score; Level2_Score;..Level77_Score..)
...but I could be wrong..


Well in this situation a array would be best. I under the impression OP wanted to carry level 1 score to level 2 to level 3 etc.
But, if he wants to store a score for each level then array would be best.

Store level / score
Array Push back "Score" on X axis
Array Set value at (array.width-1, 1) to level
Array set value at (array.width-1, 2) to score


Fetch Level / score
Array for each x element
System compare array.at(array.curx) = "Score"
System compare array.at(array.curx,1) = level

Add action to return score so set text array.at(array.curx,2)
You think you can do these things, but you can't, Nemo!
Just keep reading.
Just keep learning.
B
65
S
16
G
9
Posts: 1,429
Reputation: 12,718

Post » Tue Oct 06, 2015 12:45 pm

Well...I might have been misguided with
SebastianOs wrote: I made separate score variables for each level. i.e. "Score" for layout 1/level 1, "Score 2" for layout 2/level 2, and so on. ...


..it would be best to Os better explain his problem, now that he knows that the global variable are global.. not "limited to the event sheet they are on"...it may be enough only one variable Score for all levels :)
B
67
S
24
G
7
Posts: 1,518
Reputation: 11,072


Return to How do I....?

Who is online

Users browsing this forum: jezjones24, Lancifer, matriax, newt, R0J0hound and 25 guests