debugging
this is going to be a little more complex to debug as you dont necessarily know the sequence of events which lead to an error. In some ways it will also be much easier tho smaller bits of code to debug...
I'd suggest that we look at something like a unit of work type pattern (not really a unit-ofwork pattern tho now that i think about it) where an event is fired but also contains a sequential log of things that occur during the event handling).
e.g. the main loop runs, updating the player information. It recognises that the player HP has changed so fires the onHPChanged event (which includes a logger session)...
so far the log would look like:
Code: Select all
20120731215600000 - main - Player HP changed from 100 to 35.
Code: Select all
combatState:onEvent(event)
base:onEvent(event);
switch (event.Name)
{
case "onHPChanged":
if (event.newHP < 70) then
event.Log("Player hp < 70, URGENT HEALING REQUIRED!!!!!!");
self.currentAction = STATE_URGENT_HEAL;
return;
end;
}
end;
combatState:update()
switch (self.currentAction)
{
case STATE_URGENT_HEAL:
<somehow get a ref back to event here...have to think about this more>
event.Log("Healing");
player:heal();
break;
end;
}
end;
Code: Select all
20120731215600000 - main - Player HP changed from 100 to 35.
20120731215600010 - combatState - onEvent() called.
20120731215600011 - combatState - Player hp < 70, URGENT HEALING REQUIRED!!!!!!.
20120731215600015 - combatState - update() called;
20120731215600015 - combatState - Healing;
lastly!!
I'd suggest starting the the goals/requirements of the new bot and then working back from there to a phase1 bot that can move, phase2 that can work out how to get from a to b, phase3 that can fight....