Toggling item prog

Posted by Edgeofforever on Tue 02 Nov 2004 12:32 PM — 7 posts, 22,186 views.

#0
Heres what I want to do: Have a representational value of an item set to 0 when the item is created. Then, when you examen the item, it does some echo and sets the value to 1. Then, if it is examned again, it does some different echo and sets the item to 0 again. I tried this:


if objval5(0)
<echo 1>
mposet 1201 v5 1
else
<echo 2>
mposet 1201 v5 0
endif

I also tried replacing the if statement by:

if objval(5) = 0
if objval5(<vnum>) = 0
if objval5(<keyword>) = 0

All of these are returning an "unknow ifcheck error", but when I went into the code, the ifcheck for "objval5" is there and seems to do what I would want it to. This has also somehow turned my object into a noteboard that you can wear on your back.
Any help on this problem would be appriciated.
Australia Forum Administrator #1
Can you post your exact mob/object prog, and state what kind of program you are running (eg. look_prog)?
#2
Well, I fixed this problem by writing two new commands that do what I wanted it to. However, while I was writing the commands, I stumbled across an Idea for a permanent flag, ie the equiptment never is removed, never scraps, doesn't dt etc. Heres my editing of the making a corpse code:


for ( obj = ch->first_carrying; obj; obj = obj_next )
    {
		obj_next = obj->next_content;

		if( IS_OBJ_STAT(obj, ITEM_PERM))
		{
			if(obj->next_content == NULL)
			{
				obj_to_room( corpse, ch->in_room );
				return;
			}
					
		}
		else
		{
			obj_from_char( obj );
			if ( IS_OBJ_STAT( obj, ITEM_INVENTORY )
			  || IS_OBJ_STAT( obj, ITEM_DEATHROT ) )
				extract_obj( obj );
			else
				obj_to_obj( obj, corpse );
		}
    }
Amended on Sun 07 Nov 2004 12:59 AM by Nick Gammon
#3
The problem seems to be that even though the code never hits the

obj_from_char code, my item still dissapears. Any ideas?
Australia Forum Administrator #4
Is this the code before you edited it? ...


    for ( obj = ch->first_carrying; obj; obj = obj_next )
    {
        obj_next = obj->next_content;
        obj_from_char( obj );
        if ( IS_OBJ_STAT( obj, ITEM_INVENTORY )
          || IS_OBJ_STAT( obj, ITEM_DEATHROT ) )
            extract_obj( obj );
        else
            obj_to_obj( obj, corpse );
    }

    obj_to_room( corpse, ch->in_room );
    return;


Your changes seem to make it do something different to what you might expect.

Why not just use continue, like this:


    for ( obj = ch->first_carrying; obj; obj = obj_next )
    {
        obj_next = obj->next_content;
        if( IS_OBJ_STAT(obj, ITEM_PERM)) 
           continue;

        obj_from_char( obj );
        if ( IS_OBJ_STAT( obj, ITEM_INVENTORY )
          || IS_OBJ_STAT( obj, ITEM_DEATHROT ) )
            extract_obj( obj );
        else
            obj_to_obj( obj, corpse );
    }

    obj_to_room( corpse, ch->in_room );
    return;

#5
That code makes sense to me, the continue, unfortunately, I tested it and the item dissapears. Instead of remaining on the character or in the corpse, it simply dissapears. Not sure why this is... any ideas?
Australia Forum Administrator #6
No it isn't clear, unless you maybe put the check *after* obj_from_char. Try running under gdb and seeing what happens after that loop.