How to make an array game_save friendly?

Posted By: paracharlie

How to make an array game_save friendly? - 10/09/12 13:22

I have multiple container arrays that I want to make game_save friendly. How do I do that?
e.g.
var item_id[500];
var item_name[500];
I know with a struct you set it to memory and then use add_struct but I don't know how to do an array.
Help please.
Posted By: WretchedSid

Re: How to make an array game_save friendly? - 10/10/12 01:55

You should be able to use add_struct without problem... It simply saves the memory blob and doesn't care how the underlying data looks like.
Posted By: paracharlie

Re: How to make an array game_save friendly? - 10/10/12 03:49

Ok here is what I have. Let me know if you think I am on the right course. My complete code compiles without error but the problem is that I have so many containers. Do I need to write out a save function for each array?

Code:
// container variable arrays
var slot_owner[500];									// if slot_owner[index] > 0, the slot is being used by something
var slot_origin[500];								// original slot number in case new slot is full, item will return to origin
var item_id[500];										// id number of the slot item; if 0, no item in slot
var bmp_icon_x[500];									// x location of the upper left pixel of the bmap icon on item sheet
var bmp_icon_y[500];									// y location of the upper left pixel of the bmap icon on item sheet
var bmp_icon_width[500];
var bmp_icon_height[500];
var name_index[500];									// name lookup index
var file_index[500];									// mdl file lookup index
var synergy_id[500];									// item has synergy with item number (item_id)
var synergy_usecode[500];							// item synergy use code, looks up the action to be taken
var equip_manager[500];                      // equip manager is used to determine what slot item belongs in, such as weapons and armor, otherwise preventing action


function save_slot_owner()
{	
  
	slot_owner = sys_malloc(sizeof(slot_owner));
	memset(slot_owner,0,sizeof(slot_owner));	
	add_struct(slot_owner,sizeof(slot_owner));
	return slot_owner;
}



I have plans to release this complete inventory module to the community. Just want to make sure it's complete as possible.
Posted By: WretchedSid

Re: How to make an array game_save friendly? - 10/10/12 04:13

Why do you allocate memory for an array that is already backed by enough memory? And if you want to do it in one line, put your arrays in a struct, create a static instance and save it via add_struct.
Posted By: paracharlie

Re: How to make an array game_save friendly? - 10/10/12 04:38

I don't know why lol. Arrays have always confused the hell out of me.
Posted By: paracharlie

Re: How to make an array game_save friendly? - 10/10/12 05:50

So I get a syntax error at SLOTS; I don't understand what I'm doing wrong. Can you help?

Code:
typedef struct {

	var slot_owner[500];							// if slot_owner[index] > 0, the slot is being used by something
	var slot_origin[500];						// original slot number in case new slot is full, item will return to origin
	var item_id[500];								// id number of the slot item; if 0, no item in slot
	var bmp_icon_x[500];							// x location of the upper left pixel of the bmap icon on item sheet
	var bmp_icon_y[500];							// y location of the upper left pixel of the bmap icon on item sheet
	var bmp_icon_width[500];
	var bmp_icon_height[500];
	var name_index[500];							// name lookup index
	var file_index[500];							// mdl file lookup index
	var synergy_id[500];							// item has synergy with item number (item_id)
	var synergy_usecode[500];					// item synergy use code, looks up the action to be taken
	var equip_manager[500];                // equip manager is used to determine what slot item belongs in, such as weapons and armor, otherwise preventing action

} SLOTS;

SLOTS* container;


function save_containers()
{			
	add_struct(container,sizeof(SLOTS));	
}

Posted By: paracharlie

Re: How to make an array game_save friendly? - 10/10/12 22:49

Ok so I found out that you don't have to do any of this. Everything saves as is with the exception of saving some runtime objects and thats it. So easy I made it difficult.
© 2024 lite-C Forums