How do I destroy first of instances?

Not favoritedFavorited Favorited 0 favourites
  • 8 posts
From the Asset Store
Scrollbars with FULL functionality and versatility, just like the ones you can find in AAA games!
  • Hello

    I'm actually working on a game where I can throw swords in the walls and use them as a ladder in a 2d side view plateformer.

    I want my character to be able to stuck like 10 swords maximum at a time. So when he throw the 11th, the first one (the oldest) that he threw is destroyed. Same goes for the 12th (destroying the 2nd) etc...

    For the sake of clarity there is one sprite (of a whole sword) that is thrown using the mouse click by the player. And when the sword collide with a wall, it get stucked, turn invisible and I spawn a different sprite of a sword stuck hallfway throught at the same position and angle.

    I already made a global variables that track each time a SwordStuck sprite is created to keep track of the number of sword for my player (because all the flying sword arent mandatory to end in a wall, so I d rather track the sword planted in the wall are thoses are the ones I want to limit).

    I tried different solutions using chatgpt, looking for answer in forums and asking friends of mine, and I can't seems to managed to delete the oldest instances.

    Thanks a lot for the help

    sorry for the grammar, english isn t my first language.

  • System compare two values Sword.count>10
    System pick Sword instance number 0: Sword destroy
    
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Maybe this will work:

    System -> compare two values -> SwordStuck>10

    System -> pick by highest/lowest value -> lowest (Sword.UID) Sword -> Destroy

  • Hello,

    When I do

    "System -> compare two values -> SwordStuck>10

    System -> pick by highest/lowest value -> lowest (Sword.UID) Sword -> Destroy"

    When the eleventh sword is spawned, all the previous sword are deleted instead of juste one. And it now become impossible to even stuck 1 sword anymore, they get inst deleted

  • Hello,

    When I do

    "System -> compare two values -> SwordStuck>10

    System pick Sword instance number 0: Sword destroy"

    When the eleventh sword is spawned, all the previous sword are deleted instead of juste one. And it now become impossible to even stuck 1 sword anymore, they get inst deleted

  • Hello,

    When I do

    "System -> compare two values -> SwordStuck>10

    System pick Sword instance number 0: Sword destroy"

    When the eleventh sword is spawned, all the previous sword are deleted instead of juste one. And it now become impossible to even stuck 1 sword anymore, they get inst deleted

    Maybe you need to substract 1 from the variable SwordStuck in the same event. Otherwise if the variable Its at eleven or more it will continue destroying all the swords.

  • Why do you need the SwordStuck variable at all? Just use Sword.count expression

  • Thanks you so much Superxonic it work perfectly with the "substract 1 from the variable SwordStuck".

    Thank you all very much fot all the help

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