Is there a way that I can access a variable value in one program from a second different program?
For example, lets say I have two different programs: mainProgram.c and inventory.c . If the mainProgram.c program file needs to determine what a value is for a variable saved in a different program file, like inventory.c , in order to execute some process in mainProgram.c , how would I call on that inventory.c variable in the gameProgram.c ?
So, if the value in inventory.c that gameProgram.c needs is saved in a variable called "slot_id", and the "slot_id" variable is stored in a function inside of inventory.c , how would I call on the value stored in slot_id from the main function in gameProgram.c ?
For example, here is the logic:
gameProgram.c : I need the value of the variable "slot_id" , that is stored in inventory.c , in order to initiate an action.
inventory.c : passes value of "slot_id" back to gameProgram.c .
gameProgram.c : Takes "slot_id" value passed from inventory.c , and depending on its value, takes a certain action.
**************
Does anyone know how I can call on the "slot_id" variable stored in the inventory.c program, using the gameProgram.c program, to make this happen?
Here is the actual code in inventory.c that has "slot_id" stored in it:
/*
Arguments:
bag - The bag that you created above.
slot_id - Any value that you like. It's only used for callbacks, which I'll cover later.
group_id - Only items having this value may be added to the slot.
default_image - An image showing an empty slot.
rel_x_pos - x position relative to the top left of the bag's image
rel_y_pos - y position relative to the top left of the bag's image
*/
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;
}