Basically, this is what I am trying to do. I am trying to create an inventory bag for my player, so that my player can store items, and use them. Inventory.c is a public domain program coded by somebody else to help me do this.

I can create multiple slots in my inventory bag to put items into. However, I am trying to make one special slot in the inventory bag that only accepts weapon items. Also, if you click and drag a certain weapon image into this special slot, it would arm the player with the weapon that is placed into this slot. So if a picture of a sword is in this special slot, then the player will be holding a sword in her/his hand. If a picture of a mace is in this special slot, then the player will be holding a mace in her his hand. If there is no image placed into this special slot, then the player is not armed with anything, etc.

This is the code in the main function of my main program (separate from inventory.c ) to try and make this happen:

Code:
// OrcStronghold.c Program

...

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");
   bag = inv_create_bag(1,"leather_seam.pcx");  // <---- added this line
   
   // ACTIVE ITEM SLOT
   
   active_weapon_slot = inv_add_slot_to_bag(bag, 0, 1, "leather_texture.pcx", 
      9, 60); // 3rd value (group_id) = 1.  Only equipment items with group_id 
              // = 1 can be placed into this slot.

   // 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);
	
   // SECOND ROW OF INVENTORY BAG
	
   inv_add_slot_to_bag(bag,5,0,"leather_texture.pcx",9,214);
   inv_add_slot_to_bag(bag,6,0,"leather_texture.pcx",70,214);
   inv_add_slot_to_bag(bag,7,0,"leather_texture.pcx",130,214);
   inv_add_slot_to_bag(bag,8,0,"leather_texture.pcx",190,214);
	
   // THIRD ROW OF INVENTORY BAG
	
   inv_add_slot_to_bag(bag,9,0,"leather_texture.pcx",9,278);
   inv_add_slot_to_bag(bag,10,0,"leather_texture.pcx",70,278);
   inv_add_slot_to_bag(bag,11,0,"leather_texture.pcx",130,278);
   inv_add_slot_to_bag(bag,12,0,"leather_texture.pcx",190,278);
	
   ...  
}


Code:
// Inventory.c program

...

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_create_bag(int bag_id, STRING* image_name)
{
   Bag* bag;
   bag = new(Bag);
	
   bag->image_name = image_name;
   bag->id = bag_id;
	
   // Initialize slot_count to 0
   bag->_slot_count = 0;
   bag->is_open = 0;
	
   // Add bag to global array for cleanup purposes

   inv_bags_array[inv_bag_count] = bag;
   inv_bag_count++;
	
   return bag;
}

...

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

...



So, the variable "floating_icon" is saved in the "inv_create_item" function inside the inventory.c program. When I use the inv_create_item in the "function main" inside the OrcStronghold.c program, in order to create a new item that can be placed inside the inventory bag, I am setting a string value to the third value in the inv_create_item function, which belongs to the "floating_icon" variable.

I try to set the "active weapon" slot instance of inv_create_item equal to a variable called "active_weapon_slot", and this is done in the "function main", inside the OrcStronghold.c program.

I then create a separate function from the "function main" inside the OrcStronghold.c program called "active_weapon_slot" function. In this function, I try to compare the floating_point string value in the "active weapon" slot to whether it equals "steel_sword.pcx". If it does, then I try to create a sword entity to be placed in the player's hand using the ent_create function, and an attach_weapon function that snaps the weapon (saved into its own separate .mdl file from the player) into the player's hand.

When I try and compile the OrcStronghold.c program, I get this error:

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

***********************

How can I take the floating_icon string value that is passed to the "inv_create_item" function, and compare it to the string value "steel_sword.pcx" (which is the name of the image being placed in the "active weapon" slot; and if they are equal, arming the player with a sword. If they are not equal (meaning the string value in the floating_icon variable is not equal to the string "steel_sword.pcx", then a sword will not be armed in the hand of the player. How can I access that floating_icon value, that is stored in the inv_create_item function in inventory.c ?

P.S. Is this issue beyond the "Gamestudio Basics" forum? Should I post this in a more advanced thread?

Last edited by Ruben; 12/27/13 05:38.