A problem/bug with recurring timer events

These are old bug reports that have been closed.
Locked
Apemant
Commonwealth Pilot
Commonwealth Pilot
Posts: 94
Joined: Mon Dec 03, 2007 12:51 pm

When you add a certain recurring timer event on an object, and then leave the system where that object resides, it stops firing - which is good. BUT, when you reenter that system, it appears that the game sends too many of those events at once. If the recurring even is quick it can result in all kinds of problems.

Try it yourself, add the following timer to any station:

Code: Select all

<OnCreate>
    (block Nil
        (objSetData gSource "ticker" 0)
        (sysAddObjRecurringTimerEvent 30 gSource "OnCheckEntry")
    )
</OnCreate>

<OnCheckEntry>
    (block Nil
        (objIncData gSource "ticker" 1)
        (objSendMessage gPlayerShip Nil (cat "Tick: " (objGetData gSource "ticker")))
    )
It shows a message every second and displays which second that was. But, when you enter a gate, it stops showing messages (so far so good); however, once you get back the number of seconds increases too fast; at least by 12 secs even though I got back immediatelly and it shouldn't be more than 3-4 seconds.

I thought maybe the problem was this gSource variable I use in the OnCheckEntry event handler? Is there another way of getting the object which fired the even except by gSource? I mean, since gSource is a global-ish variable maybe it gets mixed up with something etc.
User avatar
Betelgeuse
Fleet Officer
Fleet Officer
Posts: 1920
Joined: Sun Mar 05, 2006 6:31 am

When I tried it passed normally with your code it didn't display the sec that I wasn't in the system.

gSource in this case will always be the calling station so that's not the problem. I am guessing you can't message the player from a different system.

Code: Select all

			<OnCreate>
			    (block Nil
				(objSetData gPlayerShip "ticker" 0)
				(sysAddObjRecurringTimerEvent 30 gSource "OnCheckEntry")
			    )
			</OnCreate>

			<OnCheckEntry>
			    (block Nil
				(objIncData gPlayerShip "ticker" 1)
				(objSendMessage gPlayerShip Nil (cat "Tick: " (objGetData gPlayerShip "ticker")))
				) 
			</OnCheckEntry>
I changed it to this and it only incremented when the player was in the same system as the station. What do you want it to do? My guess is that you can't message outside the same system.
Crying is not a proper retort!
Apemant
Commonwealth Pilot
Commonwealth Pilot
Posts: 94
Joined: Mon Dec 03, 2007 12:51 pm

Betelgeuse wrote:When I tried it passed normally with your code it didn't display the sec that I wasn't in the system.

gSource in this case will always be the calling station so that's not the problem. I am guessing you can't message the player from a different system.
No no, I wasn't talking about that... of course you don't receive events from another system! But, try this: go to some stargate, check what second it is. Then enter the stargate and immediatelly come back. It doesn't take more than 3-4 seconds, and yet the message gets incremented by like 14-15 seconds! In fact, it's always the same increment, no matter how long you spend on the other side. But certainly, if I was outside just for 3-4 seconds, how did it get incremented 15 times? There has to be some problem with this.

Betelgeuse wrote: I changed it to this and it only incremented when the player was in the same system as the station. What do you want it to do? My guess is that you can't message outside the same system.
Curiously enough, when I change it like that (attach the variable to gPlayerShip, not gSource) then it counts correctly. So it means there really is some problem with gSource while you are in the process of gating between systems. In fact, if there is a really fast recurring event (several times a second) which mentions gSource in its handler, then it lags really badly for a few seconds when you get back to the system with that object.
User avatar
Betelgeuse
Fleet Officer
Fleet Officer
Posts: 1920
Joined: Sun Mar 05, 2006 6:31 am

No no, I wasn't talking about that... of course you don't receive events from another system!
hmm odd the incrementer seemed to be working in the other system. Will do more testing.

I have never encountered the lag even when I spent lots of time in the other system and never got multiple messages which implies they don't get bunched up and released at once.

