Ofind/Mfind not working

Hello again,
So, I’m having problems with my ofind/mfind commands. Neither of them show anything when I use them, even when I use the exact keywords. This leads me to believe that it is not an actual problem in the command itself, but maybe something deeper, but not sure what.

void do_ofind(CHAR_DATA *ch, char *argument)
{
	extern int top_obj_index;
	OBJ_INDEX_DATA      *pObjIndex;
	BUFFER              *buf1;
	char                arg  [ MIL ]={'\0'};
	bool fAll;
	bool fBigger;
	bool found = FALSE;
	long largest = 0;
	int vnum = 0;
	int lsize = 0;
	int col = 0;
	int nMatch = 0;
	CheckCH(ch);

	one_argument( argument, arg );
	if ( IS_NULLSTR(arg) )
	{
		send_to_char("\tCSyntax:  ofind [all/name/item_type/item_size/oversize]\tn\n\r", ch );
		return;
	}

	buf1=new_buf();
	fAll    = !str_cmp( arg, "all" );
	fBigger = !str_cmp( arg, "oversize" );

	/*
	 * Yeah, so iterating over all vnum's takes 10,000 loops.
	 * Get_obj_index is fast, and I don't feel like threading another link.
	 * Do you?
	 * -- Furey
	 */
	for ( vnum = 0; nMatch < top_obj_index; vnum++ )
	{
		if ( ( pObjIndex = get_obj_index( vnum ) ) )
		{
			nMatch++;
			if ( fAll || is_name( arg, pObjIndex->name )
				|| flag_value( type_flags, arg ) == pObjIndex->item_type
				|| flag_value( size_flags, arg ) == pObjIndex->weight
				|| (fBigger && pObjIndex->weight > MAX_SIZE) )
			{
				found = TRUE;
				add_buf( buf1, (char *)Format("[%5d] %-17.16s", pObjIndex->vnum, capitalize( pObjIndex->short_descr )) );
				
				if ( ++col % 3 == 0 )
				{
					add_buf( buf1, "\n\r" );
				}
				
				if(pObjIndex->weight > lsize) 
				{
					lsize = pObjIndex->weight;
					largest = pObjIndex->vnum;
				}
			}
		}
	}

	if ( !found )
	{
		send_to_char( "No object(s) found.\n\r", ch);
		return;
	}

	if ( col % 3 != 0 )
	{
		add_buf( buf1, "\n\r" );
	}

	if ( fBigger )
	{
		add_buf( buf1, (char *)Format("The largest object is %ld at size %d.\n\r", largest, lsize) );
	}

	page_to_char( buf_string(buf1), ch );
	free_buf(buf1);
	return;
}
1 Like

@arholly - when you are asking programming for help like this, you’ve got to give a better example of what you are typing into your game, what you expect that to do, and what you actually see. Then, since you have a git repo up, give the link to that so that if someone wants to help you they can easily get to all of the code and throw it into a debugger.

…and then maybe add some instructions for starting a test character that doesn’t involve going through your sixty question new player setup form each time. :wink:

Do that, and I’d be happy to have another look.

1 Like

id personally check your is_name function, something must be wrong in there?

1 Like

Not a problem @Rahjill. So, I’ve setup a test mud at themudhost.net 9080.
Login: testchar
password: password

Github repository: https://github.com/ptrayal/Project_Twilight

This is what I’m seeing:

<unhurt> 
inv
You are carrying:
     a long cloak

<unhurt> 
obj_find long cloak
No object(s) found.

<unhurt> 
obj_find cloak
No object(s) found.

I should be seeing a list of all the objects with the keyword cloak, but I’m not.

Hope that helps.
Best Regards,
Arholly

1 Like

I suggest you increase your bug messages, and logging the arguments passed to the methods you’re having trouble with. :smiley:

I added a log statement and it is passing the correct argument.

Feb-28-2019 (07:41) :: TRACKING - do_ofind cloak

1 Like

@Rahjill: I’ve added a testchar to the repository along with a generic password to help in the future.

1 Like

Still think there is something wrong with your is_name function, after looking at the repository…

1 Like

I wish it was that, but it is identical to stock ROM2.4b in that regard. I compared the two functions and they are identical except for my added logging functionality I put in this for problem.

1 Like

if its passing the correct arguments but not actually finding the object, then something must be wrong with it?

1 Like

Just looked that the ofind function, and yes you have it showing the argument from ofind, but id add a log myself showing what is_name() is getting, that way you can fully rule out that there is an issue with the is_name function itself.

1 Like

