19 Aug, 2009, Kline wrote in the 21st comment:
Votes: 0
AFAIK you can return in a switch( … ) but then need to omit the break for that case: … element.
19 Aug, 2009, Lazerous wrote in the 22nd comment:
Votes: 0
Lines 17 & 19
As for indenting, I will endevor to do better, how ever as I am not college educated in
code but in networking and have played as an amature in code since the days of
gwbasic, you can understand if I don't indent correctly.
19 Aug, 2009, Lazerous wrote in the 23rd comment:
Votes: 0
opps my bad I just linked the login menu not the logout one….
well at least you can see the one that works now…

I will link the other shortly…
19 Aug, 2009, David Haley wrote in the 24th comment:
Votes: 0
Do you mean that you don't know how to indent? Sorry, just trying to understand. If that's your question we can help there.

Anyhow I'll wait to see the rest of the code you said you were going to post so that we're all on the same page.
19 Aug, 2009, Lazerous wrote in the 25th comment:
Votes: 0
Ok the logout one, gosh I am sorry about that last post…
What I did was, make this into the function called do_quit and renamed do_quit into do_quit2
which I then made sure was declared in smaug.h so here we go again…

// Log Out Menu - Ryan Rae

void do_quit (CDescriptor *d, char *argument)
{
char buf [MAX_STRING_LENGTH];
CCharacter *ch;
ch = d->m_pCharacter;

d->WriteToBuffer("*** Welcome to: The Realm of Draenor ***\n\r\
\n\n\rLog Out Menu:\n\n\r\
0) Leave the Game\n\r\
1) Return to the Game\n\n\r\
2) Read the background story\n\r\
3) Read latest realm changes.\n\r\
4) Read the latest code changes.\n\n\r\
5) See the World Map.\n\r\
6) See a list of all the area's in the realm.\n\n\r\
Please select your choice: ", 0);
d->m_Connected = CON_MENU2;
break;

case CON_MENU2:
switch ( argument [0] )
{
case '0':
// d->WriteToBuffer( "Come back again.\n\r", 0 );
// d->m_pCharacter->SetDesc (NULL);
// RemoveCharacter (*d);
do_quit2 ( ch, "");
break;

case '1':
break;

case '2':
do_help( ch, "story" );
break;

case '3':
do_help( ch, "motd" );
break;

case '4':
do_help( ch, "code" );
break;

case '5':
do_help( ch, "world" );
break;

case '6':
do_help( ch, "prep" );
break;

default:
d->WriteToBuffer("\nLog Out Menu:\n\n\r\
0) Leave the Game\n\r\
1) Return to the Game\n\n\r\
2) Read the background story\n\r\
3) Read latest realm changes.\n\r\
4) Read the latest code changes.\n\n\r\
5) See the World Map.\n\r\
6) See a list of all the area's in the realm.\n\n\r\
Please select your choice: ", 0);
return;
}}
// End of New Log out Menu


Sorry about the indents but that is exactly how it is in my code, not sure
what you are looking for indent wise as this forum thing doesn't let me
use my actual tab button to indent stuff.

So line 21 and 23 are the problems.
19 Aug, 2009, tphegley wrote in the 26th comment:
Votes: 0
I know David will probably go into better detail, but your break is not in a switch/case/for statement(?) so you can't just put a break wherever you want. Then 23 is not in a switch statement so it is illegal. You have to use the case inside a switch statement.

Sorry, I'm not proficient in how to explain it but that's the best I could do.
19 Aug, 2009, Lazerous wrote in the 27th comment:
Votes: 0
I see, well like I said I was taking from my log in menu and adapting that to a log out menu.
The log in menu is posted above, and works just fine.

Now with what you said, how would you rewrite this then?
Just remove the break and move the case?

If I do this, I end up with these errors:

Linking…
ACT_COMM.OBJ : error LNK2001: unresolved external symbol "void __cdecl do_quit2(class CCharacter *,char *)" (?do_quit2@@YAXPAVCCharacter@@PAD@Z)
ACT_WIZ.OBJ : error LNK2001: unresolved external symbol "void __cdecl do_quit(class CCharacter *,char *)" (?do_quit@@YAXPAVCCharacter@@PAD@Z)
SKILLS.OBJ : error LNK2001: unresolved external symbol "void __cdecl do_quit(class CCharacter *,char *)" (?do_quit@@YAXPAVCCharacter@@PAD@Z)
UPDATE.OBJ : error LNK2001: unresolved external symbol "void __cdecl do_quit(class CCharacter *,char *)" (?do_quit@@YAXPAVCCharacter@@PAD@Z)
.\Release/SmaugWiz.exe : fatal error LNK1120: 2 unresolved externals
Error executing link.exe.
Creating browse info file…

