How do I select only the instance that was just spawned?

Get help using Construct 2

Post » Tue Jun 21, 2016 1:47 pm

Ugg. My first instinct when I saw your code was to blame Wait, but as is, it does work, except of course if you destroy the Monster that is then later still referred to, as you painfully found out. So switch to using a Timer on Monster instead. Then if the Monster is later destroyed, the timer will be cancelled automatically. Sorry I didn't speak up sooner.
ImageImageImage
B
71
S
22
G
242
Posts: 3,734
Reputation: 134,994

Post » Tue Jun 21, 2016 2:08 pm

blackhornet wrote:Ugg. My first instinct when I saw your code was to blame Wait, but as is, it does work, except of course if you destroy the Monster that is then later still referred to, as you painfully found out. So switch to using a Timer on Monster instead. Then if the Monster is later destroyed, the timer will be cancelled automatically. Sorry I didn't speak up sooner.



Ahh. So in general it would be a good idea to replace any waits with timers when dealing with monsters and combat and such?
ImageImageImage
B
41
S
24
G
11
Posts: 501
Reputation: 10,193

Post » Tue Jun 21, 2016 2:09 pm

I avoid Wait for anything but the simplest things. Timers give you 100% control over your timing.
ImageImageImage
B
71
S
22
G
242
Posts: 3,734
Reputation: 134,994

Post » Tue Jun 21, 2016 3:15 pm

blackhornet wrote:I avoid Wait for anything but the simplest things. Timers give you 100% control over your timing.


Thanks, makes sense. So easy to throw in a wait without thinking about it. Need to get out of that habit and get more familiar with timers.

If you don't mind a follow up question: How do you organize your timers? (or more accurately name them)

So lets say it takes a small amount of time for the main character to do certain actions (cast a spell, open a treasure box, prepare special attack, etc) but if hit by enemy that buildup is stopped. So if you had a timer tagged "fireballSpell" & "openChest" & "superPowerUp" etc. you would have to add a stop timer for each one of those tags in the event for the character getting hit, no? Or can you stop all timers for one instance? (of course that might lead to issues stopping all timers, not just relevant timers, for that instance)

Or I was thinking have an instance variable, lets call it timerFunction. Then could do:

On key/button pressed:
-set timerFunction to "fireball" or "openChest" or whatever they are doing
-start timer "mainCharacter" (always keep the tag the same)

On timer "mainCharacter"
-call function character.timerFunction

On main character hit
-stop "mainCharacter"


Sorry I am using you to think my thoughts through but it seems as you are filled with wisdom :)
ImageImageImage
B
41
S
24
G
11
Posts: 501
Reputation: 10,193

Post » Tue Jun 21, 2016 3:51 pm

Yes, that is essentially a state-machine. You have one timer, but different states within, where you perform different actions based on the state. You may even need sub-states, as your original example had three sub-timer states for the Shoot state.
ImageImageImage
B
71
S
22
G
242
Posts: 3,734
Reputation: 134,994

Previous

Return to How do I....?

Who is online

Users browsing this forum: 25games, Artcadev, grodrigues and 22 guests