Showing object's vNum

Posted by Alkarindil on Tue 08 Apr 2008 05:28 PM — 21 posts, 84,271 views.

Brazil #0
Hi! Some time ago I had changed my do_look code to display the vnum of the room to immortals with a very simple modification:

if( IS_IMMORTAL(ch))
pager_printf(ch, " (%d)",ch->in_room->vnum);

I am trying to do the same with the listed objects when using the look command, but with many trials, I have no success in this matter.

Is there any easy way to make this work?
Any suggestions?
USA #1
Why doesn't basically the same thing work? What have you tried so far, and how has it failed?
Brazil #2
I tryied to show vnum in the show_list_to_char() function.
But I am not understanding how the hell I can find the vnum.
I realise there is a for, and it prints the content of an array with the objects in the room. In the end we can find the breakline after the name of the object.
I also find out that the line that write the object's name is:

send_to_char( prgpstrShow[iShow], ch );

But is there any way of extract the vnum using this information?
USA #3
The vnum is located in the object's prototype. So you want something like obj->prototype->vnum, although it might not actually be called "prototype".

If the function you're looking at is building things up one line at a time, putting them into an array, then you need to find where it prints out the name after which you want to put the vnum.

But no, you can't extract the vnum from the generated strings. You need to find the place where the object pointer is.
Brazil #4
Ok, now I am trying something like

pager_printf(ch, " (%d)", obj->pIndexData->vnum);

Does not work.
What does pIndexData means?
USA #5
Ah, yes, it's pIndexData, not prototype. That is indeed the prototype for the object. What do you mean by "does not work"? What is it doing, or not doing?
Brazil #6
Okay, I downloaded the code from gammon's site, so this show_list_to_char() function in act_info.c is the same thing; I never touched it before.

in the end of this function are this lines:

send_to_char( prgpstrShow[iShow], ch );
//Print the object's name
pager_printf(ch, " (%d)", obj->pIndexData->vnum);
//My line
/*if ( IS_NPC(ch) || xIS_SET(ch->act, PLR_COMBINE) ) */
	{
	    if ( prgnShow[iShow] != 1 )
		ch_printf( ch, " (%d)", prgnShow[iShow] );
	}
	send_to_char( "\n\r", ch );
	DISPOSE( prgpstrShow[iShow] );
    }

    if ( fShowNothing && nShow == 0 )
    {
	if ( IS_NPC(ch) || xIS_SET(ch->act, PLR_COMBINE) )
	    send_to_char( "     ", ch );
	set_char_color( AT_OBJECT, ch );
	send_to_char( "Nada.\n\r", ch );
    }

    /*
     * Clean up.
     */
    DISPOSE( prgpstrShow );
    DISPOSE( prgnShow	 );
    DISPOSE( pitShow	 );
    return;
}


Well, it must work for any player, but that's easy to change...
Amended on Tue 08 Apr 2008 08:25 PM by Alkarindil
USA #7
Quote:
What do you mean by "does not work"? What is it doing, or not doing?
Brazil #8
Do nothing, it crashes.
USA #9
Could you give the output from gdb? Nick wrote an excellent guide here:
http://www.gammon.com.au/forum/bbshowpost.php?bbsubject_id=3653
Brazil #10
I am using Windows with Visual Studio: it's my computer at work.
I couldn't get this kind of debbuging to work here, I am just a "low-level" programmer.
USA #11
If you have Visual Studio, you can use its debugger too. Just show the point at which the crash occurs; perhaps the 'obj' pointer is null?
Brazil #12
This is the problem, there are no errors during the compilation! It crashes when I log in with any player and "see" the room.
USA #13
Use the debugger when it crashes.
USA #14
That's why I asked for the debugger output, not the compiler output. :-)

I'd suggest googling for Visual Studio Debugger tutorials. The only one I know of off-hand is:
http://www.stanford.edu/class/cs106b/handouts/HO07P.pdf
I don't know how helpful it will be, though.
Australia Forum Administrator #15
You need to look at the code to see what is happening.

You did this:


pager_printf(ch, " (%d)", obj->pIndexData->vnum);


However the place you did it was at the end of the loop which looked at all objects, so obj will be null and it will crash with a null dereference.

If you examine the code you will see that s/he allocates some temporary variables (prgpstrShow, prgnShow, pitShow, pstrShow) which are used to hold the object's information (and group like objects). This is what is being displayed at display time. To display the vnum you need to allocate another item (I called it pvnumShow) and move the vnum into it. Here is the diff of my amendments:


*** act_info.c_orig	2008-04-09 07:14:44.000000000 +1000
--- act_info.c	2008-04-09 07:25:03.000000000 +1000
***************
*** 473,478 ****
--- 473,479 ----
     char **prgpstrShow;
     int *prgnShow;
     int *pitShow;
+    int *pvnumShow;
     char *pstrShow;
     OBJ_DATA *obj;
     int nShow;
