Thank you txesmi.

I tried incorporating some of your code into my program.

So far, this is what my OrcStronghold.c program looks like:

Code:
...

function change_mouse_mode()
{
   mouse_mode += 1;
   mouse_mode %= 2;

   if (mouse_mode == 1)
   {
      mouse_map = cursor_pcx;
   }
   
}

...


// switch to toggle inventory:
void toggleInventory()
{
	// put some comparisons here:
	// f.e. if we are dead, don't allow to toggle inventory:
	if(player.HEALTH <= 0)
	{ 
		return; 
	}
	// toggle var:
	invOpen += 1;
	invOpen %= 2;
	
	// if we've opened the inventory:
	if(invOpen == 1)
	{
		// show the mouse pointer:

		change_mouse_mode();
		mouse_mode = 1;
		
		// PUT IN CODE FOR INVENTORY GUI
		
	   inv_open_bag ( bag, 375, 75 );  // OPEN INVENTORY BAG CODE
	}
	else
	{

	   mouse_mode = 0;
	   inv_close_bag(bag);
   }
}

action Player()
{
   ...

   on_i = toggleInventory; 
   on_m = change_mouse_mode;
	
   set_on_click_callback("inv_run_slot_callback");

   while (my.x)
   {
      ...
   }

   ...
}

function inv_run_slot_callback ( Bag *bag, var slot_id ) 
{
	if ( !on_click_callback_function_ptr )
		return 0;
	
	int i = 0;
	for ( ; i<bag->_slot_count; i++ )
	{
		Slot *slot = bag->slots[i];
		if ( slot->id != slot_id )
			continue;
		Item *item = slot->item;
		if ( !item )
			return 0;
		on_click_callback_function_ptr ( INV_ITEM_PLACED, bag->id, slot->id, item->id, NULL );
		return 1;
	}
	return 0;
}



With this code, the game goes fine, until I bring up my inventory bag by pressing the "i" key. The inventory bag will come up, and I can even arm my player with a weapon using it. However, when I press the "i" key again to close the inventory bag, my player will move like normal for about a second, but then freeze in place.

Do you know what bug in this code might be causing this? I have been trying to figure it out myself.

Last edited by Ruben; 01/28/14 05:06.