SmaugWiz.exe - 5 error(s), 0 warning(s)
19 Aug, 2009, tphegley wrote in the 28th comment:
Votes: 0
Look up a command that uses an argument, IE do_buy. Look how it does the one argument thing. Then kind of mold that to how you want it in do_quit. I don't even think there's a need to put ch = d->writetobuffer. There should be something like send_to_char that would show the choices, then you look for the argument to do those choices.

pseudocode
do_quit (CHAR_DATA * ch, char * argument)
if no argument
send_to_char your list of options
return

if argument = 1
do this

else if argument = 2
do this
else
default
and so on…

OR

switch (argument)
case 1
do this

break

case 2
do this
break

default


Something along those lines.
19 Aug, 2009, Lazerous wrote in the 29th comment:
Votes: 0
Well heh, ya I could do that easily enough, but not really what I was after, I wanted the actual menu.
I guess as a stop gap it would work, but…er…would just prefer an actual menu…

Don't get me wrong, I appreciate your idea and everything.
19 Aug, 2009, tphegley wrote in the 30th comment:
Votes: 0
Well, you need to study the nanny function a little bit more then. heh.
20 Aug, 2009, Lazerous wrote in the 31st comment:
Votes: 0
lol, heh…lucky for me I just as I was reading your reply and laughing,
got an email from the fellow who gave me the original menu snippet that I used in my login menu.

So hopefully when he gets off tonite if I haven't fixed it by then, he may have time to help me out.
Gotta say, for something so simple in a number of other languages I have used is alot more trouble in c/c++.
20 Aug, 2009, Rendelven wrote in the 32nd comment:
Votes: 0
Lazerous said:
Ok the logout one, gosh I am sorry about that last post…
What I did was, make this into the function called do_quit and renamed do_quit into do_quit2
which I then made sure was declared in smaug.h so here we go again…

..code..

So line 21 and 23 are the problems.


I suggest moving lines 23-67 into your nanny function, wherever that might be. Make sure it is actually within the SWITCH statement. Line 67 has two }. You should put these on separate lines.

Next, line 21 needs to be: return instead of break.

