[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]  Error when adding to a table?
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Error when adding to a table?

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


Posted by Faedara   (104 posts)  [Biography] bio
Date Tue 05 Jul 2011 12:10 AM (UTC)
Message
I'm using Trevize's old rift script (Achaean) because I like a neat and orderly view of my rift, but it hasn't been updated since the reagent release. For those of you that don't know it, this is the location of the Rift XML file: http://sites.google.com/site/trevizemoonflair/main/MUSHclient.zip?attredirects=0&d=1
Not too complicated, but when I tried adding a reagants table/group to it I kept returning a parsing error, saying that I was returning a nil value.

Does anyone know how I would add a new group to the existing table?

The eternally clueless <3
Currently looking for a mentor/tutor to help me learn everything about Lua from the ground up. I can't understand 28*41 until I learn what causes 2+2.
[Go to top] top

Posted by Twisol   USA  (2,257 posts)  [Biography] bio
Date Reply #1 on Tue 05 Jul 2011 01:41 AM (UTC)
Message
Can you show us the full error you're getting, and what you're changing?

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
[Go to top] top

Posted by Faedara   (104 posts)  [Biography] bio
Date Reply #2 on Tue 05 Jul 2011 02:09 AM (UTC)
Message
I changed the following lines:
326
cats = {"herbs", "concoct", "inks", "comms", "crys", "misc", "reag"},

408-410
    reag = {
      ["buffalo horn"] = "bhorn",
      },

431
   reag     = {bhorn     = 0}

555
    reag    = false,


And get this:
Run-time error
Plugin: Rift (called from world: Achaea)
Immediate execution
[string "Plugin"]:214: attempt to index field '?' (a nil value)
stack traceback:
        [string "Plugin"]:214: in function 'parse'
        [string "Trigger: riftitem"]:4: in main chunk
Error context in script:
 210 :   parse = function (item, amount)
 211 :     local x = false
 212 :     for k, v in pairs (rift.table) do
 213 :       if v[item] then
 214*:         rift.current[k][v[item]] = amount
 215 :         x = true
 216 :       end -- if
 217 :     end -- for
 218 :     if not x then


Which, if I knew what it meant, would probably have a very simple explanation.

The eternally clueless <3
Currently looking for a mentor/tutor to help me learn everything about Lua from the ground up. I can't understand 28*41 until I learn what causes 2+2.
[Go to top] top

Posted by Fiendish   USA  (1,775 posts)  [Biography] bio   Global Moderator
Date Reply #3 on Tue 05 Jul 2011 04:03 AM (UTC)

Amended on Tue 05 Jul 2011 04:07 AM (UTC) by Fiendish

Message
Quote:
Which, if I knew what it meant, would probably have a very simple explanation.


The first step to successful programming is understanding what your error messages mean.

attempt to index field '?' (a nil value)

"attempt to index...a nil value"
Means that you tried to look deep inside a non-existent table index.

Let's say you have a table 'foo' that contains three keys 'bar', 'buzz', and 'pants' with associated values. If you try to look at foo.pants (equivalently foo["pants"]), you'll get whatever is stored for that key. Maybe that's a number or maybe that's another table. If you try to look instead at foo.hello_my_name_is_fred, you'll get nil, because foo doesn't have anything stored for that key. Now let's say you ignore the fact that foo doesn't have a "hello_my_name_is_fred" key and try to look at foo.hello_my_name_is_fred[5], that is index 5 into an imaginary table at key "hello_my_name_is_fred" in table foo. Now you'll get an error like above, because you just tried to examine some index of something that doesn't even exist.

214*:

The asterisk in the trace context means that the error happened on this line.

https://github.com/fiendish/aardwolfclientpackage
[Go to top] top

Posted by Faedara   (104 posts)  [Biography] bio
Date Reply #4 on Tue 05 Jul 2011 04:08 AM (UTC)
Message
I know all that stuff, problem is that line is NOT where the error says it is, and I don't know what's drawing the nil.

The eternally clueless <3
Currently looking for a mentor/tutor to help me learn everything about Lua from the ground up. I can't understand 28*41 until I learn what causes 2+2.
[Go to top] top

Posted by Fiendish   USA  (1,775 posts)  [Biography] bio   Global Moderator
Date Reply #5 on Tue 05 Jul 2011 04:13 AM (UTC)

Amended on Tue 05 Jul 2011 04:14 AM (UTC) by Fiendish

Message
Faedara said:

problem is that line is NOT where the error says it is


It is. The line numbers do not start at the beginning of the file. They start at the beginning of the script block inside the file. You're given the line. You can just search for it. Or find the line number in the file where the script block begins and add that to the given number.

https://github.com/fiendish/aardwolfclientpackage
[Go to top] top

Posted by Faedara   (104 posts)  [Biography] bio
Date Reply #6 on Tue 05 Jul 2011 04:45 AM (UTC)
Message
Already did that using the search function. Doesn't help me any to know there's a problem I don't understand sadly.

The eternally clueless <3
Currently looking for a mentor/tutor to help me learn everything about Lua from the ground up. I can't understand 28*41 until I learn what causes 2+2.
[Go to top] top

Posted by Fiendish   USA  (1,775 posts)  [Biography] bio   Global Moderator
Date Reply #7 on Tue 05 Jul 2011 05:40 AM (UTC)
Message
Quote:
I don't know what's drawing the nil.

Try adding
print(k, rift.current, rift.current[k])
above the line where the error happens.

https://github.com/fiendish/aardwolfclientpackage
[Go to top] top

Posted by Nick Gammon   Australia  (21,675 posts)  [Biography] bio   Forum Administrator
Date Reply #8 on Tue 05 Jul 2011 05:45 AM (UTC)
Message
Quote:



 214*:         rift.current[k][v[item]] = amount



