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


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  SMAUG
. -> [Folder]  SMAUG coding
. . -> [Subject]  Function help

Function help

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


Posted by MattJ820   (32 posts)  [Biography] bio
Date Mon 13 Apr 2015 01:41 AM (UTC)

Amended on Mon 13 Apr 2015 03:12 AM (UTC) by MattJ820

Message
Hello guys,

I'm trying to write my first function and I'm getting some strange results.

if I type "bountyscan" with no argument, I'm getting a "They aren't here" response rather than the Usage bountyscan <target>

If I bounty scan an NPC, I'm getting the Indetification No match response rather than the you can't scan NPC response.

If I try to bounty scan myself or another player, I get an emergency copy over that prevents the crash so I don' have a core to work with. This is my first function that I pieced together after a view C tutorials and reviewing other functions within bounty.c

Can someone help me figure out what I'm doing wrong?

/* Allows bounty hunters to hunt players by identifying them with a scanner to see if they'e on the bounty list
for situations where they have not been introduced. Object may be required to be worn later..not sure. */
void do_bountyscan ( CHAR_DATA *ch, char *argument)
{
char arg[MAX_STRING_LENGTH];
BOUNTY_DATA *bounty;
CHAR_DATA *victim;

bounty = get_disintegration( victim->name );

if ( IS_NPC(victim))
{
send_to_char( "You cannot bountyscan an NPC\n\r", ch );
return;
}

if ((victim = get_char_room(ch, argument)) == NULL)
{
send_to_char("They aren't here.\n\r", ch);
return;
}

if (argument[0] == '\0' )
{
send_to_char( "Usage: bountyscan <target>\n\r", ch );
return;
}

if ( ch == victim )
{
send_to_char( "Why scan yourself, would you kill yourself for the money?\n\r", ch );
return;
}

if ( bounty != NULL )
{
ch_printf( ch, "Identification: Match! %s has a bounty worth %ld credits.\n\r", victim->name, bounty->amount );
return;
}

if (bounty == NULL)
{
send_to_char( "Identification: No Match!\n\r", ch );
return;
}
}
[Go to top] top

Posted by Meerclar   USA  (733 posts)  [Biography] bio
Date Reply #1 on Mon 13 Apr 2015 03:41 AM (UTC)
Message
Purely for ease of reading ...
/* Allows bounty hunters to hunt players by identifying them with a scanner to see if they'e on the bounty list
for situations where they have not been introduced. Object may be required to be worn later..not sure. */
void do_bountyscan ( CHAR_DATA *ch, char *argument)
{
char arg[MAX_STRING_LENGTH];
BOUNTY_DATA *bounty;
CHAR_DATA *victim;

bounty = get_disintegration( victim->name );

if ( IS_NPC(victim))
	{
	send_to_char( "You cannot bountyscan an NPC\n\r", ch );
	return;
	}

if ((victim = get_char_room(ch, argument)) == NULL)
	{
	send_to_char("They aren't here.\n\r", ch);
	return;
	}

if (argument[0] == '\0' )
	{
	send_to_char( "Usage: bountyscan <target>\n\r", ch );
	return;
	}

if ( ch == victim )
	{
	send_to_char( "Why scan yourself, would you kill yourself for the money?\n\r", ch );
	return;
	}

if ( bounty != NULL )
	{
	ch_printf( ch, "Identification: Match! %s has a bounty worth %ld credits.\n\r", victim->name, bounty->amount );
	return;
	}

if (bounty == NULL)
	{
	send_to_char( "Identification: No Match!\n\r", ch );
	return;
	}
}

Meerclar - Lord of Cats
Coder, Builder, and Tormenter of Mortals
Stormbringer: Rebirth
storm-bringer.org:4500
www.storm-bringer.org
[Go to top] top

Posted by Meerclar   USA  (733 posts)  [Biography] bio
Date Reply #2 on Mon 13 Apr 2015 03:51 AM (UTC)

Amended on Mon 13 Apr 2015 03:55 AM (UTC) by Meerclar

Message
Ok, now that we can read it more easily, let's see if we can find the problem .....

At first glance, I don't see anything obviously wrong in the code, though that doesn't mean much if you missed a declaration. The hotboot you're experiencing would seem to indicate a missed declaration somewhere and while you aren't getting a core dump, you could try running in gdb to get more info on the background processes prior to the hotboot.

As for your scan without an arg returning the "wrong" message, it's a perfectly valid response against a null argument. Take a look at fight.c or magic.c or skills.c and compare the code for checking targets in the room against what you did here.

Meerclar - Lord of Cats
Coder, Builder, and Tormenter of Mortals
Stormbringer: Rebirth
storm-bringer.org:4500
www.storm-bringer.org
[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] bio   Forum Administrator
Date Reply #3 on Mon 13 Apr 2015 06:02 AM (UTC)
Message
I think it's the order you are doing it. Check for no argument, before you look up the person in the room.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by MattJ820   (32 posts)  [Biography] bio
Date Reply #4 on Mon 13 Apr 2015 04:43 PM (UTC)
Message
Changing the order worked. I don't really understand why the order matters, but I guess it does. Proof is in the pudding. Do you have any insight into why so I can understand? I would think the computer would go through all the ifchecks one after another and deliver the appropriate action regardless of the order.

I did it in this order

no argument

victim not in room

victim = self

victim = npc

no bounty

bounty
[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] bio   Forum Administrator
Date Reply #5 on Mon 13 Apr 2015 07:56 PM (UTC)
Message
Well, you are calling "get_char_room" with an empty argument. It is probably written to respond "they aren't here" in that situation. Otherwise what else could it do? It returns the "victim" variable, so if there is no victim you would then need to test that to be NULL or not.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] bio   Forum Administrator
Date Reply #6 on Mon 13 Apr 2015 07:57 PM (UTC)
Message
Your original code had this, for example:


CHAR_DATA *victim;

bounty = get_disintegration( victim->name );

if ( IS_NPC(victim))
	{
	send_to_char( "You cannot bountyscan an NPC\n\r", ch );
	return;
	}



At that point "victim" does not exist, because you haven't found who the victim is, and thus you are lucky it didn't crash when you tried to get the victim name.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by MattJ820   (32 posts)  [Biography] bio
Date Reply #7 on Mon 13 Apr 2015 08:50 PM (UTC)
Message
That makes sense, thank you.
[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.


19,715 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]