Have you looked at state machines ? If I were you, I would not use a linked list except the stack. I think the end result is the same.
stack:push(action:new(goto, character, point_a)) stack:push(action:new(say, character, "Oh dear, this lawn was stomped by a mammoth!")) stack:push(action:new(mowLawn, character))
Performing the actions sequentially will give something like:
while stack.count > 0 do -- do all actions in the stack action = stack:peek() -- gets the action on top of the stack while action.over ~= true do -- continue action until it is done action:execute() -- execute is what the action actually does end stack:pop() -- action over, remove it and proceed to next one end
goto and other functions will look like this:
function goto(action, character, point) -- INSTANT MOVE YEAH character.x = point.x character.y = point.y action.over = true -- set the overlying action to be over end function attack(action, character, target) -- INSTANT DEATH WOOHOO target.hp = 0 action.over = true -- attack is a punctual action end function berserk(action, character) attack(action, character, getNearestCharacterId()) -- Call the underlying attack action.over = false -- but don't set action as done ! end
Therefore, whenever you stack:push(action:new(berserk, character)) , it will attack another target each time.
I also made you a stack and implementation of the action in the lua object here . I have not tried it. Maybe damned like hell. Good luck with the game!
source share