Register forum user name Search FAQ

Gammon Forum

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 ➜ tables, and functions as keys?

tables, and functions as keys?

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


Pages: 1  2 

Posted by David Haley   USA  (3,881 posts)  Bio
Date Reply #15 on Wed 11 Apr 2007 04:39 PM (UTC)
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
Top

Posted by Gore   (207 posts)  Bio
Date Reply #16 on Wed 11 Apr 2007 06:02 PM (UTC)

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
Top

Posted by David Haley   USA  (3,881 posts)  Bio
Date Reply #17 on Wed 11 Apr 2007 09:57 PM (UTC)
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
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #18 on Wed 11 Apr 2007 10:11 PM (UTC)
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
Top

Posted by Gore   (207 posts)  Bio
Date Reply #19 on Thu 12 Apr 2007 12:54 AM (UTC)
Message
David, should I post the files to my website, would that help?

Nick, using dofile at the moment
Top

Posted by David Haley   USA  (3,881 posts)  Bio
Date Reply #20 on Thu 12 Apr 2007 02:28 AM (UTC)
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
Top

Posted by Gore   (207 posts)  Bio
Date Reply #21 on Mon 16 Apr 2007 04:43 AM (UTC)
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.
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #22 on Tue 17 Apr 2007 12:13 AM (UTC)
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
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.


69,294 views.

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

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

Go to topic:           Search the forum


[Go to top] top

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