recurring timer event query

Freeform discussion about anything related to modding Transcendence.
Post Reply
relanat
Militia Captain
Militia Captain
Posts: 941
Joined: Tue Nov 05, 2013 9:56 am

The Commander's Log mod fires a type recurring timer event in <GetGlobalDockscreen>.

Here's the code. There is some other code and a Nil entry at the end which isn't shown here. This <GetGlobalDockscreen> event doesn't show any dockscreens, just runs code.

Code: Select all

(if (or 	;Arcology special case.
		(eq (objGetName gSource) "Arcology of New Victoria")
			;CSCs.
		(if (objIsShip gSource)
			(and (eq (shpGetClassName (objGetType gSource) 0x100) "Commonwealth Star Carrier")
				(eq (shpGetDockObj gPlayerShip) gSource)
			)
		)
			;Europa vault.
		(eq gSource (sysFindObject Nil "TN+CSCEuropa"))
			;CSC wrecks. Also handles CSC-IIs from the Network mod.
		(typHasAttribute (objGetShipwreckType gSource) 'commonwealthStarCarrier)
			;Cargo autons.
		(and (objHasAttribute gSource 'cargoAuton)
			(eq (shpGetDockObj gPlayerShip) gSource)
		)
			;Cargo auton wrecks.
		(typHasAttribute (objGetShipwreckType gSource) 'cargoAuton)

			;Everything else.
		(and (find (staGetDockedShips gSource) gPlayerShip)
			(not (objHasAttribute gSource 'shipwreck))
		)
	)
	(block Nil
		(printTo 'console "CheckScreen running.")
		(typSetData &evD789CommandersLog; 'currentStation gSource)
		(typAddRecurringTimerEvent &evD789CommandersLog; 15 "CheckScreen")
	)
)
And the <CheckScreen> event which cancels it.

Code: Select all

<CheckScreen>
	(if (or (isError (scrGetScreen gScreen)) ;TY, NMS.
			(eq (scrGetScreen gScreen) Nil)
		)
		(block Nil
			(typCancelTimerEvent &evD789CommandersLog; "CheckScreen")
			(printTo 'console "CheckScreen cancelled.")
			(logSetItems
				(set@ (logGetItems)
					(convertTo 'string (objGetID (typGetData &evD789CommandersLog; 'currentStation)))
					(list
						(objGetID (typGetData &evD789CommandersLog; 'currentStation))
						(objGetName (typGetData &evD789CommandersLog; 'currentStation))
						(sysGetNode)
						"Visited"
						(objGetItems (typGetData &evD789CommandersLog; 'currentStation) '*U)
					)
				)
			)
			(typSetData &evD789CommandersLog; 'currentStation Nil)
		)
	)
</CheckScreen>
It all works fine but on entering the Sisters station in Eridani at game start the debug console shows "CheckScreen running." three times.
This is, I assume, because the player works through multiple Bendict dockscreens and each of these different screens fires the event again.
But on undocking "CheckScreen cancelled." only shows once.

Does this mean there are still two of the events running? And if so how do I stop them? By the end of a game there could be quite a few still running!
Or is some alteration to the code that fires the event needed so it only fires once per object?
Possibly it needs to be changed to an object timer event but I don't want to mess with it while it is working so well unless absolutely necessary.
TIA.
Stupid code. Do what I want, not what I typed in!
User avatar
AssumedPseudonym
Fleet Officer
Fleet Officer
Posts: 1190
Joined: Thu Aug 29, 2013 5:18 am
Location: On the other side of the screen.

 I’m pretty sure that a type can only have one instance of a timer event running at a time, and that firing it while it’s already running will start a new instance of the timer. Don’t quote me on that, though. <.< >.> <.<; If you really want to check to be certain, I would suggest testing with a printTo 'log blocked in before that first conditional to check and see if you’re still getting output to Debug.log after you’ve undocked.

 Tangentially related, I would suggest changing the timer to fire every tick instead of every fifteen ticks. The timer isn’t supposed to be active during normal gameplay, so it won’t be able to impact performance. It also won’t impact performance inside dockscreens due to their time slowdown. Furthermore, it could help eliminate any edge cases where you undock and immediately go to whatever dockscreens you need for the mod.
Image

Mod prefixes: 0xA010 (registered) and 0xDCC8 (miscellaneous)

My mods on Xelerus: Click here!

Of all the things I’ve lost in life, I miss my mind the least. (I’m having a lot more fun without it!)
NMS
Militia Captain
Militia Captain
Posts: 569
Joined: Tue Mar 05, 2013 8:26 am

There can be multiple non-recurring timers of the same name on a type/object/whatever. I'm not sure about recurring timers. Regardless, the cancel functions cancel all matching timers, so this should be OK.
relanat
Militia Captain
Militia Captain
Posts: 941
Joined: Tue Nov 05, 2013 9:56 am

Thank you both.

I set the timer to 15 so as not to impact performance. I figured 15 ticks would be about the shortest time between undocking from a station and entering the mod dockscreen so it always cancelled before the info was used.
But since there is no performance impact I'll set it to 1. Thanks, that's great info.
Stupid code. Do what I want, not what I typed in!
relanat
Militia Captain
Militia Captain
Posts: 941
Joined: Tue Nov 05, 2013 9:56 am

I would suggest testing with a printTo 'log blocked in before that first conditional to check and see if you’re still getting output to Debug.log after you’ve undocked.
Ah, of course. I studied this a bit more and thanks again. I couldn't work out how to check if the event or events were still running; that'll do it. Nice work.

For future reference:
Changing the code for the <CheckScreen> event to this:

Code: Select all

<CheckScreen>
	(block Nil
		(printTo 'log "Running")
		(if (or (isError (scrGetScreen gScreen)
		......
	)
</CheckScreen>
prints "Running" to the debug log every tick while the event is running, although the dockscreen slow-down means only about 5 show every second.
Checking the debug log after undocking shouldn't show any additional "Running"s being added as the event has been cancelled. And that is what happens. (Be aware this code can cause very long debug log files if the events run for a while.)
Stupid code. Do what I want, not what I typed in!
Post Reply