Unfortunately there is a lot if indexing going on in that line. Sounds like one of them is nil.

if "item" nil? Is v [item] nil?
Is "k" nil?
Is rift.current (that is, rift ["current"]) nil?

You might have to throw in some print statements to see what is going on. And even that might not tell you how to fix it.

Fiendish was basically saying the same thing. And yes, the line numbers are from the start of the script, not the start of the plugin. The error context it showed is probably right.

You said you "added a new group" to an existing table. I would look closely at your changes. Perhaps if you explained the before and after some vital step that you omitted might become clearer.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Faedara   (104 posts)  [Biography] bio
Date Reply #9 on Tue 05 Jul 2011 06:20 AM (UTC)
Message
It is the reagent table returning a nil:
reag table: 02E77BE8 nil

The eternally clueless <3
Currently looking for a mentor/tutor to help me learn everything about Lua from the ground up. I can't understand 28*41 until I learn what causes 2+2.
[Go to top] top

Posted by Faedara   (104 posts)  [Biography] bio
Date Reply #10 on Thu 07 Jul 2011 02:35 AM (UTC)
Message
Alright! After extensive lazy testing I've figured out that there are TWO tables for each category. Hence the reason the error shows up in K for V in pairs:

  [ 323] bloodroot leaf     [   8] blue ink           [ 102] buffalo horn
herbs table: 023F0808 table: 023DECD0
inks table: 023F0808 table: 023E06C8
reag table: 023F0808 nil


I'm going to continue to work on this myself, but if anyone knows anything feel free to let me know what you know so I can know what I don't know.

The eternally clueless <3
Currently looking for a mentor/tutor to help me learn everything about Lua from the ground up. I can't understand 28*41 until I learn what causes 2+2.
[Go to top] top

Posted by Fiendish   USA  (1,775 posts)  [Biography] bio   Global Moderator
Date Reply #11 on Thu 07 Jul 2011 02:59 AM (UTC)

Amended on Thu 07 Jul 2011 03:02 AM (UTC) by Fiendish

Message
It looks like the script just assumes that rift.current and rift.table are the same. But they aren't. Clearly rift.current[k] doesn't always exist when rift.table[k] does. Or maybe rift.current doesn't exist at all! Is rift.current supposed to be initialized to contain all the same keys as rift.table at some point? Maybe you should just throw in
rift.current = rift.current or {}

above the loop
and then put
rift.current[k] = rift.current[k] or {}

before the inner assignment

https://github.com/fiendish/aardwolfclientpackage
[Go to top] top

Posted by Faedara   (104 posts)  [Biography] bio
Date Reply #12 on Thu 07 Jul 2011 03:03 AM (UTC)

Amended on Thu 07 Jul 2011 03:05 AM (UTC) by Faedara

Message
Huh... so there's a problem with the way the script pairs the item and it's... nope, I don't get it. Years of using lua and everything about tables still eludes me, that's kinda sad.

Also, I tried calling the item table itself, and it gave me an entirely new error. Not sure if it helps though:

Run-time error
Plugin: Rift (called from world: Achaea)
Immediate execution
[string "Plugin"]:63: bad argument #1 to 'pairs' (table expected, got nil)
stack traceback:
        [C]: in function 'pairs'
        [string "Plugin"]:63: in function 'sortedpairs'
        [string "Plugin"]:252: in function 'displaygroup'
        [string "Plugin"]:242: in function 'display'
        [string "Alias: "]:1: in main chunk
Error context in script:
  59 : 
  60 : sortedpairs = function (tbl)
  61 :   local i = 0
  62 :   local tmp = {}
  63*:   for n in pairs (tbl) do table.insert (tmp, n) end
  64 :   table.sort (tmp)
  65 :   return function ()
  66 :     i = i + 1
  67 :     if tmp ~= nil then return tmp, tbl[tmp] end


Also, there are several loops and I'm not sure what an inner assignment is. I feel computer illiterate around you coders.

The eternally clueless <3
Currently looking for a mentor/tutor to help me learn everything about Lua from the ground up. I can't understand 28*41 until I learn what causes 2+2.
[Go to top] top

Posted by Fiendish   USA  (1,775 posts)  [Biography] bio   Global Moderator
Date Reply #13 on Thu 07 Jul 2011 03:05 AM (UTC)

Amended on Thu 07 Jul 2011 03:17 AM (UTC) by Fiendish

Message
bad argument #1 to 'pairs' (table expected, got nil)

pairs() and ipairs() can only be called on a table. Your "tbl" value isn't a table. It is nil.

Quote:
I'm not sure what an inner assignment is

By "inner assignment" I just meant this line:
rift.current[k][v[item]] = amount

It's an assignment inside the loop.

Quote:
there are several loops

There is only one loop in the first error message you posted.

https://github.com/fiendish/aardwolfclientpackage
[Go to top] top

Posted by Faedara   (104 posts)  [Biography] bio
Date Reply #14 on Thu 07 Jul 2011 03:19 AM (UTC)

Amended on Thu 07 Jul 2011 03:21 AM (UTC) by Faedara

Message
Amazing! After I added that, it created the second reag table when I took the item out of the rift, so it has something to do with how the script tracks item withdrawals I believe. Either way, whatever you did worked like a charm and I can get this posted up once I register all the items into it and build an inkmilling counter (a lot like the tattoo one already on there)

Thank you!!

The eternally clueless <3
Currently looking for a mentor/tutor to help me learn everything about Lua from the ground up. I can't understand 28*41 until I learn what causes 2+2.
[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.


11,639 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]