switch (argument0) { case ev_step_normal: // Called in step event break; case ev_enter: state_index = zombie_roaming // Change to script index // Called when state is entered break; case ev_exit: // Called when state is exited break; case ev_create: // Initalises any variables for the state break; case ev_destroy: // Cleans up any memory used by the state break; default: // Event not used for this state break;}This script now becomes a new resource called... a state! This way states can have as many events as they need and they are kept nicely together in one package. They also keep the advantages of having enter and exit events. Custom events are as easy as adding a constant in global game settings.To use the states call in the create event something like this.
// Create states script_execute(zombie_roaming, ev_create); script_execute(zombie_mauling, ev_create); // Enter roaming state script_execute(zombie_roaming, ev_enter);In the step event call
script_execute(state_index, ev_step_normal);And the destroy event call
// Exit current state script_execute(state_index, ev_exit); // Destroy states script_execute(zombie_roaming, ev_destroy); script_execute(zombie_mauling, ev_destroy);Etc.
For convenience, another script (state_change) can be easily created
// state_change(state) script_execute(state_index, ev_exit); script_execute(argument0, ev_enter);So what do you have to say about this method? I personally think it looks really good, I'm going to try and make an AI using it. I'll post it here if it turns out OK.
Edited by ~Dannyboy~, 10 January 2009 - 11:44 AM.











