How do I choose an instance of a sprite based on its instance variable while looping?

0 favourites
  • 3 posts
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • I have a Level Select layout with 9 instances of a level icon sprite. The sprite has 10 frames, 0 being a "lock" icon and frames 1-9 being an icon with the level number on it.

    Each level icon has an instance variable called "Index" which has the level name: "1-1", "1-2", "1-3", etc. (The first "1" is for the Area--like the "Worlds" in a Mario game--because I plan to add more Areas later).

    I also have a LevelUnlocksArray that keeps track of which levels the player has unlocked so far. To make it easier for myself, the X coordinate represents the Area number (remember, only 1 so far) and the Y coordinate represents the Level number (there are 9 in total). For example, the unlock value (0 or 1) for level 1-3 would be found at X=1, Y=3. (I know it's not 0 indexed this way but it makes it easier for me to remember where things are.)

    So here's my problem:

    On the start of the Level Select layout, I'm looping through the LevelUnlocksArray to figure out what frame each of my Level icon sprites needs to be at. If the value at [1,2] is 1, then I want to pick the Level sprite whose instance variable is "1-2" and change the frame of that specific instance from frame 0 (a lock picture) to frame 2 (a picture of a "2").

    Unfortunately, nothing happens. All the level icons remain "locked" (so they're at frame 0 instead of changing to the frame showing their level number).

    Here's the logic:

    And here's the project:

    drive.google.com/file/d/1-MLn4d0Ki72nUBrdgL5fMlXW9Acp6Bzs/view

    (The values are being inserted into the Array in the YouWinSheet, after each level is completed.)

  • You haven't sized your array correctly. It's only 10x1, but you need 10x10 - depends on Worlds & Levels needed. Use the debug option to look at the array data, and you see immediately, there's just a one-D array.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You haven't sized your array correctly. It's only 10x1, but you need 10x10 - depends on Worlds & Levels needed. Use the debug option to look at the array data, and you see immediately, there's just a one-D array.

    Thank you!

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