***************
*** 537,542 ****
--- 538,544 ----
     CREATE( prgpstrShow, char *, count + ( ( offcount > 0 ) ? offcount : 0 ) );
     CREATE( prgnShow, int, count + ( ( offcount > 0 ) ? offcount : 0 ) );
     CREATE( pitShow, int, count + ( ( offcount > 0 ) ? offcount : 0 ) );
+    CREATE( pvnumShow, int, count + ( ( offcount > 0 ) ? offcount : 0 ) );
     nShow = 0;
     tmp = ( offcount > 0 ) ? offcount : 0;
     cnt = 0;
***************
*** 553,558 ****
--- 555,561 ----
           prgpstrShow[nShow] = str_dup( hallucinated_object( ms, fShort ) );
           prgnShow[nShow] = 1;
           pitShow[nShow] = number_range( ITEM_LIGHT, ITEM_BOOK );
+          pvnumShow[nShow] = number_range( 1, 500000 );
           nShow++;
           --tmp;
        }
***************
*** 560,565 ****
--- 563,569 ----
            && can_see_obj( ch, obj ) && ( obj->item_type != ITEM_TRAP || IS_AFFECTED( ch, AFF_DETECTTRAPS ) ) )
        {
           pstrShow = format_obj_to_char( obj, ch, fShort );
+          pvnumShow[nShow] = obj->pIndexData->vnum;
           fCombine = FALSE;
  
           if( IS_NPC( ch ) || xIS_SET( ch->act, PLR_COMBINE ) )
***************
*** 599,604 ****
--- 603,609 ----
           prgpstrShow[nShow] = str_dup( hallucinated_object( ms, fShort ) );
           prgnShow[nShow] = 1;
           pitShow[nShow] = number_range( ITEM_LIGHT, ITEM_BOOK );
+          pvnumShow[nShow] = number_range( 1, 500000 );
           nShow++;
        }
     }
***************
*** 646,651 ****
--- 651,657 ----
              ch_printf( ch, " (%d)", prgnShow[iShow] );
        }
  
+       ch_printf( ch, " [%d]", pvnumShow[iShow] );
        send_to_char( "\r\n", ch );
        DISPOSE( prgpstrShow[iShow] );
     }
***************
*** 664,669 ****
--- 670,676 ----
     DISPOSE( prgpstrShow );
     DISPOSE( prgnShow );
     DISPOSE( pitShow );
+    DISPOSE( pvnumShow );
     return;
  }

Amended on Tue 08 Apr 2008 09:53 PM by Nick Gammon
Australia Forum Administrator #16
Example output:


You are carrying:
     a bone sword [9828]

...

A large marble fountain gushes forth here. [10401]

...

The corpse of the bone naga lies here. (2) [10]
A pool of spilled blood lies here. (4) [17]
The corpse of a carrion crawler lies here. (2) [10]
Still twitching as if to kick you, the leg of a carrion crawler lies here. [15]
Brazil #17
Ow yes yes! My mistake, sorry!



Loaded 'ntdll.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\kernel32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\winmm.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\user32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\gdi32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\advapi32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\rpcrt4.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\secur32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\wsock32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\ws2_32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\msvcrt.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\ws2help.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\mswsock.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\dnsapi.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\winrnr.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\wldap32.dll', no matching symbolic information found.
Loaded 'C:\Arquivos de programas\Bonjour\mdnsNSP.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\iphlpapi.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\hnetcfg.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\wshtcpip.dll', no matching symbolic information found.
First-chance exception in smaug.exe: 0xC0000005: Access Violation.
The program 'C:\Documents and Settings\alkarindil\Desktop\Smaug\smaug.exe' has exited with code 0 (0x0).



Is that info you need?
USA #18
Well, what I was trying to get at is that the obj pointer was probably null, and for you to find that information in the debugger because it will save you a very large amount of time in the future. But Nick provided the solution, so you can probably use that and make sure that it works for you. :-)
Australia Forum Administrator #19
Try making my suggested changes now.

By the way, I agree with the earlier posters that it is much more helpful to say in what way it doesn't work, rather than to say "I had no success".

There are a few major ways things "don't work":

  • It doesn't compile. In which case copy and paste the error message from the compiler.
  • It crashes when it runs. In which case copy and paste the error message from the crash, and describe what you did to cause it. Preferably use gdb to examine the crash, and do a "bt" (backtrace) to see exactly what happened leading up to the crash.
  • It seems to do nothing at all - that is, it runs but does the same thing as before. Perhaps you didn't reboot the server? Or you changed completely the wrong place?
  • It makes a difference, but the difference is wrong. In which case copy and paste the output you got, and explain in what way it is wrong. For example, it might show the incorrect vnum.


More detailed information saves a lot of time as we go to and fro trying to extract from you something which is in front of you on the screen. For example:

Quote:

Do nothing, it crashes.


That is not doing nothing, that is crashing. You need to be specific.
Amended on Tue 08 Apr 2008 09:52 PM by Nick Gammon
Brazil #20
It's working!
Man, I would never think in made all this stuff...
Thanks a lot Nick!
Thanks David! U guys rox!