A break must be within a loop or switch statement. (I believe that's it.)
20 Aug, 2009, quixadhal wrote in the 33rd comment:
Votes: 0
Kline said:
AFAIK you can return in a switch( … ) but then need to omit the break for that case: … element.


Actually, you don't need to (unless C++ did something stupid). The break will never be executed, as the return will happen first, but it doesn't hurt to leave it there. The compiler may very well optimize it away, since it's normally unreachable code.

Personally, I think it's bad practice to have multiple exit points in a function, and usually try to work things so it falls through to a single return, but sometimes it's just not practical to do so.
20 Aug, 2009, Lazerous wrote in the 34th comment:
Votes: 0
Okies…I figured out sorta what the issues were with the link errors. It had to do with the declarations in the files listed.
Once I move the lines you sugested over to nanny, swapped those declarations it compiled fine.
I then went into the commands file to edit the quit to use do_quit2 which I had changed in the code to make it read into do_quit.
How ever, once i tried this, all it did was by pass the menu and actually quit me out.
I then figured I was gonna have to add a line to do_quit2 to make it go into do_quit, which i then did.
Once I loaded up the mud then tried to quit, it crashed with a unknown cexception…mutter….
why is something so basic in any other silly language this bloody hard to do in this one?

So I gonna call it a nite here, its 2am and I am tired of banging my head into this.
I will add in the morning a posting with the code in its various places and where I changed the declarations,
from what they were to what they are now. Maybe we can figure this last part out before I take a sledge hammer
to the code base…

Here is the places that were confusing and I may have made a mistake on my fixes to the link issues:

Skills.cpp Line: 7061
if (!str_cmp (name, "do_quit"))		return do_quit;


Skills.cpp Line: 7536
if (skill == do_quit)			return "do_quit";


changed to:

Skills.cpp Line: 7061
if (!str_cmp (name, "do_quit2"))		return do_quit2;


Skills.cpp Line: 7536
if (skill == do_quit2)			return "do_quit";


Here now is my complete do_quit and do_quit2 functions:
// Log Out Menu - Ryan Rae

void do_quit (CDescriptor *d, CCharacter *ch)
{
// char buf [MAX_STRING_LENGTH];
// CCharacter *ch;
ch = d->m_pCharacter;

d->WriteToBuffer("*** Welcome to: The Realm of Draenor ***\n\r\
\n\n\rLog Out Menu:\n\n\r\
0) Leave the Game\n\r\
1) Return to the Game\n\n\r\
2) Read the background story\n\r\
3) Read latest realm changes.\n\r\
4) Read the latest code changes.\n\n\r\
5) See the World Map.\n\r\
6) See a list of all the area's in the realm.\n\n\r\
Please select your choice: ", 0);
d->m_Connected = CON_MENU2;
return;
}

void do_quit2 (CCharacter *ch, char *argument)
{
int x, y;
int level;

if (ch->IsNpc () && ch->IsPolymorphed ()) {
ch->SendText ("You can't quit while polymorphed.\n\r");
return;
}

if (ch->IsNpc ())
return;

if (ch->IsFightPosition ()) {
set_char_color (AT_RED, ch);
ch->SendText ("No way! You are fighting.\n\r");
return;
}

if (ch->GetPosition () < POS_STUNNED) {
set_char_color (AT_BLOOD, ch);
ch->SendText ("You're not DEAD yet.\n\r");
return;
}

if (get_timer (ch, TIMER_RECENTFIGHT) > 0 && ch->IsMortal ()) {
set_char_color (AT_RED, ch);
ch->SendText ("Your adrenaline is pumping too hard to quit now!\n\r");
return;
}

if (auction->IsActive () && ((ch == auction->GetBuyer ())
|| (ch == auction->GetSeller ()))) {
ch->SendText ("Wait until you have bought/sold the item on auction.\n\r");
return;
}

if (ch->IsPkiller ()
&& ch->GetWimpLevel () > (int) ch->GetMaxHp () / 2.25) {
ch->SendText ("Your wimpy has been adjusted to the maximum level"
" for deadlies.\n\r");
do_wimpy (ch, "max");
}

// Get 'em dismounted until we finish mount saving – Blodkai, 4/97
if (ch->IsMounted ())
do_dismount (ch, "");


set_char_color (AT_WHITE, ch);
ch->SendText ("Your surroundings begin to fade as a mystical swirling "
"vortex of colors\n\renvelops your body… When you come to, things"
" are not as they were.\n\r\n\r");
act (AT_SAY, "A strange voice says, 'We await your return, $n…'", ch, NULL, NULL, TO_CHAR);
act (AT_BYE, "$n has left the game.", ch, NULL, NULL, TO_ROOM);
set_char_color (AT_GREY, ch);

sprintf (log_buf, "%s has quit.", ch->GetName ());
quitting_char = ch;
save_char_obj (ch);

if (ch->HasPet ()) {
act (AT_BYE, "$N follows $S master into the Void.", ch, NULL,
ch->GetPet (), TO_ROOM);
extract_char (ch->GetPet (), TRUE);
}

// Synch clandata up only when clan member quits now. –Shaddai
if (ch->GetPcData ()->GetClan ())
ch->GetPcData ()->GetClan ()->Save ();

saving_char = NULL;

level = ch->GetTrustLevel ();
// After extract_char the ch is no longer valid!
extract_char (ch, TRUE);
for (x = 0; x < MAX_WEAR; ++x)
for (y = 0; y < MAX_LAYERS; ++y)
save_equipment [x][y] = NULL;

gpDoc->LogString (log_buf, LOG_COMM, level);
}


Now you notice I took out any force push from do_quit2 into do_quit which leads to the menu.
Why keep it in if it was failing.

Now here is the code from the nanny for this menu:

// Temp Spot for Log Out Menu Stuff - Ryan Rae

switch ( argument [0] )
{
case CON_MENU2:
case '0':
// d->WriteToBuffer( "Come back again.\n\r", 0 );
// d->m_pCharacter->SetDesc (NULL);
// RemoveCharacter (*d);
do_quit2 ( ch, "");
break;

case '1':
break;

case '2':
do_help( ch, "story" );
break;

case '3':
do_help( ch, "motd" );
break;

case '4':
do_help( ch, "code" );
break;

case '5':
do_help( ch, "world" );
break;

case '6':
do_help( ch, "prep" );
break;

default:
d->WriteToBuffer("\nLog Out Menu:\n\n\r\
0) Leave the Game\n\r\
1) Return to the Game\n\n\r\
2) Read the background story\n\r\
3) Read latest realm changes.\n\r\
4) Read the latest code changes.\n\n\r\
5) See the World Map.\n\r\
6) See a list of all the area's in the realm.\n\n\r\
Please select your choice: ", 0);
return;
}

// End of New Log out Menu


So as it stands on this stuff, my quit command in the game is set to goto do_quit2 but as you see
in the skills.cpp I made that point to do_quit or so I thought…
So very confused and tired, but wanted to get this in here for you peeps before I crashed…
20 Aug, 2009, Rendelven wrote in the 35th comment:
Votes: 0
In your last code example, take case CON_MENU2: put it before the switch statement. put a break; statement at the end of the switch statement.
20 Aug, 2009, Lazerous wrote in the 36th comment:
Votes: 0
gah..okies…sigh…everyone telling me to put it in the switch…i figured it was other way around…
Ok, I did as asked, and sure it did the same as before and just quit out, did not go to the menu at all…

Here is the changes made to the code to try to fix that and it just kills the server, so my fix didnt fix it…not sure how
to get it to the menu… line # 49 in the code below.

act_comm.cpp Line: 1145
void do_quit2 (CCharacter *ch, char *argument)
{
int x, y;
int level;

if (ch->IsNpc () && ch->IsPolymorphed ()) {
ch->SendText ("You can't quit while polymorphed.\n\r");
return;
}

if (ch->IsNpc ())
return;

if (ch->IsFightPosition ()) {
set_char_color (AT_RED, ch);
ch->SendText ("No way! You are fighting.\n\r");
return;
}

if (ch->GetPosition () < POS_STUNNED) {
set_char_color (AT_BLOOD, ch);
ch->SendText ("You're not DEAD yet.\n\r");
return;
}

if (get_timer (ch, TIMER_RECENTFIGHT) > 0 && ch->IsMortal ()) {
set_char_color (AT_RED, ch);
ch->SendText ("Your adrenaline is pumping too hard to quit now!\n\r");
return;
}

if (auction->IsActive () && ((ch == auction->GetBuyer ())
|| (ch == auction->GetSeller ()))) {
ch->SendText ("Wait until you have bought/sold the item on auction.\n\r");
return;
}

if (ch->IsPkiller ()
&& ch->GetWimpLevel () > (int) ch->GetMaxHp () / 2.25) {
ch->SendText ("Your wimpy has been adjusted to the maximum level"
" for deadlies.\n\r");
do_wimpy (ch, "max");
}

// Get 'em dismounted until we finish mount saving – Blodkai, 4/97
if (ch->IsMounted ())
do_dismount (ch, "");

do_quit2 ( ch, ""); // This was the change made to try to get to the menu for logout.
set_char_color (AT_WHITE, ch);
ch->SendText ("Your surroundings begin to fade as a mystical swirling "
"vortex of colors\n\renvelops your body… When you come to, things"
" are not as they were.\n\r\n\r");
act (AT_SAY, "A strange voice says, 'We await your return, $n…'", ch, NULL, NULL, TO_CHAR);
act (AT_BYE, "$n has left the game.", ch, NULL, NULL, TO_ROOM);
set_char_color (AT_GREY, ch);

sprintf (log_buf, "%s has quit.", ch->GetName ());
quitting_char = ch;
save_char_obj (ch);

if (ch->HasPet ()) {
act (AT_BYE, "$N follows $S master into the Void.", ch, NULL,
ch->GetPet (), TO_ROOM);
extract_char (ch->GetPet (), TRUE);
}

// Synch clandata up only when clan member quits now. –Shaddai
if (ch->GetPcData ()->GetClan ())
ch->GetPcData ()->GetClan ()->Save ();

saving_char = NULL;

level = ch->GetTrustLevel ();
// After extract_char the ch is no longer valid!
extract_char (ch, TRUE);
for (x = 0; x < MAX_WEAR; ++x)
for (y = 0; y < MAX_LAYERS; ++y)
save_equipment [x][y] = NULL;

gpDoc->LogString (log_buf, LOG_COMM, level);
}


Here is the changes you sugested and done in the nanny.cpp

// Temp Spot for Log Out Menu Stuff - Ryan Rae

case CON_MENU2:
switch ( argument [0] )
{
case '0':
// d->WriteToBuffer( "Come back again.\n\r", 0 );
// d->m_pCharacter->SetDesc (NULL);
// RemoveCharacter (*d);
do_quit2 ( ch, "");
break;

case '1':
break;

case '2':
do_help( ch, "story" );
break;

case '3':
do_help( ch, "motd" );
break;

case '4':
do_help( ch, "code" );
break;

case '5':
do_help( ch, "world" );
break;

case '6':
do_help( ch, "prep" );
break;

default:
d->WriteToBuffer("\nLog Out Menu:\n\n\r\
0) Leave the Game\n\r\
1) Return to the Game\n\n\r\
2) Read the background story\n\r\
3) Read latest realm changes.\n\r\
4) Read the latest code changes.\n\n\r\
5) See the World Map.\n\r\
6) See a list of all the area's in the realm.\n\n\r\
Please select your choice: ", 0);
break;
}

// End of New Log out Menu


Color me confused….
21 Aug, 2009, Rendelven wrote in the 37th comment:
Votes: 0
If I read your code correctly, you are calling the function 'do_quit2' from within the function 'do_quit2'. This will end up in an endless recursive loop because it never exits. This should be removed.

'extract_char' is the function that removes a character from the game and disconnects them.

what you will want to do:

Use 'do_quit' instead of 'do_quit2'
Copy some of the checks to make sure a character can 'logout/quit'.
21 Aug, 2009, Lazerous wrote in the 38th comment:
Votes: 0
lol thats funny, i must have been really tired…lol, ok will test that and see..
21 Aug, 2009, Lazerous wrote in the 39th comment:
Votes: 0
hrmm…ended up with a link error when i swapped it to do_quit.
21 Aug, 2009, Lazerous wrote in the 40th comment:
Votes: 0
How should I called the do_quit? Ie: do_quit (victim, "") or ???? <— victim wont work without being defined and if defined it will cause link errors
with the other do_quit calls within the rest of the codebase, such as from idle time outs etc. I looked at what they are using, tried those and no
luck, ended up with link errors and undeclared identifiers that turned into link errors when declared… Here is the code from my search on do_quit

Searching for 'do_quit'…
E:\BuiltByRustry\Current Game Code\ACT_COMM.CPP(1125):void do_quit (CDescriptor *d, CCharacter *ch)
E:\BuiltByRustry\Current Game Code\ACT_COMM.CPP(1145):void do_quit2 (char *argument, CCharacter *ch)
E:\BuiltByRustry\Current Game Code\ACT_COMM.CPP(1193): do_quit ( ch, "");
E:\BuiltByRustry\Current Game Code\ACT_WIZ.CPP(256): do_quit2 (victim, "");
E:\BuiltByRustry\Current Game Code\ACT_WIZ.CPP(424): do_quit2 (victim, "");
E:\BuiltByRustry\Current Game Code\ACT_WIZ.CPP(502): do_quit2 (victim, "");
E:\BuiltByRustry\Current Game Code\ACT_WIZ.CPP(4011): do_quit (d->m_pCharacter, "");
E:\BuiltByRustry\Current Game Code\NANNY.CPP(580):do_quit2 ( ch, "");
E:\BuiltByRustry\Current Game Code\SKILLS.CPP(7061): if (!str_cmp (name, "do_quit2")) return do_quit2;
E:\BuiltByRustry\Current Game Code\SKILLS.CPP(7536): if (skill == do_quit2) return "do_quit";
E:\BuiltByRustry\Current Game Code\SMAUG.H(1817):DECLARE_DO_FUN(do_quit);
E:\BuiltByRustry\Current Game Code\SMAUG.H(1818):DECLARE_DO_FUN(do_quit2);
E:\BuiltByRustry\Current Game Code\UPDATE.CPP(1419): do_quit2 (ch, "");
13 occurrence(s) have been found.


Line #5 in the above code is the problem. Or appears to be the problem for the time being, it could be a
symptom of other things as well, but its the issue atm.
20.0/64