Page 1 of 2

How do I pick only one sprite by comparission

PostPosted: Mon Jul 10, 2017 4:59 pm
by megatronx
Hi,

I'm picking sprite with boo var. boo is set to inform weather sprite is free to pick or not. However sometimes i have more then one sprite free to pick, and picking by comparison picks all of them. I tired fixing this with trigger once, but it doesn't seam to help. Any suggestions welcome. Also, if anyone knows how to do "on picking failed", so I can do another action if there are none sprites to pick that would be ace. Cheers

Re: How do I pick only one sprite by comparission

PostPosted: Mon Jul 10, 2017 5:31 pm
by Aphrodite
When no sprites are picked at all, an else will trigger (it's actually the only time you want to use else with a picking condition).

As for you first issue, try adding a condition system: pick Nth instance or pick random instance depending on your need after your conditions.

Re: How do I pick only one sprite by comparission

PostPosted: Mon Jul 10, 2017 6:05 pm
by conker23
One idea : instead of having a boolean, you could have an instance variable "ID" and a global variable "NumberOfInstancesAvailable". When a new instance is available, ,you attribute the value "NumberOfInstancesAvailable"+1 to the ID and then you add 1 to NumberOfInstancesAvailable.
When you pick an instance, instead of checking all instances with boolean set to true, you pick the instance which ID is such that ID=NumberOfInstancesAvailable and you substract one to NumberOfInstancesAvailable.

Re: How do I pick only one sprite by comparission

PostPosted: Mon Jul 10, 2017 6:06 pm
by conker23
I hadn't seen the post of aphrodite. I didn't know these commands, it looks great :)

Re: How do I pick only one sprite by comparission

PostPosted: Wed Jul 12, 2017 6:57 pm
by megatronx
Aphrodite wrote:When no sprites are picked at all, an else will trigger (it's actually the only time you want to use else with a picking condition).

As for you first issue, try adding a condition system: pick Nth instance or pick random instance depending on your need after your conditions.


Hi,

So you're saying that my event should look like more like this: Sprite.BooIsAvaible = 1, Pick Nth instance of the sprite? Will it only pick one instance and move on, or will it pick all nth instances? I'll check that out.

@conker23 I tried similar approach, but it didn't work. I might look in to it again and try different approach if Aphrodites way won't work.

Re: How do I pick only one sprite by comparission

PostPosted: Wed Jul 12, 2017 7:25 pm
by Aphrodite
pick Nth imstance will pick the nth instance (1st or 2nd or 3rd or 4th etc...) not multiple instances AFAIK

Re: How do I pick only one sprite by comparission

PostPosted: Wed Jul 12, 2017 7:29 pm
by megatronx
Aphrodite wrote:pick Nth imstance will pick the nth instance (1st or 2nd or 3rd or 4th etc...) not multiple instances AFAIK


Sweet, thx

Re: How do I pick only one sprite by comparission

PostPosted: Thu Jul 13, 2017 3:49 pm
by megatronx
Aphrodite wrote:pick Nth imstance will pick the nth instance (1st or 2nd or 3rd or 4th etc...) not multiple instances AFAIK


Yo, any clue how can I use that nth instance picking without knowing IID? Or get IID of one object from many that have boo set true.

Re: How do I pick only one sprite by comparission

PostPosted: Thu Jul 13, 2017 4:45 pm
by plinkie
Sprite > Boolean=true.
Pick sprite nth instance 0.

You now have the sprite where Boolean=true with the lowest IID. Sprite.IID in actions is now the IID of the picked sprite so it's knowable.

Re: How do I pick only one sprite by comparission

PostPosted: Thu Jul 13, 2017 5:18 pm
by megatronx
plinkie wrote:Sprite > Boolean=true.
Pick sprite nth instance 0.

You now have the sprite where Boolean=true with the lowest IID. Sprite.IID in actions is now the IID of the picked sprite so it's knowable.


Ah man, gotch ya. So it is 0 based index of picked sprites and not of all sprites IID's, correct? And thx. Althought. literaly the moment you wrote your post, I've changed from reusing existing sprite in to destroying and creating them. And it worked. After seeing your post I've fixed the reusing sprites events, and they work too. Interestingly, I don't see any difference in performance between both ways ( thought at first glance I'm leaning towards spawn/destroy option having better fps). I thought from some old topics, that creating objects is more taxing o the framerate. I guess I'll have to check for average fpx.