recurring timer event query

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

Tue Mar 12, 2019 1:06 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
				([email protected] (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.

User avatar
AssumedPseudonym
Fleet Officer
Fleet Officer
Posts: 1060
Joined: Thu Aug 29, 2013 5:18 am
Location: On the other side of the screen.

Tue Mar 12, 2019 11:06 am

 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

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: 500
Joined: Tue Mar 05, 2013 8:26 am

Wed Mar 13, 2019 6:42 pm

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: 666
Joined: Tue Nov 05, 2013 9:56 am

Sat Mar 16, 2019 12:41 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.

Post Reply