fire a recurrring event from an item

This is a moderated forum that collects tutorials, guides, and references for creating Transcendence extensions and scripts.
Post Reply
User avatar
digdug
Fleet Admiral
Fleet Admiral
Posts: 2620
Joined: Mon Oct 29, 2007 9:23 pm
Location: Decoding hieroglyphics on Tan-Ru-Dorem

I had an idea on how to fire a recurring event from anywhere in code, in particular I was interested to fire a recurring event from an item in a simple way, without the need to create a station and/or ship to handle the recurring event.
Don't get me wrong, the spawned station idea proved to be flexible and stable, this is another solution to it, and I like it for its simplicity.

The idea is to use an event handler on the playership :

Code: Select all

(block Nil
	 
	 (objSetEventHandler gPLayership &evtest;)
	 (objFireEvent gPLayership "IMTESTEVENT")

)
and then fire the event that is in the virtual handler:

Code: Select all

<ShipClass UNID="&evtest;"
			class=				"(test)"
			virtual=			"true"
			>
		<Events>
			<IMTESTEVENT>
				(dbglog "IT WORKS!!!!!!!!!!!!!!")
			</IMTESTEVENT>
		</Events>
	</ShipClass>
Event handlers are stackable, so multiple mods can run their recurring events without clashing.
This can work on the playership, or on any other spaceobject.

when the player installs an item
<OnInstall>
add the event handler and fire the recurring event

<OnUninstall>
stop the recurring event


What do you think ?
User avatar
Prophet
Militia Captain
Militia Captain
Posts: 826
Joined: Tue Nov 18, 2008 6:09 pm

I love event handlers!

Your thread topic made me think you were talking about an item type, however.

<OnInstall> and <OnUnInstall> only work for devices but could trigger an <Onupdate> event if you want it to run every 30 ticks or start your own recurring event if you need a different time frame.

One function that I like to use is typFireObjEvent (recently added to the wiki and xelerus )which works great if your events are on an existing type and you don't want all the hassle of creating a space object.

The other added benefit of using an event handler is that its effects persist across systems, IIRC. You can start a recurring event in Eridani and it will still be running in Heretic without having to spawn a background station in every system.
Coming soon: The Syrtian War adventure mod!
A Turret defense genre mod exploring the worst era in Earth's history.
Can you defend the Earth from the Syrtian invaders?
Stay tuned for updates!
User avatar
Cygnus.X1
Militia Lieutenant
Militia Lieutenant
Posts: 245
Joined: Sun Feb 24, 2008 6:21 pm
Location: Elysium Fields... I mean System
Contact:

Sorry for the thread necro but I just tried this and totally failed :(

http://paste.neurohack.com/view/YfvCn/

I really wanted to avoid having to create a virtual station but it looks like that's the only way to go.
Watch TV, Do Nothing
Militia Captain
Militia Captain
Posts: 803
Joined: Sun Feb 05, 2012 12:22 am
Contact:

Cygnus.X1 wrote:Sorry for the thread necro but I just tried this and totally failed :(

http://paste.neurohack.com/view/YfvCn/

I really wanted to avoid having to create a virtual station but it looks like that's the only way to go.
Seconding this.
Post Reply