I will attempt to explain this in simpler terms again. It seems very hard for me to communicate this problem to people. If people on this thread cannot understand my problem after trying to explain it here, I will have no choice but to take this to a different thread beyond "Starting with Gamestudio". So here it goes:
Code:
Script:     OrcStronghold.c
Functions:  main()
            active_weapon_slot()
Actions:    #include "inventory.c" in beginning of script.
            In Main():  Uses inv_create_item() function 
               (stored in inventory.c) to process .pcx images 
               of equipment items, like sword, mace, gold, 
               apple, etc., so that their .pcx images can be 
               used in the inventory bag GUI as equipment 
               item images that can be placed in slots, 
               representing equipment items in the player's 
               inventory.
            In Main():  Uses inv_add_slot_to_bag() function 
               (stored in inventory.c) to add slots in the 
               inventory bag.  The programmer can create as 
               many slots as she/he wants for the inventory 
               bag.  The function name "active_weapon_slot" 
               is set equal to the inv_add_slot_to_bag 
               instance that is supposed to represent the 
               slot used for arming the player with a weapon.
            In active_weapon_slot():  Tries to compare the 
               variable string stored in floating_icon 
               variable (which is an argument in 
               inv_create_item() function, stored in 
               inventory.c) against the string 
               "steel_sword.pcx".  The file name 
               "steel_sword.pcx" is an argument passed to the 
               inv_create_item() function from 
               OrcStronghold.c main() function, to allow an 
               image of a sword representing a sword in 
               inventory, that can be used among the slots in 
               the inventory bag.

Script:     inventory.c
Functions:  inv_add_slot_to_bag(Bag* bag, int slot_id, int 
               group_id, STRING* default_image, int 
               rel_x_pos, int rel_y_pos)
            inv_create_item(item_id, group_id, STRING* 
               floating_icon, STRING* inventory_icon)
Actions:    inv_add_slot_to_bag() function creates a slot for 
               a custom made inventory bag for the player.
            inv_create_item() function allow a .pcx image to 
               be used in the inventory bag, representing an 
               equipment item.



Code:

Code:
// OrcStronghold.c

#include "inventory.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);
   }
}

...

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");
   
   ... 
   
   // START OF INVENTORY BAG
 
   // ACTIVE ITEM SLOT
   
   active_weapon_slot = inv_add_slot_to_bag(bag, 0, 1, "leather_texture.pcx", 
      9, 60); 

   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);
	
   ...
   
}


Code:
// 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;		
}

...

function inv_add_slot_to_bag(Bag* bag, int slot_id, int group_id, STRING* default_image, int rel_x_pos, int rel_y_pos)
{
   Slot* new_slot;
   new_slot = new(Slot);

   // Set the position for the new slot
	
   new_slot->rel_x_pos = rel_x_pos;
   new_slot->rel_y_pos = rel_y_pos;	
   new_slot->background_image = default_image;
   new_slot->item = NULL;
   new_slot->id = slot_id;
   new_slot->group_id = group_id;
   new_slot->bag_id = bag->id;	
		
   bag->slots[bag->_slot_count] = new_slot;
	
   bag->_slot_count += 1;	
}

...



How can I get OrcStronghold.c to access the floating_icon value (stored in inv_create_item() function, which is stored in inventory.c script) for the "active weapon" slot, using the active_weapon_slot() function in OrcStronghold.c ?

I think this is about the simplest way that I can try to explain this.


Last edited by Ruben; 12/29/13 01:39.