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

Gammon Software Solutions forum

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

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Lua
. . -> [Subject]  tables, and functions as keys?

Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?
(New message)
Subject: tables, and functions as keys?
Name:
Your forum user name.
Register forum user name
Password:
Your forum password.
Forgotten password?
Message:
Message to be posted (in English, please).
Forum codes:
Check this if your message uses 'forum codes' or templates (auto-detected for new posts).
Forum codes Templates

Save this message ...


Subject review (reverse sequence)

Pages: 1 2  

Posted by Nick Gammon   Australia  (18,772 posts)  [Biography] bio   Forum Administrator
Date Tue 17 Apr 2007 12:13 AM (UTC)  quote  ]
Message
It looks OK. Loading separate files shouldn't cause problems, although the devil is in the detail, as usual.

Whatever makes it easy for you to understand and maintain is fundamentally a good idea. :)

- Nick Gammon

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

Posted by Gore   (207 posts)  [Biography] bio
Date Mon 16 Apr 2007 04:43 AM (UTC)  quote  ]
Message
Sorry I haven't posted anything for this, I've been slightly busy as of late, but I fiddled with it (yes, sorry to be nondescript) a bit, and I have it working properly.

Basically the issue was with the table that contained the name, and cure keys, being in the same folder as the function that contained the for each statement to reference them, I believe.

I have my script file set up like this, temporarily until I change it into a plugin.

Character Script File
|All of the character stuff
|-main.lua the file that contains all of the dofiles
 |         for the system
 |-affliction record files
 |-various script files etc
 |-all of the tables file
 |-sipping portion of the script
 |-fire.lua all functions concerning fire potion affs
 |-prone.lua all functions concerning being prone
 |-focus.lua all functions cured by focus


etc etc

the problem occurred when the cure list table was A) not in the same file as the queue function, or B) both of them were not in the character script file, or the main.lua file, but rather in the third set of files.. don't know why.

I'm not a programming major or anything, so my style of organization hasn't been taught to me by someone who knows what they are doing. If anyone has any suggestions or advice, I'd appreciate it.
[Go to top] top

Posted by David Haley   USA  (3,881 posts)  [Biography] bio   Moderator
Date Thu 12 Apr 2007 02:28 AM (UTC)  quote  ]
Message
Well, it's just that you post a file, and then you say you changed some things and got an error message; with this kind of debugging it's really important to see the whole picture. So sure, posting them to a website would be fine, or posting them here if they're not too long.

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
[Go to top] top

Posted by Gore   (207 posts)  [Biography] bio
Date Thu 12 Apr 2007 12:54 AM (UTC)  quote  ]
Message
David, should I post the files to my website, would that help?

Nick, using dofile at the moment
[Go to top] top

Posted by Nick Gammon   Australia  (18,772 posts)  [Biography] bio   Forum Administrator
Date Wed 11 Apr 2007 10:11 PM (UTC)  quote  ]
Message
Quote:

... then I moved the tables back from my script file (the one that mushclient compiles..) to tables.lua and it doesn't work anymore ...


OK, you have your script in different files? How are you combining them? Using "require"? Or "dofile"? Something else?

- Nick Gammon

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

Posted by David Haley   USA  (3,881 posts)  [Biography] bio   Moderator
Date Wed 11 Apr 2007 09:57 PM (UTC)  quote  ]
Message
It's kind of hard to debug this because I don't know exactly where things are. It would be helpful if you showed the exact file you are running, and then the exact thing you did to generate the output, followed by the output (and if it refers to lines, indicate what lines those are). Otherwise it's sort of a guessing game with respect to what is happening where.

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
[Go to top] top

Posted by Gore   (207 posts)  [Biography] bio
Date Wed 11 Apr 2007 06:02 PM (UTC)  quote  ]

Amended on Wed 11 Apr 2007 06:08 PM (UTC) by Gore

Message
all tables are defined in tables.lua

I am so incredibly puzzled, by this. I'm close to figuring out what the issue is.

function queue ()
 cnote ('wtf')
  for _, v in ipairs (curelist) do
    if aff [v.name] then
    cnote (_ .. v.name .. ' ' .. v.heal) 
      if v.heal then
        v.heal ()
        return 
      end
    end
  end
end


function searchaffs ()
Note ('queue') 
  for _, v in ipairs (curelist) do
  Note (v.name)
    if aff [v.name] then 
      if v.heal then
        Note (v.heal)
        v.heal ()
        return 
      end
    end
  end
end


Those look the same to me, and are right beside eachother in my script file.

queue () produces this:

Run-time error
World: Laeric on Lusternia (Ur'Guard)
Immediate execution
[string "Script file"]:233: attempt to concatenate field 'heal' (a function value)
stack traceback:
        [string "Script file"]:233: in function 'queue'
        [string "Command line"]:1: in main chunk


searchaffs () produces this:

queue
shiver
function: 04AC9E58
drink fire
You take a drink from an amethyst vial.
A feeling of comfortable warmth spreads over you.


curelist & aff:

aff=
  {
  illusion=false,
  prone=false,
  sleep=false,
  waking=false,
  
-- Focus affs
  paralysis=false,
  leglock=false,
  throatlock=false,
  
-- Drink affs (cold)
  shiver=true,
  frozen=false,
  }
curelist = {
 {name='shiver', heal=drink.fire,},
 {name='afflict2', heal=drink.frost,},
 }


Am I missing something? Yes it looks weird because I was fiddling with different things to test it out, but with those settings.. searchaffs () works correctly and queue () does not, are they different somehow?

EDIT: Oh boy, I'm an idiot, I didn't fully read the error message before posting... removed the .. v.heal and ..

it worked, but then I moved the tables back from my script file (the one that mushclient compiles..) to tables.lua and it doesn't work anymore. No errors, gah need to experiment more.. Any ideas thus far? this as output:
queue
frozen
shiver
[Go to top] top

Posted by David Haley   USA  (3,881 posts)  [Biography] bio   Moderator
Date Wed 11 Apr 2007 04:39 PM (UTC)  quote  ]
Message
What is the name of the file in which you are defining the drink and cure tables?

