Extending formList

Post » Wed May 29, 2013 11:24 pm

I have a script that requires users to 'subscribe' to it for services. Basically, it will cache all it's data until all 'subscribers' have indicated they have finished with it. So the script needs to keep track of other scripts.

I have a working solution in my script, but I thought a nice extensible way to do this would be to extend formList, and add a property for tracking things. ie.

ScriptName kvwcSubscriberFormList extends FormList{	$Rev: 100 $	$Date: 2013-05-24 00:17:51 -0500 (Fri, 24 May 2013) $	Base formList to handle data subscriptions	Add list of subscribing forms		Used to delay execution until all subscribers signal finished, or time-out.}int Property timeOut = 1000 Autofloat Property waitInterval = 0.5 Autobool[] subscriberFinished		; Bool.  Index matches formList, indicates subscriber done w/ this data setbool subscriptionsFinished		; Bool.  All subscribers donefunction init()	subscriberFinished = new bool[64]	subscriptionsFinished = falseendFunction; Add subscriber.  function subscribe(form sub)	if (!hasForm(sub))		addForm(sub)		debug.trace("New data subscriber: " + sub)	endIfendFunction; Remove subscriberfunction removeSubscriber(form sub)	if (hasForm(sub))		removeAddedForm(sub)	endIfendFunction; Subscriber calls this to indicate finished with data from current iterationfunction subscriptionReceived(form sub)	; Mark finished	int i = find(sub)	if (i >= 0)		subscriberFinished[i] = true		debug.trace("Data subscriber finished: " + sub)	endIf		; Check if all subscriptions are complete	i = getSize()	while i		i -= 1		subscriptionsFinished = subscriptionsFinished && subscriberFinished[i] 	endWhileendFunction; Wait until all subscribers have gotten their infofunction checkSubscribers()	int c	while (!subscriptionsFinished && c < timeOut)		Utility.wait(waitInterval)		c += 1	endWhile		; Clear	if (c >= timeOut)		debug.trace("Subscriber timeout")	endIf		; Calling method should call init() to cleanupendFunction

But of course, I cannot instantiate a formList in a script, I cannot down cast from a formList to my script. So as far as I can tell, this svcker is dead in the water... ie. not possible.

Is there any practical reason to extend a formList then?

User avatar
Nauty
 
Posts: 3410
Joined: Wed Jan 24, 2007 6:58 pm

Return to V - Skyrim