Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Due to spam on this forum, all posts now need moderator approval.
Entire forum
➜ MUSHclient
➜ Lua
➜ table.insert
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Lethethar
(7 posts) Bio
|
Date
| Sun 27 Jul 2014 12:15 AM (UTC) |
Message
| 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 | Top |
|
Posted by
| Nick Gammon
Australia (23,158 posts) Bio
Forum Administrator |
Date
| Reply #1 on Sun 27 Jul 2014 12:28 AM (UTC) |
Message
| Please post the relevant code. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Lethethar
(7 posts) Bio
|
Date
| Reply #2 on Sun 27 Jul 2014 01:10 AM (UTC) Amended on Sun 27 Jul 2014 01:13 AM (UTC) by Lethethar
|
Message
| <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) | Top |
|
Posted by
| Nick Gammon
Australia (23,158 posts) Bio
Forum Administrator |
Date
| Reply #3 on Sun 27 Jul 2014 01:26 AM (UTC) |
Message
| 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)
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Lethethar
(7 posts) Bio
|
Date
| Reply #4 on Sun 27 Jul 2014 02:13 AM (UTC) |
Message
| 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. | Top |
|
The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).
To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.
13,062 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top