|
|
|
|
|
|
|
|
|
|
|
|
SGT_FW
by Aku_Aku. 05/31/26 11:05
|
|
|
|
|
5 registered members (alx, TipmyPip, AndrewAMD, Quad, 1 invisible),
3,180
guests, and 3
spiders. |
|
Key:
Admin,
Global Mod,
Mod
|
|
|
how to save the structures with add_struct ?
#340580
09/05/10 20:06
09/05/10 20:06
|
Joined: May 2008
Posts: 257
djfeeler
OP
Member
|
OP
Member
Joined: May 2008
Posts: 257
|
hello, I would like to know how to register structures with add_struct ? With an example please djfeeler
|
|
|
Re: how to save the structures with add_struct ?
[Re: djfeeler]
#340581
09/05/10 20:13
09/05/10 20:13
|
Joined: Jan 2004
Posts: 3,023 The Netherlands
Helghast
Expert
|
Expert
Joined: Jan 2004
Posts: 3,023
The Netherlands
|
Hey djfeeler, I had EXACTLY the same question last week, and asked EvilSOB this. Here's his reply to me: "game_save" :: Ive never used it, as I prefer to code my own save-game systems, but SV_STRUCT is pretty self-explanitory to me, in that it will include all of the "add_struct"ed objects into the ONE save-game file. "add_struct(void* data,long size)" :: the "void* data" is the address of the individual memory block lives at, and the "size" is how many bytes long it is. FI: (untested example)
typedef struct NPC
{ ... } NPC;
NPC* new_NPC(...)
{
NPC* new = sys_malloc(sizeof(NPC)); //create new memory block
memset(new, 0, sizeof(NPC)); //fill it with zeros
//
add_struct(new, sizeof(NPC)); //add it to game-save table
//add_struct(new, (long)sizeof(NPC)); //MAY need this syntax
...
return(new);
}
I hope this helps, it has helped me though  regards,
|
|
|
Re: how to save the structures with add_struct ?
[Re: djfeeler]
#340650
09/06/10 10:32
09/06/10 10:32
|
Joined: May 2008
Posts: 257
djfeeler
OP
Member
|
OP
Member
Joined: May 2008
Posts: 257
|
hello ! I tried the example but I have a problem when I backup it works but when I close the window and I want to load the backup it says can not find the file save1.SAV. tell me where I made a mistake. Thanks in advance ^^
//test add_struct
///////////////////////////////
#include <acknex.h>
#include <default.c>
///////////////////////////////
typedef struct PERSO{
int age;
char* name;
char* nickname;
} PERSO;
PERSO* Person = { age = 0; name = ""; nickname = "";}
PERSO* new_person()
{
PERSO* new = sys_malloc(sizeof(PERSO));
memset(new,0,sizeof(PERSO));
add_struct(new,sizeof(PERSO));
return new;
}
PANEL* panDisplay =
{
digits(35, 20, "VG_second = %0.f", *, 1, VG_second);
digits(35, 30, "VG_minute = %0.f", *, 1, VG_minute);
digits(35, 40, "VG_hours = %0.f", *, 1,VG_hours);
digits(35, 50, "VG_days = %0.f", *, 1,VG_days);
digits(35, 60, "VG_months = %0.f", *, 1,VG_months);
digits(35, 70, "VG_years = %0.f", *, 1,VG_years);
flags = SHOW;
}
TEXT* test =
{
pos_x = 10;
pos_y = 400;
flags= SHOW;
}
function save()
{
new_person();
if(game_save("save",1,SV_STRUCT) <= 0)
{
error("save no found");
}else{
error("save found");
}
}
function load()
{
if(game_load("save",1) <= 0)
{
error("no load");
sys_exit(NULL);
}else{
error("chargé");
}
}
function quit()
{
sys_exit(NULL);
}
function send()
{
Person.nickname = "Toto";
}
function d()
{
str_cpy((test.pstring)[0],_str(Person.nickname));
}
function main()
{
video_mode = 7;
video_depth = 32;
video_screen = 2;
level_load(NULL);
on_f1 = d;
on_f2 = send ;
on_f3 = save;
on_f4 = load;
on_esc = quit;
on_close = quit;
}
|
|
|
Re: how to save the structures with add_struct ?
[Re: djfeeler]
#340655
09/06/10 11:18
09/06/10 11:18
|
Joined: Jan 2004
Posts: 3,023 The Netherlands
Helghast
Expert
|
Expert
Joined: Jan 2004
Posts: 3,023
The Netherlands
|
Because the same stuff needs to be in memory when saved and when being loaded. So Person needs to have been created, before loading. I changed your test, and this worked here:
//test add_struct
///////////////////////////////
#include <acknex.h>
#include <default.c>
///////////////////////////////
typedef struct PERSO{
int age;
char* name;
char* nickname;
} PERSO;
PERSO* Person;
PERSO* new_person()
{
PERSO* new = sys_malloc(sizeof(PERSO));
memset(new,0,sizeof(PERSO));
new->nickname = "Toto_2"; // test name
add_struct(new,sizeof(PERSO));
return new;
}
PANEL* panDisplay =
{
digits(35, 20, "VG_second = %0.f", *, 1, VG_second);
digits(35, 30, "VG_minute = %0.f", *, 1, VG_minute);
digits(35, 40, "VG_hours = %0.f", *, 1,VG_hours);
digits(35, 50, "VG_days = %0.f", *, 1,VG_days);
digits(35, 60, "VG_months = %0.f", *, 1,VG_months);
digits(35, 70, "VG_years = %0.f", *, 1,VG_years);
flags = SHOW;
}
TEXT* test =
{
pos_x = 10;
pos_y = 400;
flags= SHOW;
}
function save()
{
if(game_save("save",1,SV_STRUCT) <= 0)
{
error("save no found");
}else{
error("save found");
}
}
function load()
{
if(game_load("save",1) <= 0)
{
error("no load");
sys_exit(NULL);
}else{
error("chargé");
}
}
function quit()
{
sys_exit(NULL);
}
function send()
{
Person.nickname = "Toto";
}
function d()
{
str_cpy((test.pstring)[0], _str(Person.nickname));
}
function main()
{
video_mode = 7;
video_depth = 32;
video_screen = 2;
level_load(NULL);
on_f1 = d;
on_f2 = send ;
on_f3 = save;
on_f4 = load;
on_esc = quit;
on_close = quit;
Person = new_person();
}
|
|
|
Re: how to save the structures with add_struct ?
[Re: Helghast]
#340679
09/06/10 15:46
09/06/10 15:46
|
Joined: May 2008
Posts: 257
djfeeler
OP
Member
|
OP
Member
Joined: May 2008
Posts: 257
|
Thanks for your help ^^ I would like I could register a value and I would provide to show it when I run a saving? Because I make f2 to put toto in the structure and I make f1 so that toto display but when I close the window and I run the saving there is toto_2 not toto when I make f1. How to make ?
Last edited by djfeeler; 09/06/10 16:00.
|
|
|
Re: how to save the structures with add_struct ?
[Re: djfeeler]
#340712
09/07/10 07:54
09/07/10 07:54
|
Joined: Jan 2004
Posts: 3,023 The Netherlands
Helghast
Expert
|
Expert
Joined: Jan 2004
Posts: 3,023
The Netherlands
|
Thanks for your help ^^ I would like I could register a value and I would provide to show it when I run a saving? Because I make f2 to put toto in the structure and I make f1 so that toto display but when I close the window and I run the saving there is toto_2 not toto when I make f1. How to make ? Yes, this already works, but the string does not update untill you tell it to update... Try it like this instead then:
//test add_struct
///////////////////////////////
#include <acknex.h>
#include <default.c>
///////////////////////////////
typedef struct PERSO{
int age;
char* name;
char* nickname;
} PERSO;
PERSO* Person;
PERSO* new_person()
{
PERSO* new = sys_malloc(sizeof(PERSO));
memset(new,0,sizeof(PERSO));
new->nickname = "Toto_2"; // test name
add_struct(new,sizeof(PERSO));
return new;
}
TEXT* test =
{
pos_x = 10;
pos_y = 10;
flags= SHOW;
}
function save()
{
if(game_save("save",1,SV_STRUCT) <= 0)
{
error("save no found");
}else{
error("save found");
}
}
function load()
{
if(game_load("save",1) <= 0)
{
error("no load");
sys_exit(NULL);
}else{
error("chargé");
}
}
function quit()
{
sys_exit(NULL);
}
function send()
{
Person.nickname = "Toto";
}
function main()
{
video_mode = 7;
video_depth = 32;
video_screen = 2;
level_load(NULL);
on_f2 = send ;
on_f3 = save;
on_f4 = load;
on_esc = quit;
on_close = quit;
Person = new_person();
while(1) {
str_cpy((test.pstring)[0], _str(Person.nickname));
wait(1);
}
}
Tested and Works  regards,
|
|
|
|