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
➜ Trying to set up tables
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Dexodro
(4 posts) Bio
|
Date
| Mon 01 Sep 2008 05:57 AM (UTC) |
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 | Top |
|
Posted by
| Nick Gammon
Australia (23,162 posts) Bio
Forum Administrator |
Date
| Reply #1 on Mon 01 Sep 2008 06:10 AM (UTC) |
Message
|
Quote:
... and upon finding an answer ...
Sorry, I couldn't see a question there. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Nick Gammon
Australia (23,162 posts) Bio
Forum Administrator |
Date
| Reply #2 on Mon 01 Sep 2008 06:12 AM (UTC) |
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 | Top |
|
Posted by
| Dexodro
(4 posts) Bio
|
Date
| Reply #3 on Mon 01 Sep 2008 06:22 AM (UTC) |
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. | Top |
|
Posted by
| Nick Gammon
Australia (23,162 posts) Bio
Forum Administrator |
Date
| Reply #4 on Mon 01 Sep 2008 06:33 AM (UTC) |
Message
| |
Posted by
| Dexodro
(4 posts) Bio
|
Date
| Reply #5 on Mon 01 Sep 2008 07:22 AM (UTC) 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. | Top |
|
Posted by
| Fadedparadox
USA (91 posts) Bio
|
Date
| Reply #6 on Mon 01 Sep 2008 09:23 AM (UTC) 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 | Top |
|
Posted by
| Fadedparadox
USA (91 posts) Bio
|
Date
| Reply #7 on Mon 01 Sep 2008 09:41 AM (UTC) 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:
It gave me this output:
Dark room. = John Matt Jake
| 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.
25,090 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top