[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]  Trying to set up tables

Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?
(New message)
Subject: Trying to set up tables
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)

Posted by Fadedparadox   USA  (91 posts)  [Biography] bio
Date Mon 01 Sep 2008 09:41 AM (UTC)  quote  ]

Amended on Mon 01 Sep 2008 09:42 AM (UTC) by Fadedparadox

Message
I tested this whole script with a fake table, like so:


getPeopleInRoom = function (room_name)
  local t = {}
  if places[room_name] then
    for _,p in pairs(places[room_name]) do
      table.insert(t, p)
    end
    return t
  end
  return nil
end


printRoom = function (room)
  local x = "" -- temporary variable x
  for i, n in ipairs (getPeopleInRoom (room)) do -- go through the names in the room
    x = x .. n -- add the name
    if i < #x then x = x .. " " end -- if it's not the end, add a space
  end -- for
  print (room .. " = " .. x)
end -- func

places = {["Dark room."] = {"John", "Matt", "Jake"}}


And had an alias do this:

printRoom("Dark room.")


It gave me this output:

Dark room. = John Matt Jake
[Go to top] top

Posted by Fadedparadox   USA  (91 posts)  [Biography] bio
Date Mon 01 Sep 2008 09:23 AM (UTC)  quote  ]

Amended on Mon 01 Sep 2008 09:44 AM (UTC) by Fadedparadox

Message
Check out my reply on the Achaea forums (http://forums.achaea.com/index.php?showtopic=34475) as I do something very similar.

To answer the basic question, you call it like you do anywhere else, making sure you send to 'script' or 'script (after omit)', like so:

function (argument 1, argument 2, ..)

In the case of getPeopleInRoom() above, it returns a numerically indexed table of people in the room. Here's another function you could use to print the room name and people in it using that one:


printRoom = function (room)
  local x = "" -- temporary variable x
  for i, n in ipairs (getPeopleInRoom (room)) do -- go through the names in the room
    x = x .. n -- add the name
    if i < #x then x = x .. " " end -- if it's not the end, add a space
  end -- for
  print (room .. " = " .. x)
end -- func


Which you can then call using printRoom ("room name")

edit: I found an error in the function you pasted above. Change:

for p,_ in pairs(places[room_name]) do

to

for _,p in pairs(places[room_name]) do
[Go to top] top

Posted by Dexodro   (4 posts)  [Biography] bio
Date Mon 01 Sep 2008 07:22 AM (UTC)  quote  ]

Amended on Mon 01 Sep 2008 09:03 AM (UTC) by Dexodro

Message
I looked as thoroughly as I can, but nothing works to get this to work, but, as I've mentioned, my inexperience could be the reason I'm faulting.

Example :
temp1 = "%1"
temp2 = "%2"
who.place[temp1] = temp2

That works. But it overwrites all information that was on who.place.whereever.name and rewrites the latest information. I scoured over that page, and the page it links to, and couldn't find how to add in any information.

I later tried :
table.insert (who.place[temp1], temp2)

but I don't even think that can be used in such a situation. I could be mistaken, and am simply using it incorrectly.

tprint for example, on the example above, prints out :
(only using four lines rather than the full 40-ish)

"Centre Crossing"="-removed-"
"Bard's Way north of Centre Street"="-removed-"
"Fire and Spice"="-removed-"
"North of New Thera"="-removed-"

I know for certain there are four or five, (probably more), people in those specific areas, and the names that shown through were only the latest on the list.

The problem I'm having is getting it go "Centre Crossing"="-removed-,-removed-,-removed-".

Where am I going wrong with this?

-edit-

Keldar has given me a way to gather the names of the people in a specific room :


places["%2"] = places["%2"] or {}
places["%2"]["%1"] = true


and a function:


function getPeopleInRoom(room_name)
  local t = {}
  if places[room_name] then
    for p,_ in pairs(places[room_name]) do
      table.insert(t, p)
    end
    return t
  end
  return nil
end


How exactly would I be able to call this function via alias?

Example

DWHO (room_name)

I can't find any information on calling functions via aliases triggers with arguments.
[Go to top] top

Posted by Nick Gammon   Australia  (18,770 posts)  [Biography] bio   Forum Administrator
Date Mon 01 Sep 2008 06:33 AM (UTC)  quote  ]
Message
Perhaps read this and get back to us if you still have questions:

http://www.gammon.com.au/forum/bbshowpost.php?bbsubject_id=6036

Not quite sure about getting the tables to "name themselves", but everything you want to do is certainly possible.

- Nick Gammon

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

Posted by Dexodro   (4 posts)  [Biography] bio
Date Mon 01 Sep 2008 06:22 AM (UTC)  quote  ]
Message
Sorry. I'm half-asleep, and trying to focus. Guess I lost myself.

What I meant was, every time I try to run this trigger :


[string "Trigger: "]:2: attempt to index field 'NameHere' (a string value)
stack traceback:
        [string "Trigger: "]:2: in main chunk


This is the error message I get every time.
I'm not sure what I'm doing wrong, though.

I've never done any coding beyond Qbasic as a kid, right? So this is still all new to me. I've learned what I could, and am still reading some of the topics, but interaction has always been the best teacher.
So, my questions are :

(a) How can I get the tables to name themselves after the %1 and %3 areas?
(b) Upon doing that, is there any way I can place %1 in the corresponding %3 areas, and then output them to the screen?

I might have more after, but these are the ones that are bothering me right now.
[Go to top] top

Posted by Nick Gammon   Australia  (18,770 posts)  [Biography] bio   Forum Administrator
Date Mon 01 Sep 2008 06:12 AM (UTC)  quote  ]
Message
If you are referring to the bit about the "more than one word", these are equivalent:


who.name.nick

who.name ["nick"]


Thus you can put anything you like in, if you quote it, eg.


who.name ["the quick brown fox jumps over the lazy dog"] = "hungrily"


- Nick Gammon

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

Posted by Nick Gammon   Australia  (18,770 posts)  [Biography] bio   Forum Administrator
Date Mon 01 Sep 2008 06:10 AM (UTC)  quote  ]
Message
Quote:

... and upon finding an answer ...


Sorry, I couldn't see a question there.

- Nick Gammon

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

Posted by Dexodro   (4 posts)  [Biography] bio
Date Mon 01 Sep 2008 05:57 AM (UTC)  quote  ]
Message
Hello.

To get straight into what I'm trying to do, I'll start by throwing my script :


^(\w+)(?:(\s+))(?:\(|\(house\))(.+)\)$

script :
who.name.%1 = "%1"
who.name.%1.where = "%3"


Mind you, the RegEx is sloppy, and the tables aren't precisely what I'd like, but I have to stick with it. (Can't get %3 to get a table named after itself because it sometimes consists of more than one word and/or other characters).

Essentially, this is just a script to gather everyone from a WHO list and their location, and place them altogether. With that, I'm hoping with enough time, that I can output location names (will show example below) and everyone who is in that specific room.

-Roomname1- : Name1, Name2, Name3, Name4
-Roomname2- : Name5

Et cetera. This is going to take some work on my part, understandably, but, I think it's good practice, and upon finding an answer, should better my skills with Lua.

I'll be in debt to whomever can help me.

Thanks in advance,
BDKL
[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,134 views.

[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]