How do I skip a value in a for loop?

0 favourites
  • 7 posts
From the Asset Store
For Adventure, Action, Heroes, Sci-fi and Action-RPG games.
  • Hello, I'm working on a selection system in Construct 3 where clicking on an object toggles its state. I've successfully implemented the toggling functionality for the array, but I can't seem to update the states of all non-selected items.

    Currently the array consists of object UIDs on the X axis and boolean values(0 or 1) on the Y axis.

    My goal is to untoggle every other object each time an object is clicked and toggled. I'm trying to figure out how to exclude a value from X axis from the loop then pick only the values except for the excluded one.

    Thank you very much in advance.

  • Array Structure:

    The X axis holds object UIDs (unique identifiers).

    The Y axis holds boolean values (0 or 1) to indicate whether an object is selected (1 for selected, 0 for not selected).

    2. On Object Click:

    When an object is clicked, toggle its boolean state (0 to 1, or 1 to 0) in the array.

    Then, loop through the array and untoggle (set to 0) every other object, excluding the one that was clicked.

    3. Event Structure:

    1. On Click Event:

    Use the On clicked condition to detect the object that was clicked.

    Get the UID of the clicked object.

    2. Toggle Clicked Object:

    Find the clicked object's UID in the array and toggle its boolean value.

    This will toggle between 1 (selected) and 0 (unselected).

    3. Untoggle Other Objects:

    Use a loop to iterate through the array and untoggle every other object by setting their boolean value to 0, excluding the clicked object.

  • Since you have isActive variable on on the icons, why do you need an array to keep selection state? This task can done a lot easier without it.

    I also suggest using number type variables (0/1) instead of boolean, it's easier to work with them in Construct.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Since you have isActive variable on on the icons, why do you need an array to keep selection state? This task can done a lot easier without it.

    I also suggest using number type variables (0/1) instead of boolean, it's easier to work with them in Construct.

    I am very aware of the easy way to implement this feature, but the reason why I have it as an array form is because:

    1) These objects are dynamically created and tied to multiple of inventories that perform individually from each other(i.e. dozens of these objects are tied to inventory A, another dozen to inventory B, etc).

    2) These objects are drag and droppable and will involve sorting and reordering as well since they are in an inventory.

    3) Due to above reasons I figured using arrays will be significantly more efficient.

    So going back to the original question, I want to ask how to set up condition-action sequence that will jump an iteration during a loop, since it seems like Construct 3 does not have built-in continue statement.

  • So I did eventually manage to get the array toggle to work by just squeezing bunch of conditions and a couple of Stop loops. I probably optimized it horribly but at least it works. But now I can't seem to pick the objects properly. How do I properly pick objects in a structure like this?

  • Working with arrays in Construct is not fun, it's a lot easier to manipulate instance variables, and then copy them into the array.

    So I would toggle the icons like this:

    And when the inventory is closed - copy them back into the array. For example:

    For each Icon ordered by Icon.ID
    .. Array set value:Icon.isActive at X:loopindex
    

    You can create a helper function WriteToArray and call it every time any icon in the inventory is changed - toggled state, dragged and dropped, re-sorted etc.

  • Working with arrays in Construct is not fun, it's a lot easier to manipulate instance variables, and then copy them into the array.

    So I would toggle the icons like this:

    And when the inventory is closed - copy them back into the array. For example:

    > For each Icon ordered by Icon.ID
    .. Array set value:Icon.isActive at X:loopindex
    

    You can create a helper function WriteToArray and call it every time any icon in the inventory is changed - toggled state, dragged and dropped, re-sorted etc.

    I see. Thank you for your suggestion. I will probably just stick with your method of managing arrays and objects. It is indeed a pain manipulating arrays real time in Construct 3..

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