random reaction table
random reaction table
alright, what I am trying to do is make a table that will automatically fire off one of several pre-made emotes at a certain trigger. I need a little push in the direction of how this coding would work though
Re: random reaction table
maybe something like this works?
set this up first:
set this up first:
then on trigger:tableName = { "do this", "do that", "do something silly", "do something clever" }
local randNumb = math.random(table.size( tableName ))
for numb, thingTodo in pairs(tableName) do
if numb == randNumb then send(thingTodo) end
end
Re: random reaction table
table.size does not exist lua5.1. Also, iterating through the table to find the command is unintuitive given random access abilities.kakku wrote:maybe something like this works?
set this up first:then on trigger:tableName = { "do this", "do that", "do something silly", "do something clever" }local randNumb = math.random(table.size( tableName ))
for numb, thingTodo in pairs(tableName) do
if numb == randNumb then send(thingTodo) end
end
Using table indexing ([]) and the length operator (#), you can just do:
Code: Select all
cmdTable = {"blee", "bloo", "blaa"}
send(cmdTable[math.random(#cmdTable)])
Re: random reaction table
table.size comes with mudlet, though I agree that is a much better solution (similar to http://forums.mudlet.org/viewtopic.php? ... 234&p=4600)
Re: random reaction table
after giving this a few tries this simply dosent work, something about the '}''s wanted around the emote I want to send
Re: random reaction table
Post the code you're using and the error message you're being given?