table.insert

Posted by Lethethar on Sun 27 Jul 2014 12:15 AM — 5 posts, 16,824 views.

#0
I have need to keep a list that I addto and remove from I figured table.insert would work for this purpose I have managed to insert one value but not a second value of same name since there may be multiples of the same I tried to use
tprint to debug and resulted in all scripting being shutoff and this error
Immediate execution
[string "Trigger: "]:2: attempt to index field 'insert' (a function value)
stack traceback:
[string "Trigger: "]:2: in main chunk
Australia Forum Administrator #1
Please post the relevant code.
#2
<triggers>
<trigger
enabled="y"
match="^A Scaly worm slides past you\.$"
regexp="y"
send_to="12"
sequence="100"
>
<send>if not mobs then mobs = {}
table.insert [#mobs + 1] = "worm"
Note (mobs)
end
</send>
</trigger>
</triggers>
function Prompt (thename, theoutput, wildcards, line)
require "tprint"
iHP = wildcards [1]
iMovement = wildcards [2]
iCoins = wildcards [3]

Note ("Your HP are " .. iHP)
Note ("Your Movement is " .. iMovement)
Note ("Your coins are " .. iCoins)
tprint (mobs)
Amended on Sun 27 Jul 2014 01:13 AM by Lethethar
Australia Forum Administrator #3
You have combined two different ways you can insert into a table. One is:


table.insert (mobs, "worm")


The other is:


mobs [#mobs + 1] = "worm"



Quote:


if not mobs then mobs = {}
table.insert [#mobs + 1] = "worm"
Note (mobs)
end



Also your code will only do anything if there is no mobs table. I think you mean:


if not mobs then 
  mobs = {}  -- create table
end -- if no mobs table

table.insert (mobs, "worm")

require "tprint"

tprint (mobs)
#4
Thank you nick, I had read the help on it and thought I understood it but it was not working that how ever does work.