edit: did some more testing and OnCheckEntry is not run in the other system and there is no multiple messages it just changes ticker (even differentticker) by how long you spent in the other system will do more testing

edit2: found that plyMessage does not repeat messages and it doesn't change ticker if it wasn't incremented in the code
Crying is not a proper retort!
User avatar
Betelgeuse
Fleet Officer
Fleet Officer
Posts: 1920
Joined: Sun Mar 05, 2006 6:31 am

multiply has the same behavior (jumping up as if there where several runnings) I know the function isn't running many times before then.

maybe it is running due to being linked to gsource but the outputs are not for some reason
Crying is not a proper retort!
Apemant
Commonwealth Pilot
Commonwealth Pilot
Posts: 94
Joined: Mon Dec 03, 2007 12:51 pm

Betelgeuse wrote:I have never encountered the lag even when I spent lots of time in the other system and never got multiple messages which implies they don't get bunched up and released at once.
Agreed, I just thought that was the case the first time I encountered this. But after further testing, it seems it just doesnt matter how long I spend on the other side. Be it 3 seconds or 3 minute, the ticker gets increated by 15 seconds. How to explain it? I have no clue.

And yes, the lag I was talking about doesn't happen just because of this, but because I was using (objGetDistance gPlayerShip gSource) and then did some more stuff if that distance was less than 8. Now if gSource gets screwed for some reason while in the proces of switching systems, I guess it could have caused all kinds of problems. Going to test it further.
Apemant
Commonwealth Pilot
Commonwealth Pilot
Posts: 94
Joined: Mon Dec 03, 2007 12:51 pm

YES I think I have an answer.

Certainly you noticed that when you enter a stargate you DISAPPEAR immediatelly, and then there is the efStargateOut effect, then the system switches, then there is the efStargateIn, and THEN you appear again.

So naturally, gPlayerShip just doesn't work in that period. You can't send it messages and you can't increase it's data, it just isn't there. That's why you didn't notice those wild increments when using gPlayerShip. You can test it yourself if you use gSource, but like this: (if gPlayerShip (objIncData gSource "ticker" 1)). That will increase ticker only if gPlayerShip is not Nil. If you do this, the ticker works correctly even with gSource.

However, it does appear that the recurring event gets called more times than it should, while gPlayerShip is Nil (during the gating effect). Namely, I have set it up to increase once every second, but when I enter a gate and immediatelly get back (no more than 4 secs could have possibly passed) it gets incremented by like 15. And it doesn't even depend on the time I spend in the other system; it could be a second or 10 minutes, the result is the same: 15 seconds increment or so.

Therefore, I see only one possible answer: while you are gating in, the moment between switching the system and the reappearance of your ship (in other words, the duration of efStargateIn) the recurring event gets called rapidly for some reason. Some bug I'd say.
george moromisato
Developer
Developer
Posts: 2998
Joined: Thu Jul 24, 2003 9:53 pm
Contact:

Right before the player enters a system (before setting gPlayerShip) the game executes a few dozen cycles "off-screen". This simulates the fact that some time has passed in the system while the player was gone.

Can you use a check on gPlayerShip (check for Nil) to avoid processing the event in these situations?
User avatar
Betelgeuse
Fleet Officer
Fleet Officer
Posts: 1920
Joined: Sun Mar 05, 2006 6:31 am

can you make dbgOutput work in those "off-screen" cycles? You would still need to debug even in those cycles.
Crying is not a proper retort!
Apemant
Commonwealth Pilot
Commonwealth Pilot
Posts: 94
Joined: Mon Dec 03, 2007 12:51 pm

george moromisato wrote:Right before the player enters a system (before setting gPlayerShip) the game executes a few dozen cycles "off-screen". This simulates the fact that some time has passed in the system while the player was gone.

Can you use a check on gPlayerShip (check for Nil) to avoid processing the event in these situations?
Thanks for clarifying... yes I used (if gPlayerShip) in all event handlers that require anything from gPlayerShip variable, as soon as I figured out the problem was in gPlayerShip and not gSource like I initially thought.

BTW, great game... :D
Locked