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
➜ SMAUG
➜ SMAUG coding
➜ Help understanding how dest_buf works...
|
Help understanding how dest_buf works...
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
| Posted by
| Nick Cash
USA (626 posts) Bio
|
| Date
| Tue 18 Mar 2003 11:57 PM (UTC) Amended on Tue 18 Mar 2003 11:59 PM (UTC) by Nick Cash
|
| Message
| I know I asked this before, and you said it was a destination buffer but I have an example from my SWR based MUD and I just wanted to ask a few questions. First I'll put in the example...
switch( ch->substate )
{
default:
if ( arg[0] == '\0' )
{
send_to_char( "&RUsage: Makeblade <name>\n\r&w", ch);
return;
}
checktool = FALSE;
checkdura = FALSE;
checkbatt = FALSE;
checkoven = FALSE;
if ( !IS_SET( ch->in_room->room_flags, ROOM_FACTORY ) )
{
send_to_char( "&RYou need to be in a factory or workshop to do that.\n\r", ch);
return;
}
for ( obj = ch->last_carrying; obj; obj = obj->prev_content )
{
if (obj->item_type == ITEM_TOOLKIT)
checktool = TRUE;
if (obj->item_type == ITEM_DURASTEEL)
checkdura = TRUE;
if (obj->item_type == ITEM_BATTERY)
checkbatt = TRUE;
if (obj->item_type == ITEM_OVEN)
checkoven = TRUE;
}
if ( !checktool )
{
send_to_char( "&RYou need toolkit to make a vibro-blade.\n\r", ch);
return;
}
if ( !checkdura )
{
send_to_char( "&RYou need something to make it out of.\n\r", ch);
return;
}
if ( !checkbatt )
{
send_to_char( "&RYou need a power source for your blade.\n\r", ch);
return;
}
if ( !checkoven )
{
send_to_char( "&RYou need a small furnace to heat the metal.\n\r", ch);
return;
}
chance = IS_NPC(ch) ? ch->top_level
: (int) (ch->pcdata->learned[gsn_makeblade]);
if ( number_percent( ) < chance )
{
send_to_char( "&GYou begin the long process of crafting a vibroblade.\n\r", ch);
act( AT_PLAIN, "$n takes $s tools and a small oven and begins to work on something.", ch,
NULL, argument , TO_ROOM );
add_timer ( ch , TIMER_DO_FUN , 25 , do_makeblade , 1 );
ch->dest_buf = str_dup(arg);
return;
}
send_to_char("&RYou can't figure out how to fit the parts together.\n\r",ch);
learn_from_failure( ch, gsn_makeblade );
return;
case 1:
if ( !ch->dest_buf )
return;
strcpy(arg, ch->dest_buf);
DISPOSE( ch->dest_buf);
break;
case SUB_TIMER_DO_ABORT:
DISPOSE( ch->dest_buf );
ch->substate = SUB_NONE;
send_to_char("&RYou are interupted and fail to finish your work.\n\r", ch);
return;
}
ch->substate = SUB_NONE;
Alright, there is more code but that is the section I have questions on. And yes, I know this is a timer....
Question 1: What exactly is dest_buf used for?
Question 2: Some codes like this use dest_buf_2, how do I know of I need to use dest_buf_2?
Question 3: Dest_buf and dest_buf_2 are defined as void, shouldn't they be defined with other values?
Question 4: Could I switch the ch->substate in the switch statement to ch->cusstate? I'm making a code that involves a lot of timers and I just wanted to make sure I knew how all of this stuff worked so I didn't sit there for hours wondering why.
Thanks for any and all help. I really appreciate it. |
~Nick Cash
http://www.nick-cash.com | | Top |
|
| Posted by
| Nick Gammon
Australia (23,173 posts) Bio
Forum Administrator |
| Date
| Reply #1 on Thu 20 Mar 2003 02:30 AM (UTC) |
| Message
| I haven't looked in great detail, but will try to answer in part.
- It is used to hold a pointer to various temporary things, like the description you are editing, or the character you have morphed to.
- This is probably because the author knew dest_buf was, or might be, in use at the same time. I can't see dest_buf_2 in stock SMAUG, so the SWR author might have chosen another pointer to be on the safe side.
- Because they can be pointers to different things, eg. MORPH_DATA, CHAR_DATA. It is more logical to use a pointer to void, rather than confusing people by choosing a specific pointer and then overriding it. Also, a pointer to void doesn't need casting.
- Can't answer that one.
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | 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.
6,561 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top