Dynamic Object Number Ordering Problem [SOLVED]

This forum is currently in read-only mode.
From the Asset Store
This is a single chapter from the "Construct Starter Kit Collection". It is the Student Workbook for its Workshop.
  • Hello! Right now I'm prototyping a turn-based sort of game. You move units around and it creates a wall behind themselves, kind of the same way snake does. <img src="{SMILIES_PATH}/icon_e_wink.gif" alt=";)" title="Wink" />

    The trouble I'm having is, when you move a unit it spawns a tail piece that I'd like to give an individual private variable number to. Something like, if you move 4 spaces, create a trail of 4 tail pieces and number them 1, 2, 3, 4. I could give them a private variable when I spawn them, but I'd like it so if you lost a piece, the rest would be able to adjust accordingly.

    For example, The unit has 4 pieces: 1, 2, 3, 4. Looses the number 3 piece then the others would recalculate their variables to 1, 2, 3 instead of 1, 2, 4.

    If you want more info let me know. I've been searching keywords on the forum for an hour or two so I'd really appreciate a helping hand here! Thanks so much! <img src="{SMILIES_PATH}/icon_e_biggrin.gif" alt=":D" title="Very Happy" /> <img src="{SMILIES_PATH}/icon_e_biggrin.gif" alt=":D" title="Very Happy" /> <img src="{SMILIES_PATH}/icon_e_biggrin.gif" alt=":D" title="Very Happy" />

    Cap file:

    mega.co.nz ... BkCNdaADf8

  • I am guessing you could use a for each, sorted by IID.

    When object.IID = 0 reset a counter to 1 which increments with 1 each time its assigned to tail piece.

    counter = 1

    event

    for each tail order by tail.IID ascending

    sub

    tail.IID = 0

    action

    set counter to 1

    sub

    blank event

    action

    tail set variable tail.number = counter

    add 1 to counter

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • SpookySkeleton

    Give the tail pieces a private variable called "index".

    Then every time you create a tail piece set their index to -1. Finally to do the ordering use a "for each ordered" loop:

    For each tail ordered by tail.value('index') ascending

    --- tail: set index to loopindex

    That will make the tail piece right behind the player always be 1 counting up to the oldest one. This loop also cleanly handles destroying pieces, so they will be recalculated correctly.

  • lennaert

    Thanks guys! This solved my problem, and more!

    R0J0hound

    woof woof!

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