I am using a main() script and an inventory.c script. I use the inventory.c script to provide an inventory bag for the player to bring up when the player taps the "i" key. I am trying to alter the inventory.c script code so that if I click on any item in the inventory bag (shown on the left side of the screen), a detailed description of that item shows up on the right side of the screen, such as a large image of that item, plus descriptive information underneath it such as weight, damage, value, and effects.

If the player has gold in its inventory bag, a small image of gold coins shows in one of the slots of the inventory bag. If the player clicks on the small gold coins image, I have it programmed so that a large image of gold coins shows up on the right side of the screen. I also want to display the amount of gold that the player has, underneath the large image of gold coins that shows up on the right side of the screen.

The variable "player_gold" is used and calculated in the main.c program. However, I would like to try and use the same player_gold variable in the inventory.c program as well. Is there a way that I can access the value stored in "player_gold" from the main.c script, to be used in the inventory.c script?

Here is my code so far:

Code:
// main.c

...

#include "inventory.c"

...

int player_gold;

...

function gldCn_event()
{
	if ((event_type == EVENT_CLICK) && (my.STATE == 1))
	{
		ent_remove(gldCn);

		inv_insert_item_into_bag(bag,item_gold);

		player_gold += 1;
		
		gldCn_picked_up = 1;
		  
		change_mouse_mode();

		my.STATE = 2;
	}
}

...

action gldCn_action()
{
	my.emask |= ENABLE_CLICK;
	my.event = gldCn_event;
	
	gldCn_picked_up = 0;
	
	//player_gold += 5;
	
	my.STATE = 1;
	
	while (1)
	{	
		if (!mouse_left && my.STATE == 2)
		{
			my.STATE = 1;
		}
		if (my.STATE == 1)
		{
			if (c_scan(my.x,my.pan,vector(360,0,150),SCAN_ENTS | SCAN_FLAG2 | IGNORE_ME))
			{
				mouse_map = cursor_green_pcx;
			}
			else
			{
				mouse_map = cursor_pcx;
			}
		}

		wait(1);
	}
}

...

PANEL* pDisplay =
{
        ...

	digits (180, 190, 5, *, 1, plyr_gold);

        ...

	flags = SHOW;
}

...

function show_player_gold()
{
	plyr_gold = player_gold;
}

...

action player()
{
        ...

	while(my.x)
	{
		...

		show_player_gold();

                ...
        }
}

...

void goldCoin_present()
{
	if (gldCns_picked_up == 0)
	{
		gldCn = ent_create ( "gold_coin.mdl",  
                   vector(713,-1870,1709), gldCn_action);
		gldCn_scale();
	}
}

...

function gldCns_scale()
{
	gldCns.scale_x = 0.07; // MAIN LEVEL PLAYER SCALE
	gldCns.scale_y = 0.07;
	gldCns.scale_z = 0.07;
}

function gldCn_scale()
{
	gldCn.scale_x = 0.07; // MAIN LEVEL PLAYER SCALE
	gldCn.scale_y = 0.07;
	gldCn.scale_z = 0.07;
}

...

void goldCoin_present()
{
	if (gldCns_picked_up == 0)
	{
		gldCn = ent_create ( "gold_coin.mdl", vector(713,-1870,1709), gldCn_action);
		gldCn_scale();
	}
}

...

function main()
{
   ...

   player_gold = 0;

   ...

}


Code:
// inventory.c

...

BMAP* goldPanel = "Gold_Inv_Display.pcx";

...

TEXT* gold_amt_text =
{
	pos_x = 560;
	pos_y = 400;
	
	string ("GOLD:  ");
}

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_amt_txt;
	
	gold_amt_txt = str_create("Gold:  ");
	
	pan_setstring(gold_panel,0,560,400,gold_txt_font,gold_amt_txt);
	pan_setdigits(gold_panel,0,500,400,"%2.f",gold_txt_font,1,player_gold);

        ...

}



If I tried putting this in inventory.c:

Code:
#include "main.c"



...I get weird errors. I do not get weird errors if I include this in main.c"

Code:
#include "inventory.c"



Is there a way that I can access the player_gold variable value from main.c, to be used in inventory.c , so that I can show the player's amount of gold under the large gold coins image on the right side of the screen that shows up when the player clicks on the small gold coins image in the inventory bag that shows up on the left side of the screen?




Last edited by Ruben; 05/31/14 10:00.