I found a way to implement dynamic events. The key is that you don't do it at the creation level but at the checking level.
Here's how I did it:
First, I recorded all #Events I'm going to possibly use through the logging code, and put them in an .inc file. As I need more events to possibly check, I'll just add them.
Then, I added subs for adding and checking events in a queue. Next I'm going to write a function to remove events from the queue.
My coding is VERY sloppy at this point because I could very easily change the goto loops and incrementing to /for and /next, which I just recently learned, but here's what I have so far for adding and checking ... it works =]
Code: Select all
Sub addevent(string curevent)
|Adds an event to the queue of events to check. First event is event1, second is event2, etc
|These are checked by the main# func, checkevents. I do this instead of /doevents because
|When a user has disabled a feature, like pet attacking, it is more efficient to exclude the
|event from being checked in the first place than having the event trigger a null function
|every time it is called.
/declare tempevent int local 1
|tempevent goes out of scope upon /return, no need to delete
:addeventloop
/if (${Defined[event${tempevent}]}) {
/varcalc tempevent ${tempevent}+1
/goto :addeventloop
}
/declare event${tempevent} string outer ${curevent}
/echo Debug: addevent called: event${tempevent} set to ${event${tempevent}}
/return
Sub checkevents
|Checks events set when the macro inits ... and dynamic events created by other events
|This is always a main# function. I do this instead of /doevents because
|When a user has disabled a feature, like pet attacking, it is more efficient to exclude the
|event from being checked in the first place than having the event trigger a null function
|every time it is called. Less coding and less work for me ^^
/declare tempevent int local 1
|tempevent goes out of scope upon /return, no need to delete.
:eventloop
/if (${Defined[event${tempevent}]}) {
/doevents ${event${tempevent}}
/varcalc tempevent ${tempevent}+1
/goto :eventloop
}
/return
About the "main#" comment ... You can probably guess that I have the functions that are called by the main loop set up the same way as the events ^_^
And by the way .. /next is only mentioned in the manual as part of a /for loop ... You can increment variables ouitside /for too, right?