What I tried doing was declaring "player_gold" variable before #including "inventory.c" in main.c , as shown here:

Code:
// main.c

int player_gold;

...

#include "inventory.c"



In my inventory.c , I am attempting to add an integer variable value next to a string (by showing the string "Gold: ", and player_gold next to it), as shown here:

Code:
// inventory.c

...

PANEL* gold_panel =
{
	window(600,25,350,350,goldPanel,200,300);
}

function slotOnClick(PANEL* clicked_panel) 
{
	Slot* clicked_slot = getSlotPtrForPanelPtr(clicked_panel);
	Item* clicked_item;
	
	FONT* gold_txt_font = font_create("Times#30i");
	STRING* gold_amnt_txt;
	
   gold_amnt_txt = str_create("Gold:  ");
   
	pan_setdigits(gold_panel,0,610,400,"%2.f",gold_txt_font,1,player_gold); // GIVING OFF ERROR
	pan_setstring(gold_panel,0,598,400,gold_txt_font,gold_amnt_txt);
	
	
				
	if (clicked_slot == NULL) { diag("\n*** Error: panel not found\n"); }
				
	if (global_floating_item_ptr->item == NULL) 	// player clicked on item in inventory while not floating an item
	{
		if ( event_type == EVENT_CLICK ) // mouse left button event
		{// -------------------------------------------------------------------------
			PANEL* item_pnl_descr;	
			
			int gold_added = 0;
			if(str_cmp(clicked_slot->item->floating_icon, "steel_sword.pcx"))
			{
				reset(mace_panel, SHOW);
				reset(gold_panel, SHOW);
				set(sword_panel, SHOW);	
			}	
			else if(str_cmp(clicked_slot->item->floating_icon, "mace.pcx"))
			{
				reset(sword_panel, SHOW);
				reset(gold_panel, SHOW);
				set(mace_panel, SHOW);	
			}			
			else if(str_cmp(clicked_slot->item->floating_icon, "gold_coins.pcx"))
			{
				if(gold_added == 0)
				{
					gold_added = 1;
					
					reset(sword_panel, SHOW);
					reset(mace_panel, SHOW);
					set(gold_panel, SHOW);	
				}
			}						
						
						
						
			if (clicked_slot->item != NULL) // Player is grabbing an item out of the inventory
			{		
				// optionally callback with action, bag_id, slot_id, item_id
				if (on_click_callback_function_ptr) 
				on_click_callback_function_ptr(INV_ITEM_REMOVED,clicked_slot->bag_id,clicked_slot->id,0,clicked_slot->item->id);
							
				// Create the floating panel
							
				global_floating_item_ptr->floating_item_panel = pan_create("",floating_item_layer);
							
				// Set the item and panel image of the floating item structure.  This effectively "floats"
				// the item that was stored in the inventory slot.
							
				global_floating_item_ptr->item = clicked_slot->item;
				global_floating_item_ptr->floating_item_panel->bmap = bmap_create(clicked_slot->item->floating_icon);
				global_floating_item_ptr->floating_item_panel->flags |= VISIBLE;
							
				// Set the item pointer of the clicked on slot to NULL
							
				clicked_slot->item = NULL;
							
				// Restore inventory slot image to be the default background image
							
				clicked_slot->slot_panel->bmap = bmap_create(clicked_slot->background_image);			
							
				inv_floating_flag = 1;
				_inv_do_float(global_floating_item_ptr);
			}

		}
		// 4/16/2014 Addition -----------------------------------------------------
					
		else if ( event_type == EVENT_RIGHTCLICK ) // mouse right button event
		{
			if (clicked_slot->item != NULL)
			{
				if (on_click_callback_function_ptr) 
				on_click_callback_function_ptr(INV_ITEM_RIGHT_CLICK,clicked_slot->bag_id,clicked_slot->id,clicked_slot->item->id,0);
			}
		}
		// -------------------------------------------------------------------------
	}
	else
	{
		if ((clicked_slot->group_id == 0) || (clicked_slot->group_id == global_floating_item_ptr->item->group_id)) // Test to make sure that item can be placed in the slot
		{		
			if (clicked_slot->item == NULL) // player is putting an item into an empty inventory slot
			{
				reset(sword_panel, SHOW);
				reset(mace_panel, SHOW);
				reset(gold_panel, SHOW);
				
				// optionally callback with action, bag_id, slot_id, item_id
				if (on_click_callback_function_ptr) on_click_callback_function_ptr(INV_ITEM_PLACED,clicked_slot->bag_id,clicked_slot->id,global_floating_item_ptr->item->id,0);
							
				// Place item in slot
				clicked_slot->item = global_floating_item_ptr->item;	
				clicked_panel->bmap = bmap_create(global_floating_item_ptr->item->inventory_icon);
				global_floating_item_ptr->item = NULL;		
							
				// End float
				pan_remove(global_floating_item_ptr->floating_item_panel);
				inv_floating_flag = 0;	
			}		
			else // player is swapping the floating item for the one in the inventory
			{
				if(str_cmp(clicked_slot->item->floating_icon, "steel_sword.pcx"))
				{
					reset(mace_panel, SHOW);
					reset(gold_panel, SHOW);
					set(sword_panel, SHOW);	
				}	
				else if(str_cmp(clicked_slot->item->floating_icon, "mace.pcx"))
				{
					reset(sword_panel, SHOW);
					reset(gold_panel, SHOW);
					set(mace_panel, SHOW);	
				}			
				else if(str_cmp(clicked_slot->item->floating_icon, "gold.pcx"))
				{
					reset(sword_panel, SHOW);
					reset(mace_panel, SHOW);
					set(gold_panel, SHOW);	
				}						
						
				// optionally callback with action, bag_id, slot_id, item_id
				if (on_click_callback_function_ptr) on_click_callback_function_ptr(INV_ITEM_SWAPPED,clicked_slot->bag_id,clicked_slot->id,global_floating_item_ptr->item->id,clicked_slot->item->id);
							
							
				// Backup the information of the clicked on slot
				Item* clicked_slot_item_pointer = clicked_slot->item;
				STRING* clicked_slot_inventory_icon = str_create(clicked_slot->item->inventory_icon);
							
				// Set the slot to the floating item
				clicked_slot->item = global_floating_item_ptr->item;
				clicked_panel->bmap = bmap_create(global_floating_item_ptr->item->inventory_icon);
							
				// Set the floating item to the slot
				global_floating_item_ptr->item = clicked_slot_item_pointer;
				global_floating_item_ptr->floating_item_panel->bmap = bmap_create(clicked_slot_inventory_icon);
							
			}
		}
	}
}

...


When I run main.c , add gold to the inventory bag, and click on the small gold coins image in the inventory bag, this is the error pop-up window I get:

Code:
Malfunction W1501
Empty pointer in slotOnClick
OK               Cancel


After I click OK on the pop-up window, I see the large image of gold coins show up on the right side of the screen, with the text "Gold: " underneath it, but no value next to "Gold: ".

If I comment out the:
pan_setstring(gold_panel,0,598,400,gold_txt_font,gold_amnt_txt);
in slotOnClick() in inventory.c , I do not get the error pop-up window. Just the large image of gold coins shows up on the right side of the screen, with the text "Gold: " underneath it, with no value next to "Gold: ".

Does anyone know why the:
pan_setstring(gold_panel,0,598,400,gold_txt_font,gold_amnt_txt);
in inventory.c is giving an empty pointer?

Last edited by Ruben; 05/31/14 16:47.