Hi all, this has been asked before but after reading a few of the posts
(https://www.construct.net/en/forum/construct-2/how-do-i-18/wait-and-timescale-issues-57207 for example), I still can't get to a solution...
Basically, I have enemies that patrol. They get to the end of their patrol route, then pause, then go back to the start, then pause, etc. etc.
The problem is, I have game menus which stop all moving objects, including enemies. Their timescales get set to 0. But because the enemies are running functions with waits (eg. "Wait 0.5 seconds"), they continue to perform actions in the background, and when I return to the game from a menu, their behaviours are totally wacked. Note; I am not turning the general Time Scale to 0, because a lot of other things need to keep running. This would make things easier, but I would need to rewrite a LOT of code.
Here's the code in question:
So, what I need is a way to wait in the function - whether or not the object's time scale is 0, then continue the function when the game is unpaused or whatnot. I read about using a variable and subtracting based on dt, but the solution didn't seem like it worked. I tried signalling based on whether menus were open, but I couldn't get the function to recognise it. I also tried creating a variable which gets added to while the menus are closed, but not when open, so I could reference that within the function, but I am ... not a super mathy guy, and I'm having trouble with this.
Any help would be muchly appreciated. :)
EDIT: I forgot to highlight the third wait in that image (this wait is based on an enemy instance variable).
Develop games in your browser. Powerful, performant & highly capable.
You use a timer on the enemy object and timers are affected by timescale so they will pause and continue from where they were when you unpause.
Hey Plinkie, thanks for the quick reply. I did try timers, but thought it wouldn't work because it was leaving the function to trigger the 'on timer' event outside.
But it seems to be working ... kind of.
Here's what I have now:
The problem now is, I assumed timers are set per-instance so I don't have to worry that it's outside the function ... but if I pause the game while more than one enemy is waiting, they all seem to sync up, implying that the signal is not per-instance, but is being received by all of the waiting instances. Is there a way to fix that?
You can see what I mean here:
I tried passing the enemy_sprite_pin.UID in the timer: "Wait_Finished"&Enemy_Sprite_Pin.UID - and signalling the same thing back. But it didn't seem to work.
Yes get rid of all the system events, the timer is supposed to remove the need for waits. As you mentioned, the system event is not per instance. The on timer finished picks the instance where the timer finished, that should hopefully be enough?
Sorry, I'm not sure I understand.
After setting a timer, I have to signal when it's finished. When the signal is received, the function carries on.
The signal can only be sent outside the function ('On Timer Finished' is its own trigger) ... so I have to trigger it like I did in that screenshot. Or is there something I'm missing?
I'm saying the sub events don't need to be in a function, you can have on timer finished then execute those sub events from there. The logic looks a bit convoluted for doing what you are trying to do which is to wait for a couple of seconds then move, right? Also when you wait in a function I believe the parameters you pass through get lost so when you are picking the sprites at the start of the function, i think param 0 and param 1 are no longer valid.
Ok, yeah I see what you're saying. This is old code & much of it is redundant, I'll have a play around and see if I can get it working outside a function.
Thanks a heap for your help! I'll post any solutions I find.
The game looks interesting though, I wanna play it ^^
You can see what I mean here:
I assume you fixed the problem by now.
That's some serious graphic work :D amazing when is gonna be ready to play? ^_^
Hey all. Just an update: I've been working on this, and with your advice Plinkie I ended up breaking all the functions into chunks, each new step triggered by instance timers, rather than 'System: Wait X Seconds'.
So far, things seem to be working flawlessly now. :) I could debatably also replace some functions with 'Current_State = Patrolling > Trigger Once' but I don't see the harm in using functions instead.
I realised that the function was also breaking (where enemies were becoming 'stuck' in their waiting position) because they were overlapping a trigger object that tells them to stop. So the last couple of lines of code 'bump' the enemies off these triggers if they're overlapping when it's time to patrol again.
Thank you so much for all the help Plinkie!
— thanks! It's been in dev for a couple of years and I've really given my pixelling skills a workout in that time haha. You can follow my progress on twitter Jimzip No timeline for release yet but it's coming along pretty swiftly the last month or so. ;)