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
➜ Miniwindows
➜ Help with mapper
It is now over 60 days since the last post. This thread is closed.
Refresh page
Pages: 1
2
Posted by
| Death
(55 posts) Bio
|
Date
| Reply #15 on Thu 17 Jan 2019 11:09 PM (UTC) |
Message
| Didn't quite mean to offend you, mate. Next time I won't delete my post for any reason, I didn't really understand that was a problem.
As for the error code, I know what it's saying, but don't quite understand it.
Can you give me some guidance?
Why might it be getting a table instead of a string?
I'm not a coding expert, but I am trying to learn. | Top |
|
Posted by
| Fiendish
USA (2,534 posts) Bio
Global Moderator |
Date
| Reply #16 on Fri 18 Jan 2019 01:11 AM (UTC) Amended on Fri 18 Jan 2019 01:30 AM (UTC) by Fiendish
|
Message
|
Quote: Didn't quite mean to offend you, mate.
I'm not offended. I perceive that your action causes harm, and I'm letting you know.
Looking back at your code now...
Quote: Why might it be getting a table instead of a string?
The answer to "why" in programming is always "because programs do exactly what you tell them to, no more and no less". You keep focusing on what you yourself are doing when you interact with the code, but you're not looking at what the code is doing. Understanding the user story can certainly be useful, but relying exclusively on it will almost always let you down.
So let's walk backward through the code starting from the error.
Why is gmatch getting a table instead of a string for its first argument?
The first argument to the call to gmatch is 'exits'. So why is exits a table there? It's a table because a table is being passed into save_exits_to_database. So why is a table being passed into save_exits_to_database?
Now, because I'd rather teach you to fish than to set you on fire, it's your turn.
Look at the code you just pasted into the forum and start at your call to save_exits_to_database, where we know that exits is a table, and start going backwards line by line until you find where you define what exits is. What do you find? |
https://github.com/fiendish/aardwolfclientpackage | Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #17 on Fri 18 Jan 2019 06:51 AM (UTC) |
Message
|
Master Vivi said:
Didn't quite mean to offend you, mate. Next time I won't delete my post for any reason, I didn't really understand that was a problem.
I've reverted your first post back to what it was. The problem is that replies don't make any sense when the original post is deleted or completely changed. Also it is frustrating for people who (in the future) have a similar problem, and find only "found the problem, fixed it" without any explanation about what the fix is.
We are not offended, I'm just pointing out the problems with doing what you did. You aren't the first. :)
A forum like this can be very useful as a knowledge-base - people may search and find a problem, then find the solution, and not have to take the trouble, and time, of posting their own questions. So, win win! |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Death
(55 posts) Bio
|
Date
| Reply #18 on Fri 18 Jan 2019 07:04 AM (UTC) Amended on Fri 18 Jan 2019 07:05 AM (UTC) by Death
|
Message
| I can't figure it out...
I see two tables in
function process_exits (exits_str)
-- generate a "room ID" by hashing the room name, description and exits
-- break up exits into individual directions
exits = {}
for exit in string.gmatch (exits_str, "%w+") do
local ex = valid_direction [exit]
if ex then
exits [ex] = "-666" -- don't know where it goes yet
end -- if
end -- for
if not rooms [uid] then
rooms [uid] = {name = name, roomdesc = uid, exits = exits, area=area, fillcolour=terrain_color[terrain], fillbrush=0, bordercolour=0xffffff}
end -- if
-- save so we know current room later on
current_room = uid
-- ColourNote ("rosybrown", "", roomdesc)
-- ColourNote ("olive", "", uid)
local room = rooms [current_room]
-- not cached - see if in database
if not room then
-- print ("Loading room", current_room, "from database")
room = load_room_from_database (current_room)
end -- not in cache
if not room then
-- print ("Added room", uid) -- debugging
-- print ("Name", name)
-- ColourNote ("rosybrown", "", roomdesc)
db:exec ("BEGIN TRANSACTION;")
save_room_to_database (current_room, name, roomdesc)
save_exits_to_database (current_room, exits)
db:exec ("COMMIT;")
-- get it back now
room = load_room_from_database (current_room)
end -- if room not there
-- call mapper to draw this rom
mapper.draw (uid) -- redraw room with name
-- try to work out where previous room's exit led
if expected_exit == "-666" and from_room then
fix_up_exit ()
end -- exit was wrong
end -- process_exits
But my code breaks when I change either of those.
With the if not rooms [uid] then rooms [uid]
in place, the mapper draws fine, but won't save to database.
When I change that part, I get that gmatch string error. I've tried replacing those lines in like 1000 different ways, and even tried taking that whole line out of a table, but to no avail.
When I see getting table, I expect it to be exits = {}
or the {...exits=exits...} jam.
No clue how to fix it. | Top |
|
Posted by
| Fiendish
USA (2,534 posts) Bio
Global Moderator |
Date
| Reply #19 on Fri 18 Jan 2019 04:40 PM (UTC) |
Message
|
Quote: But my code breaks when I change either of those.
It sounds like your code has inconsistent expectations. It expects a table in one place and a string in another place. But you keep giving the same thing to both and so it fails for obvious reasons.
Quote: I've tried replacing those lines in like 1000 different ways, and even tried taking that whole line out of a table, but to no avail.
You're flailing, and no programmer ever accomplished anything by flailing. Take a step back from making changes and instead write down with pencil and paper what the code is actually doing and compare that with what you want it to be doing.
Start by putting print(exits_str) at the top of your process_exits function to make sure that exits_str is actually a string and so that you know what it looks like.
Then use that knowledge of what it looks like and go line by line and track the progression of the variables that you're using and producing and compare that with what each function call expects.
If it worked before you made changes, then your changes have violated an expectation. Before you can make changes to any code, you need to know exactly, line by line, what it's doing first. Otherwise your changes will break something, as you've discovered. |
https://github.com/fiendish/aardwolfclientpackage | 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.
45,175 views.
This is page 2, subject is 2 pages long:
1
2
It is now over 60 days since the last post. This thread is closed.
Refresh page
top