Loading an array with instance variables

Get help using Construct 2

Post » Mon Mar 11, 2013 5:46 am

Working on a grid-based puzzle with a 3x3 layout. Each cell contains the numbers 1-9, and when the player clicks on a number it increases. The goal is to set a certain pattern.

Brief overview of how I built the events/actions:

* Click a grid space to increase its instance variable by one
* Every tick, for each XY element, set the CurX/CurY values to the instance variables. Also set the displayed text to the same.
* For testing purposes, switch layouts and see a text readout of the cells.

I can get this to work just fine, but when I return to the original layout, the array always resets. I've tried different solutions but each one breaks the setup in some way, usually setting the entire array to output a single number.

I've read through the manual and tutorial on arrays, but there's obviously something I'm missing with either object instances or arrays, because this is just not working out. Test .capx file included below. Any help would be appreciated!

https://dl.dropbox.com/u/564834/array-tests.capx
B
7
S
1
Posts: 8
Reputation: 720

Post » Mon Mar 11, 2013 6:23 am

A layout resets it's elements when you go to it. This is expected behaviour. The fix is not to do this. You are just testing, so use a different mechanism. Look up the ChromeConsole for an easy way to write debugging text, or use a Layer, which you toggle visible/invisible.blackhornet2013-03-11 06:24:24
ImageImageImage
B
67
S
19
G
124
Posts: 3,219
Reputation: 74,425

Post » Mon Mar 11, 2013 8:01 pm

Right, but an array doesn't reset between layouts, correct? I need to set the grid to remain as the player left it no matter which layout he/she goes to.
B
7
S
1
Posts: 8
Reputation: 720

Post » Mon Mar 11, 2013 9:22 pm

The array doesn't reset but in event 3 you're setting every value in the array to the gridNumber of the first text box. When you reload the layout the gridNumber is reset to 1 so every value in the array is set to 1.
B
54
S
28
G
18
Posts: 1,520
Reputation: 25,020

Post » Mon Mar 11, 2013 11:42 pm

This is where I run into problems. When I try setting the grid cells to display data from the array, all I can do is set the ENTIRE grid to display a single value. How can I set it to run through each instance's gridNumber and set it to the appropriate array coordinates?
B
7
S
1
Posts: 8
Reputation: 720

Post » Tue Mar 12, 2013 12:11 am

One way is to store the grid coordinates on each textbox. They never change. Then use the coordinates to store the data into the array. You can then do a ForEach textbox to get the data back out of the array. Also, set the array sizes in the GUI, as the On start Set size may clear the data.
ImageImageImage
B
67
S
19
G
124
Posts: 3,219
Reputation: 74,425

Post » Tue Mar 12, 2013 8:56 pm

Sounds good, I'll give it a go. Thanks!
B
7
S
1
Posts: 8
Reputation: 720


Return to How do I....?

Who is online

Users browsing this forum: Lof, Yahoo [Bot] and 24 guests