How do I fix array retrieval problem?

Get help using Construct 2

Post » Mon Jun 29, 2015 1:40 pm

Hello World.

Ok, this might get dizzy so sit down and bare with me please.
My game has 50 levels and 3 difficulty modes, so I use an array to store the score for width(51):LevelNumber and height(4):Difficulty(I use 51 and 4 becaue I don't want to store at 0,0). "LevelNumber" and "Difficulty" are global variables.
We have 3 layouts:
- Main: where you have start game, options, quit, etc. (this is where the game boots up)
- LevelSelector: where you choose what level you want to play and the difficulty (you are taken here when you press "Start Game" on the main layout)
- Level 1: the first level of the game

Now on the LevelSelector I have sprites for all the levels, each sprite has 4 spritefonts on it as follows: first spritefont-the level name, second spritefont-"Easy: ", third spritefont-"Medium: " and forth spritefont-"Hard: " . The layout olso has 2 list objects, one to select your level and another to select your difficulty and another sprite(button) when you press it, it takes you to the selected level and difficulty and sets the global variables for those.
So you play a level(all levels share the same event sheet) and at the end of the level I have event: If the array value at(LevelNumber,Difficulty) < Score then action set value at(LevelNumber, Difficulty) to Score.(score is another global variable)
The problem is that now when I come back to the LevelSelector layout, if I want to show those scores I have to create on start of layout a different action for each spritefont!!!!.... so 50 levels x 3 difficulty modes=150 actions....
Imagine on start of layout:
Level1Easy(a spritefont object) | Set text to "Easy: " &Array.At(1,1)
Level1Medium(a different spritefont object) | Set text to "Medium: " &Array.At(1,2)
Level1Hard | Set text to "Hard: " &Array.At(1,3)
Level2Easy | Set text to "Easy: " &Array.At(2,1)
....
....
....
Is there a way to make this retrieval easier without using soooo many actions? Idealy I would want at start of layout to read the variables LevelNumber and Difficulty(which have been set by the level you just played) and then modify the correct spritefont that is chosen based on the number of those variables.
So what do I do, create a second array for the spritefonts? But then how do I put objects in the correct place in the array without again having 150 events telling C2 what object corresponds to what value.....
I've been sitting starring at the screen for about 1 hour now and I can't figure this out.....
Maybe I am overthinking it? Does it even matter(performance wise on mobiles and tablets) if I have so many actions on a start of layout event requesting things? Cause if it's just a "cleaner code" issue I could live without it....
Thoughts, suggestions?

Thank you.
B
21
S
11
G
6
Posts: 414
Reputation: 5,335

Post » Mon Jun 29, 2015 4:16 pm

Hello.

So I'm not sure I know exactly what you're talking about, but I am guessing you are having trouble referencing the right... stuff. :?

Usually, using multiple objects is a bad idea, not just for lag but for a clean project. If I were you I would redo the sprites to be one object with - if they aren't animated - one animation and several frames. When you set the speed to 0, and reference the frame number, you'll always get the one you set up in the animations window.

Now on to the actual issue. If you have multiple objects, and don't like the idea of using the above method, you can combine them in a family with an instance variable you can identify each one by (don't use UID or count, they're unreliable). This way you can assign a different ID to each object in the editor. You can then do the same with the text boxes; [condition] > set text (array(ID), array(ID/something else))

Hope that helps. If it doesn't, a screenshot or something might help.
B
42
S
14
G
3
Posts: 165
Reputation: 5,115

Post » Mon Jun 29, 2015 4:44 pm

Yeah, I forgot about the instance variable. I suppose I could use it to give each spritefont object a unique id, and then put those ids into another array and then correlate the 2 arrays to get the desired effect....
I'll give it a try, thanky you.
B
21
S
11
G
6
Posts: 414
Reputation: 5,335


Return to How do I....?

Who is online

Users browsing this forum: Mayfly and 6 guests