[SOLVED] Having weird issues using arrays

0 favourites
  • 4 posts
From the Asset Store
With this template you will learn how to use the GooglePlay Games native plugin
  • Hello,

    I'm trying to create a system where you can grab a total of 3 keys and they'll create a queue in your back, following you anywhere. Once you touch a locked door, the first key you grabbed will be used and destroyed, and the rest will take the next place in the queue. I used an array to make this possible.

    Now, the problem comes with the order in which I grab the keys. If you coincidentally grab them by UID order, lower to higher, the system works perfectly fine, otherwise it will take 2 keys or even all the keys to open 1 single door.

    I've remade it in a new clean project and the issue keeps happening, here's the C3P

    dropbox.com/s/t3bh397k4ox8ye4/keys.c3p

    Thanks for your help!

  • I redid your events in a group called simplified. Have a look here: 1drv.ms/u/s!AkmrWgxeuxlKhItm6Td4wPJp_rc_Kw

    There were a few things that were causing the issues. You needed to pick the key based on the UID stored in the array, not just compare it. You also were popping and pushing from the same end of the array meaning you weren't getting the first in first out behaviour you were after, and you had some unnecessary variables and events including your for each loop which was causing some issues.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I redid your events in a group called simplified. Have a look here: 1drv.ms/u/s!AkmrWgxeuxlKhItm6Td4wPJp_rc_Kw

    There were a few things that were causing the issues. You needed to pick the key based on the UID stored in the array, not just compare it. You also were popping and pushing from the same end of the array meaning you weren't getting the first in first out behaviour you were after, and you had some unnecessary variables and events including your for each loop which was causing some issues.

    Ooh I see what I did wrong. I thought by using the bool condition the picking would be done automatically, and then if the element 0 of the array matched, then the actions could work. But the event you used is literally what I needed!

    Thanks for your help calminthenight.

  • The for each loop and check against the array UID would work, the only problem is that it would execute more than one time as the actions would happen "for each" key on every door collision trigger. This was why more keys were getting used. Removing the loop and using pick means that only one key is used per door.

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