And yes, trying it first in a single file is probably a good idea, once you get it right you can split it up.

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
[Go to top] top

Posted by Gore   (207 posts)  [Biography] bio
Date Wed 11 Apr 2007 04:33 PM (UTC)  quote  ]

Amended on Wed 11 Apr 2007 04:35 PM (UTC) by Gore

Message
Yes, queue.lua will contain all of my different queue functions, for potion afflictions, eating/smoking afflictions, etc.

healing.lua contains all of the functions regarding actually healing, drinking potions, eating herbs, smoking, applying etc

Quote:
if I change it to heal='drink.fire', i get..


Error number: 0
Event: Run-time error
Description: ...program files/mushclient/scripts/lusternia/queue.lua:8: attempt to call field 'heal' (a string value)
stack traceback:
...program files/mushclient/scripts/lusternia/queue.lua:8: in function 'queue'
.../program files/mushclient/scripts/lusternia/cold.lua:16: in function <.../program files/mushclient/scripts/lusternia/cold.lua:12>
Called by: Function/Sub: afflict.shiver called by trigger
Reason: processing trigger ""


I'm assuming the error is in the queue.lua file, with queue (), when it attempts to call heal, but the contents of heal is a string.


Quote:
Now, the errors I receive..


Run-time error
World: Laeric on Lusternia (Ur'Guard)
Immediate execution
...rogram files/mushclient/scripts/lusternia/tables.lua:102: attempt to index global 'drink' (a nil value)
stack traceback:
...rogram files/mushclient/scripts/lusternia/tables.lua:102: in main chunk
[C]: in function 'dofile'
.../program files/mushclient/scripts/lusternia/init.lua:1: in main chunk
[C]: in function 'dofile'
[string "Script file"]:1: in main chunk


is from when I have it set as cure=drink.fire, it's saying that drink is a nil value, I think?

Edit: I'm going to write a smaller version of this in one file to try and see if I can make something that's exactly what I'm doing, but set up for test purposes instead..

Thanks for all your help
[Go to top] top

Posted by David Haley   USA  (3,881 posts)  [Biography] bio   Moderator
Date Wed 11 Apr 2007 04:19 PM (UTC)  quote  ]
Message
It shouldn't matter because the function pointer (drink.fire) is in the same file as the local table. However, I'm not sure how exactly you have split everything up, so it might be safer to make it non-local.

One thing I note that concerns me is that nearly every error message you have shown us is coming from a different source file.

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
[Go to top] top

Posted by Gore   (207 posts)  [Biography] bio
Date Wed 11 Apr 2007 03:29 PM (UTC)  quote  ]
Message
Very sorry, received a
Run-time error
World: Laeric on Lusternia (Ur'Guard)
Immediate execution
...ogram files/mushclient/scripts/lusternia/healing.lua:144: attempt to index global 'drink' (a nil value)
stack traceback:
        ...ogram files/mushclient/scripts/lusternia/healing.lua:144: in main chunk
        [C]: in function 'dofile'
        .../program files/mushclient/scripts/lusternia/init.lua:10: in main chunk
        [C]: in function 'dofile'
        [string "Script file"]:1: in main chunk


error, when I changed drink to local drink, I'm assuming because that made the table local to the file, as opposed to all files compiled..
[Go to top] top

Posted by Nick Gammon   Australia  (18,772 posts)  [Biography] bio   Forum Administrator
Date Wed 11 Apr 2007 01:08 PM (UTC)  quote  ]
Message
What was the error message? "Didn't work" is pretty vague.

Different files doesn't matter, as long as you have the syntax right, the order of instructions right, the spelling right, etc.

- Nick Gammon

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

Posted by Gore   (207 posts)  [Biography] bio
Date Wed 11 Apr 2007 12:55 PM (UTC)  quote  ]
Message
still didn't work, does it matter that the different components are split up into different files?
[Go to top] top

Posted by David Haley   USA  (3,881 posts)  [Biography] bio   Moderator
Date Wed 11 Apr 2007 01:37 AM (UTC)  quote  ]
Message
Doesn't have to be. I did it out of habit, because it's always better to not add global variables (global to the entire program as opposed to just the file in question) unless you have to. If you make a variable 'local' at the top-level of a file, then it is global to that entire file. (More technically speaking, it is local to the chunk, which in this case is the string containing the contents of the file.)

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
[Go to top] top

Posted by Gore   (207 posts)  [Biography] bio
Date Wed 11 Apr 2007 12:57 AM (UTC)  quote  ]
Message
Sorry I didn't put in this line

drink= { }

should it be local?
[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.


5,449 views.

This is page 1, subject is 2 pages long: 1 2  [Next page]

[Reply to this subject]  Reply to this subject   [New subject]  Start a new subject   [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

[Home]

Written by Nick Gammon - 5K

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

[Best viewed with any browser - 2K]    [Internet Contents Rating Association (ICRA) - 2K]    [Web site powered by FutureQuest.Net]