Originally Posted By: JustSid
As far as the current translation unit is concerned: Yes. The include is replaced with the contents of the other script by the pre-processor.

By the way at whoever suggested global variables: Shame on you! Polluting the global namespace with variables is evil!

Okay. Let say I create a function named active_weapon_slot() in OrcStronghold.c , as shown below:

Code:
function active_weapon_slot()
{
	if(str_cmp(active_weapon_slot.floating_icon, "steel_sword.pcx")) 
     {
          active_sword = ent_create ("sword.mdl", my.x, attach_weapon);
     }
     else
     {
          ent_remove(active_sword);
     }
}



Now lets say I use the inv_create_item() function (taken from inventory.c) in the main function of OrcStronghold.c , as shown below:

Code:
// Inside OrcStronghold.c

function main()
{
   ...

item_shield = inv_create_item(1,0,"shield.pcx","shield.pcx");
   item_apple = inv_create_item(1,0,"apple.pcx","apple.pcx");
   item_sword = inv_create_item(0,1,"steel_sword.pcx","steel_sword.pcx");
   item_mace = inv_create_item(0,1,"mace.pcx","mace.pcx");
   item_gold = inv_create_item(1,0,"gold_coins.pcx","gold_coins.pcx");



In this last piece of code, I just created five items (.pcx images of equipment items) to be used to populate the slots of the inventory bag. I can drag these images among the different slots of the inventory bag, if I chose to.

However, I still have not created the slots themselves for the inventory bag, in order to put items into. I now perform that action here within the same OrcStrongholdMain.c main function:

Code:
...

   // ACTIVE ITEM SLOT
   
   active_weapon_slot = inv_add_slot_to_bag(bag, 0, 1, 
      "leather_texture.pcx", 9, 60); // 3RD VALUE "1" (which
      //    belongs to group_id variable), ONLY EQUIPMENT 
      //    ITEMS WITH group_id value = 1 CAN BE INSERTED 
      //    INTO THIS SLOT.  ONLY WEAPON ITEMS ARE ASSIGNED
      //    group_id = 1 .  ALL NON-WEAPON ITEMS ARE ASSIGNED 
      //    group_id = 0 , SO ONLY WEAPON ITEMS CAN BE 
      //    INSERTED INTO THIS SLOT.  I SET 
      //    active_weapon_slot EQUAL TO THIS SLOT.  
      //    "active_weapon_slot()" is a function in 
      //    OrcStronghold.c , outside the main function.

   // EACH ROW OF INVENTORY BAG IS SPACED OUT BY 64 HEIGHT
   // FIRST ROW OF INVENTORY BAG

   inv_add_slot_to_bag(bag,1,0,"leather_texture.pcx",9,150);
   inv_add_slot_to_bag(bag,2,0,"leather_texture.pcx",70,150);
   inv_add_slot_to_bag(bag,3,0,"leather_texture.pcx",130,150);
   inv_add_slot_to_bag(bag,4,0,"leather_texture.pcx",190,150);
      // NOTICE THAT THE THIRD VALUE OF THESE SLOTS 
      //    ARE ASSIGNED THE VALUE 0 (zero).  THE REASON FOR 
      //    THIS IS BECAUSE THESE ITEMS ARE NOT WEAPONS, 
      //    THEREFORE, I ASSIGN THEIR group_id VARIABLE TO 0.

   ...



So in the last code above, I created an inventory bag with five slots. The top slot is reserved as the "active weapon" slot. This slot checks to see what the group_id is of an equipment item (.pcx image). If the group_id of the image is 1, that image can be placed in that slot. If the group_id of the equipment item is not 1 (like zero), then the equipment item cannot be placed in this slot.

I also created four other slots underneath the "active weapon" slot. These four slots can accept any items, weapon or non-weapon. That is because their group_id value (3rd value) is equal to 0.

Now, I also created the function active_weapon_slot() in OrcStronghold.c , before the main function. This function is supposed to represent the "active weapon" slot in the inventory bag. Whatever .pcx image of a weapon is placed in this "active weapon" slot inside the inventory bag, that is the weapon that the player should be armed with, in the player's hand, ready to use.

This is the code of function active_weapon_slot() that is trying to accomplish this:

Code:
// Inside OrcStronghold.c

function active_weapon_slot()
{
	if(str_cmp(active_weapon_slot.floating_icon, "steel_sword.pcx")) 
     {
          active_sword = ent_create ("sword.mdl", my.x, attach_weapon);
     }
     else
     {
          ent_remove(active_sword);
     }
}



The function above is comparing the floating_icon variable's string, to the string "steel_sword.pcx". The variable floating_icon comes from inventory.c , and is used in the function inv_create_item , that we used earlier to create equipment item .pcx images, to be used to populate slots in the inventory bag. The function inv_create_item() is shown here:

Code:
// Inside inventory.c

...

function inv_create_item(item_id, group_id, STRING* floating_icon, STRING* inventory_icon)
{
	// Create item and assign images
	
	Item* item = new(Item);
	item->floating_icon = floating_icon;		
	item->inventory_icon = inventory_icon;
	item->id = item_id;
	item->group_id = group_id;
	
	// Add item to global array for cleanup purposes

	inv_items_array[inv_item_count] = item;
	inv_item_count++;
	
	return item;
}



As you see in the code above, floating_icon is the third variable taken as an argument in the inv_create_item function. However, if you notice in the code before last, I am trying to access the string value of that floating_icon variable (that is used as an argument in inv_create_item() inside inventory.c script) from the OrcStronghold.c script , in order to compare it with the string value "steel_sword.pcx". "steel_sword.pcx" is the file name of the sword image that is used to populate the inventory bag slots. If floating_icon string value of the active weapon slot equals "steel_sword.pcx", I want to attach a .mdl sword model to the player's hand, which is shown in the code above last.

When I compile this, this is my error:

Compiling ORCSTRONGHOLD.C - [Esc] to abort......
Error in 'line 180:
'floating_icon' : is not a member of 'BOOL'
< if(str_cmp(active_weapon_slot.floating_icon, "steel_sword.pcx"))
.. 0.108 sec
Error compiling ORCSTRONGHOLD.C
Error E355: Startup failure - any key to abort

Even though I #include inventory.c at the beginning of OrcStronghold.c , either I am using the function active_weapon_slot incorrectly, or I am not able to access the floating_icon value in the active weapon slot for some reason.

Do you know what I am doing wrong?

Last edited by Ruben; 12/28/13 20:34.