Loading an array with instance variables

0 favourites
  • 7 posts
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • 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!

    dl.dropbox.com/u/564834/array-tests.capx

  • 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.

  • 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.

  • 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.

  • 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?

  • 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.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Sounds good, I'll give it a go. Thanks!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)