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


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  SMAUG
. -> [Folder]  SMAUG coding
. . -> [Subject]  Room number problem

Room number problem

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


Posted by Alkarindil   Brazil  (70 posts)  [Biography] bio
Date Tue 19 Jun 2007 10:01 PM (UTC)
Message
Hi!
I am finnishing a code to use hometowns.
But there's a number variable that doesn't work if it be more than 0.
So, this variable is a number of a room, if you die, you respawn in this room.

The room's value is in the file, in a line like this:
Room_recall xxxxx

In the code, I use a "struct" code, and I use an int variable called "room".

And there's a function to see all the towns, where we see this line:
pager_printf_color(ch, "Room....... %s\n\r", town_list[i]->room);

Everything works fine (I mean, all the other info about the town, such as name, description, etc), except this last line. If I use the command to this function, inside the MUD, it crashes. Except if I use room = 0.

Any ideas?

Thanks!
[Go to top] top

Posted by David Haley   USA  (3,881 posts)  [Biography] bio
Date Reply #1 on Tue 19 Jun 2007 10:36 PM (UTC)
Message
You could check the documentation for printf (man printf). The %s symbol means "string". You want a number. So, as per the documentation, you want to use %d.

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

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

Posted by Alkarindil   Brazil  (70 posts)  [Biography] bio
Date Reply #2 on Thu 21 Jun 2007 01:23 AM (UTC)
Message
Alright!! Thanks very much David!

One last doubt:

My code is now writing a new value to the character's file. Horever, all the time the character is saved, this value is set as 0.

What are the functions that can modify and save these files?

I've found "save_char_obj" function, but it seems to be all right.. Are there another functions?
Are those informations in any file that can help-me?

Thanks in advance!
[Go to top] top

Posted by David Haley   USA  (3,881 posts)  [Biography] bio
Date Reply #3 on Thu 21 Jun 2007 02:08 AM (UTC)
Message
save_char_obj is indeed where you want to look. I'm not sure why it would be printing zero; could you show us the line where it writes that field to the character file?

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

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

Posted by Alkarindil   Brazil  (70 posts)  [Biography] bio
Date Reply #4 on Thu 21 Jun 2007 02:29 AM (UTC)

Amended on Thu 21 Jun 2007 02:33 AM (UTC) by Alkarindil

Message
Is the crinsom blade nations code, but without all the hometown thing. Only nations work, okay?
So I've made an option during the registration to the new player choose a homeland.
For example: I have two lands: Erebor (0) and Rivendell (1). So I create a character called Elrond and choose Rivendell.
The game start, I can use Elrond and in the score screen, it shows-me something like this:
"Statistics to Elrond from Rivendell, the Spell Student"
So I became a wizard level 2 and I save the character save using save command or quit command..
Now, in the score it returns:
"Statistics to Elrond from Erebor, the Spell Student".
The file was created in the save action, right? But the "nation" became 0, not 1!
In the code:
(...)

fprintf( fp, "Race %d\n", ch->race);
//-->
fprintf( fp, "Nation %d\n", ch->nation);
//<--
fprintf( fp, "Languages %d %d\n", ch->speaks, ch->speaking);

(...)

I am not understanding the working process of the character. I am wondering if there's two informations, one used during the game, and another directly form the character?

Now I realize that the zero can be writed during the load process too, I'll check this out..
[Go to top] top

Posted by David Haley   USA  (3,881 posts)  [Biography] bio
Date Reply #5 on Thu 21 Jun 2007 02:43 AM (UTC)
Message
Quote:
I save the character save using save command or quit command.
You need to be precise here. Which is it? What *exactly* are you doing? Does this problem occur if you save, or only if you quit and then log on again?

Did you remember to make clean before making again?

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

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

Posted by Alkarindil   Brazil  (70 posts)  [Biography] bio
Date Reply #6 on Thu 21 Jun 2007 03:44 AM (UTC)

Amended on Thu 21 Jun 2007 04:29 AM (UTC) by Alkarindil

Message
It occurs in both commands.
I'll try to explain how I am testing:

Example:

MUD: type your character's name, or type 'new'.
Me: new
MUD: choose a name
Me: Elrond
MUD: Elrond? [Y/N]
Me: Y
MUD: choose a password
Me: 12345
MUD: re-type
Me: 12345
MUD: choose a sex [M/F]
Me: M
MUD: choose a class [Warrior/Thief/Mage]
Me: Warrior
MUD: choose a race [Elf/Man/Halfling]
Me: Elf
MUD: choose a land [Erebor/Rivendell/Hobbiton]
Me: Riv
MUD: ANSI/RIP or none of them? [A/R/N]
Me: A
MUD: Type enter
Me: [Enter]

MUD: Welcome (game started)
Me: score
MUD: Statistics for Elrond from Rivendell (...)
Me: save
Me: score
MUD: Statistics for Elrond from Erebor (...)

