Page 1 of 1

fire a recurrring event from an item

Posted: Sun Feb 27, 2011 4:06 pm
by digdug
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 ?

Re: fire a recurrring event from an item

Posted: Mon Feb 28, 2011 3:58 am
by Prophet
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.

Re: fire a recurrring event from an item

Posted: Fri Nov 09, 2012 1:09 am
by Cygnus.X1
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.

Re: fire a recurrring event from an item

Posted: Fri Nov 09, 2012 2:08 pm
by Watch TV, Do Nothing
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.