|
How to make an array game_save friendly?
#408927
10/09/12 13:22
10/09/12 13:22
|
Joined: Mar 2009
Posts: 146 USA
paracharlie
OP
Member
|
OP
Member
Joined: Mar 2009
Posts: 146
USA
|
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.
A8 Commercial
|
|
|
Re: How to make an array game_save friendly?
[Re: paracharlie]
#408986
10/10/12 01:55
10/10/12 01:55
|
Joined: Apr 2007
Posts: 3,751 Canada
WretchedSid
Expert
|
Expert
Joined: Apr 2007
Posts: 3,751
Canada
|
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.
Shitlord by trade and passion. Graphics programmer at Laminar Research. I write blog posts at feresignum.com
|
|
|
Re: How to make an array game_save friendly?
[Re: WretchedSid]
#408988
10/10/12 03:49
10/10/12 03:49
|
Joined: Mar 2009
Posts: 146 USA
paracharlie
OP
Member
|
OP
Member
Joined: Mar 2009
Posts: 146
USA
|
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?
// 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.
Last edited by paracharlie; 10/10/12 03:51.
A8 Commercial
|
|
|
Re: How to make an array game_save friendly?
[Re: paracharlie]
#408989
10/10/12 04:13
10/10/12 04:13
|
Joined: Apr 2007
Posts: 3,751 Canada
WretchedSid
Expert
|
Expert
Joined: Apr 2007
Posts: 3,751
Canada
|
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.
Shitlord by trade and passion. Graphics programmer at Laminar Research. I write blog posts at feresignum.com
|
|
|
Re: How to make an array game_save friendly?
[Re: WretchedSid]
#408990
10/10/12 04:38
10/10/12 04:38
|
Joined: Mar 2009
Posts: 146 USA
paracharlie
OP
Member
|
OP
Member
Joined: Mar 2009
Posts: 146
USA
|
I don't know why lol. Arrays have always confused the hell out of me.
A8 Commercial
|
|
|
Re: How to make an array game_save friendly?
[Re: paracharlie]
#408992
10/10/12 05:50
10/10/12 05:50
|
Joined: Mar 2009
Posts: 146 USA
paracharlie
OP
Member
|
OP
Member
Joined: Mar 2009
Posts: 146
USA
|
So I get a syntax error at SLOTS; I don't understand what I'm doing wrong. Can you help?
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));
}
A8 Commercial
|
|
|
Re: How to make an array game_save friendly?
[Re: paracharlie]
#409064
10/10/12 22:49
10/10/12 22:49
|
Joined: Mar 2009
Posts: 146 USA
paracharlie
OP
Member
|
OP
Member
Joined: Mar 2009
Posts: 146
USA
|
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.
A8 Commercial
|
|
|
|