*The character's file is created during the save command, inside it the nation option is 0.
*Before the save, I need an immortal to make "advance elrond 2". This command doesn't change the nation.

//Edit-->
Help!
[Go to top] top

Posted by David Haley   USA  (3,881 posts)  [Biography] bio
Date Reply #7 on Thu 21 Jun 2007 04:44 AM (UTC)
Message
Quote:
*Before the save, I need an immortal to make "advance elrond 2". This command doesn't change the nation.

At what point precisely does the advance occur? It is possible that the code to advance the player is broken and (somehow) breaks the nation code. It is also possible that somehow saving the character breaks the nation.

Maybe you have:
if (ch->nation = 0)
instead of ==.

You did make-clean and make, right? Sometimes forgetting to do a make-clean can cause this kind of problem.

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

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

Posted by Alkarindil   Brazil  (70 posts)  [Biography] bio
Date Reply #8 on Fri 22 Jun 2007 04:49 PM (UTC)
Message
I don't think the advance command is breaking the nation code, because I can run the executable, change the Elrond's file and log in again. The file changes everytime the character is saved, but if I change the number directly in the file, the score command will return the land #0 ever!
Horever, I will look more closely to the do_advance function.. We never know...

Can you answer-me something?

When the player log on the MUD, where did his character's characteristics information go?
I mean, the MUD read the file, and somehow, those info are "in the air", always processing in the server? I ask this because, reading the save functions I realize that the file is updated only when player exits the mud or use the save command. This is when the land's info change.

Thanks!
[Go to top] top

Posted by David Haley   USA  (3,881 posts)  [Biography] bio
Date Reply #9 on Fri 22 Jun 2007 06:36 PM (UTC)
Message
Player data is all stored in-memory in the CHAR_DATA structure. That's the place you save from and load into in the fwrite_char_obj and fread_char_obj functions.

Quote:
I don't think the advance command is breaking the nation code

The kind of problem you are facing, where the error makes no sense and you can't find it, is going to teach you one very important lesson about programming: avoid making assumptions about what works and what doesn't. :-) If you can't find the bug in the place you thought it would be, go look somewhere else, don't assume everything else is perfect.

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

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

Posted by Alkarindil   Brazil  (70 posts)  [Biography] bio
Date Reply #10 on Sat 23 Jun 2007 02:19 AM (UTC)

Amended on Sat 23 Jun 2007 02:20 AM (UTC) by Alkarindil

Message
David, I changed the level required to save the character, so we don't need to use the <advance>.
Okay, new test:
Creating Elrond, in Rivendell (1).
When the game starts, I use score command: everything is fine.
then I use save command. The file is correctly created. Then I use score again, ererything is fine. So I quit, the file remains intact. Then I log in again. So I use <score> again, the score's land is wrong, but the file is right. Then I save, and voilá! The file is wrong again!

I have absolutely no idea what is going on!
The only conclusion is: whitout the <advance> OR without the level 2 save restriction, the bug takes more time and work to happen. Horever, it is there anyway.

Now I am thinking that the bug is somewhere in a load process, maybe some function working in a transition of reading the file/writing the file.

What function is the "load" one? Are there too many loading processes?
I am tired of this problem, I just want a homeland info!

Thanks again!
[Go to top] top

Posted by David Haley   USA  (3,881 posts)  [Biography] bio
Date Reply #11 on Sat 23 Jun 2007 02:23 AM (UTC)
Message
The conclusion that I see is indeed that you haven't set up the code to load the data from disk... how are you getting the hometown from the player file into the game when the character is created?

I'm not sure this is a "bug" -- I think you just haven't coded it in yet. :-)

You want to be looking at fread_char_obj, I think, which is (if memory serves) in save.c.

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

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

Posted by Alkarindil   Brazil  (70 posts)  [Biography] bio
Date Reply #12 on Sat 23 Jun 2007 03:50 AM (UTC)

Amended on Sat 23 Jun 2007 03:51 AM (UTC) by Alkarindil

Message
I found it!
You are wrong, David, in conclude that I forgot this function.
But you are *right*! ...to conclude that something is wrong with this function!

There were a line in fread_char like this:

KEY ("Nation", ch->pcdata->nation_vnum, fread_number(fp));

So, I tryed to modify the pcdata and nation_vnum in some different combinations (I'm almost sleeping here xD )
So, after a both of trials, I've writed this:

KEY ("Nation", ch->nation, fread_number(fp));

Now it's working!
I mean, I'll make some more tests here, I hope it works!
Anyway, I think this is the real problem...

Thanks a lot David! There are some weeks now with this thing, is really good to see this right!

U guys rox!
[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.


21,790 views.

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

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

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

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

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

[Best viewed with any browser - 2K]    [Hosted at HostDash]