How do I pick UID in context

Just started using Construct 2? Post your questions here

Post » Thu Mar 06, 2014 2:09 pm

Hello,

I made a transparent sprite who spawn one or more sprite.
Sprite instance generated have instance variables as a keyboard key (like 'R' for representing 'R' of the keyboard and a Red bullet on the player's screen)
Each time a sprite is spawn, i put the uid's sprite in an array

when a sprite spawned meets a condition that is too late for player for typping the key, i remove the uid in my array and i destroy the sprite (referenced by condition on Sprite)
A user's action can make destroy before meeting condition just explain before by typping the good key.

I want to destroy the first Sprite who correspond in my array to the key pressed.

this is a representation of my array when users press a key
[0]=32
[1]=33
[2]=35
[3]=36
[4]=37
[5]=38
[6]=39

[index] = uid of sprite

I have already made a loop on the array to find Sprite by uid and find the first Red Bullet sprite to destroy and then stop loop
My question is about how to find the first instance with key=='R' in their instance variable.
Can somebody explain or show me an example?
I check for uid documentation but i only found that uid is unique and defined at runtime now the way to get the Object behind an UID.

Thanks a lot!
B
8
S
2
Posts: 35
Reputation: 838

Post » Thu Mar 06, 2014 2:39 pm

this is my condition/subcondition and actions
(i use the example with 'R' key pressed

Condition/subcondition :

System => For "bulletsLoop" 0 to bulletsAlive.Width
System => Bullet(bulletAlive.At(loopindex)).key == "R"

Actions :
...
bulletsAlive => delete loopindex from X axis //keep the array up to date
System => stop loop //don't go further

How can i get the instance returned by Bullet(bulletAlive.At(loopindex)).key == "R" ?
B
8
S
2
Posts: 35
Reputation: 838

Post » Thu Mar 06, 2014 3:05 pm

I found a solution by replacing the loop for with a loop foreach.
https://www.scirra.com/tutorials/418/for-each-tutorial
In fact it seems that in foreach loop it set the instance variable and it's not the case of loop for...
B
8
S
2
Posts: 35
Reputation: 838

Post » Thu Mar 06, 2014 4:18 pm

The loops seems working but no... i'm wrong
anyone knows how to retrieve a specific Sprite from it's uid and make action on it?
B
8
S
2
Posts: 35
Reputation: 838

Post » Fri Mar 07, 2014 8:23 am

Doesn't "Pick by UID" work?
B
84
S
22
G
15
Posts: 1,039
Reputation: 15,249


Return to Beginner's Questions

Who is online

Users browsing this forum: shawnzien and 2 guests