[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Cost of String Comparisons??
- From: "Adam D. Moss" <adam@...>
- Date: Mon, 04 Apr 2005 14:08:04 +0100
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