Ok, it’s not even getting that far into it where is_name is the problem. So, I added a bunch more logging and it’s not even making it into the for loop. Here is what the new logging is showing me and here is what the new code is.

New Logging:

Mar-01-2019 (09:23) :: TRACKING 1 - do_ofind argument cloak
Mar-01-2019 (09:23) :: TRACKING 2 - do_ofind arg cloak
Mar-01-2019 (09:23) :: TRACKING 3: fAll = FALSE. fBigger = FALSE.

Nothing else shows up for logging after Tracking 3.
New Code:
void do_ofind(CHAR_DATA *ch, char *argument)
{
extern int top_obj_index;
OBJ_INDEX_DATA *pObjIndex;
BUFFER *buf1;
char arg [ MIL ]={’\0’};
bool fAll;
bool fBigger;
bool found = FALSE;
long largest = 0;
int vnum = 0;
int lsize = 0;
int col = 0;
int nMatch = 0;

	CheckCH(ch);

	log_string( LOG_COMMAND, Format("TRACKING 1 - do_ofind argument %s", argument));
	one_argument( argument, arg );
	log_string( LOG_COMMAND, Format("TRACKING 2 - do_ofind arg %s", arg));

	if ( IS_NULLSTR(arg) )
	{
		send_to_char("\tCSyntax:  ofind [all/name/item_type/item_size/oversize]\tn\n\r", ch );
		return;
	}

	buf1 = new_buf();
	fAll    = !str_cmp( arg, "all" );
	fBigger = !str_cmp( arg, "oversize" );
	log_string( LOG_COMMAND, Format("TRACKING 3: fAll = %s. fBigger = %s.", 
		fAll ? "TRUE" : "FALSE",
		fBigger ? "TRUE" : "FALSE"));


	/*
	 * Yeah, so iterating over all vnum's takes 10,000 loops.
	 * Get_obj_index is fast, and I don't feel like threading another link.
	 * Do you?
	 * -- Furey
	 */
	for ( vnum = 0; nMatch < top_obj_index; vnum++ )
	{
		log_string( LOG_COMMAND, Format("OFIND TRACKING A: fAll = %s. fBigger = %s.", 
			fAll ? "TRUE" : "FALSE",
			fBigger ? "TRUE" : "FALSE"));
		if ( ( pObjIndex = get_obj_index( vnum ) ) )
		{
			log_string( LOG_COMMAND, Format("OFIND TRACKING B: fAll = %s. fBigger = %s.", 
				fAll ? "TRUE" : "FALSE",
				fBigger ? "TRUE" : "FALSE"));
			nMatch++;
			if ( fAll || is_name( arg, pObjIndex->name )
				|| flag_value( type_flags, arg ) == pObjIndex->item_type
				|| flag_value( size_flags, arg ) == pObjIndex->weight
				|| (fBigger && pObjIndex->weight > MAX_SIZE) )
			{
				found = TRUE;
				log_string( LOG_COMMAND, Format("TRACKING # - FOUND do_ofind arg %s", arg));
				add_buf( buf1, (char *)Format("[%5d] %-17.16s", pObjIndex->vnum, capitalize( pObjIndex->short_descr )) );
				
				if ( ++col % 3 == 0 )
				{
					add_buf( buf1, "\n\r" );
				}
				
				if(pObjIndex->weight > lsize) 
				{
					lsize = pObjIndex->weight;
					largest = pObjIndex->vnum;
				}
			}
		}
	}

	if ( !found )
	{
		send_to_char( "No object(s) found.\n\r", ch);
		return;
	}

	if ( col % 3 != 0 )
	{
		add_buf( buf1, "\n\r" );
	}

	if ( fBigger )
	{
		add_buf( buf1, (char *)Format("The largest object is %ld at size %d.\n\r", largest, lsize) );
	}

	page_to_char( buf_string(buf1), ch );
	free_buf(buf1);
	return;
}
1 Like

Ok, so kind of figured it out (I suppose). So, I guessed and it is a guess really, but I did a search through the code for top_obj_index and couldn’t find many places it was used. So, on a hunch I went and checked the do_memory command every mud has and this codebase wasn’t using top_obj_index for the memory command like stock does. It was using a variable “newobjs”. So, I replaced that and suddenly everything started popping up.

Not sure if it is correct, but at least I can find objects now.

1 Like

Sorry, I was away for a little while. Glad to hear you got it fixed!

1 Like

for mfind, does it still use top_mob_index ? The fix you have done seems fine, or correct. Do you have do_owhere? and does it use object_list?

1 Like