[Home] [Downloads] [Search] [Help/forum]

Gammon Forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Lua
. . -> [Subject]  table.insert
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

table.insert

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Posted by Lethethar   (7 posts)  [Biography] 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
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] 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
[Go to top] top

Posted by Lethethar   (7 posts)  [Biography] 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)
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] 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
[Go to top] top

Posted by Lethethar   (7 posts)  [Biography] 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.
[Go to top] 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.


2,153 views.

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at FutureQuest]