lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


sohyl siddiqui wrote:
if BOTA_STATE == "ATTACK" then
    --blah blah
elseif BOTA_STATE == ""RUN" then
    --blah blah
etc etc.....

Also... if you're sure that these sections of code are
taking too much time, and your if...elseif...elseif... chains
are quite long, then it's probably faster to use a Lua-style
hashed switch.  Something like:

bot_state_actions = {
  ATTACK = function(bot)
              -- attacky stuff
           end;
  RUN = function(bot)
              -- runny stuff
           end;
  SLEEP = function(bot)
              -- sleepy stuff
           end;
  NOSEPICK = function(bot)
              -- nose-picking stuff
           end;
}

function bot_tick(bot, state)
   bot_state_actions[state](bot);
end

...

bot_tick(BOTA, BOTA_STATE);
bot_tick(BOTB, BOTB_STATE);
bot_tick(BOTC, BOTC_STATE);

--Adam