Gamestudio Links
Zorro Links
Newest Posts
Stooq now requires an API key
by k_ivan. 06/10/26 14:39
Z9 getting Error 058
by k_ivan. 06/10/26 14:38
ZorroGPT
by TipmyPip. 06/10/26 13:07
Z12 live performance
by alx. 06/09/26 20:42
Lapsa's very own thread
by Lapsa. 06/08/26 22:41
Zorro 3.01 recoded MMI function issue
by TipmyPip. 06/04/26 05:44
SGT_FW
by Aku_Aku. 05/31/26 11:05
Issues resuming trades on Demo account
by Martin_HH. 05/22/26 13:31
AUM Magazine
Latest Screens
Dorifto samurai
Shadow 2
Rocker`s Revenge
Stug 3 Stormartillery
Who's Online Now
5 registered members (alx, TipmyPip, AndrewAMD, Quad, 1 invisible), 3,180 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Seraphinang, Koti, curry, DeepxKalsi, Samed
19219 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
how to save the structures with add_struct ? #340580
09/05/10 20:06
09/05/10 20:06
Joined: May 2008
Posts: 257
D
djfeeler Offline OP
Member
djfeeler  Offline OP
Member
D

Joined: May 2008
Posts: 257
hello,

I would like to know how to register structures with add_struct ?
With an example please laugh

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 Offline
Expert
Helghast  Offline
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:

Quote:

"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)
Code:
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 laugh

regards,


Formerly known as dennis_fantasy
Portfolio - http://www.designorhea.com/
Project - http://randomchance.cherrygames.org/
Re: how to save the structures with add_struct ? [Re: Helghast] #340584
09/05/10 20:43
09/05/10 20:43
Joined: May 2008
Posts: 257
D
djfeeler Offline OP
Member
djfeeler  Offline OP
Member
D

Joined: May 2008
Posts: 257
Thanks for your response ^^

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
D
djfeeler Offline OP
Member
djfeeler  Offline OP
Member
D

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 ^^

Code:
//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 Offline
Expert
Helghast  Offline
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:
Code:
//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();
}




Formerly known as dennis_fantasy
Portfolio - http://www.designorhea.com/
Project - http://randomchance.cherrygames.org/
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
D
djfeeler Offline OP
Member
djfeeler  Offline OP
Member
D

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 Offline
Expert
Helghast  Offline
Expert

Joined: Jan 2004
Posts: 3,023
The Netherlands
Originally Posted By: djfeeler
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:

Code:
//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 laugh
regards,


Formerly known as dennis_fantasy
Portfolio - http://www.designorhea.com/
Project - http://randomchance.cherrygames.org/
Re: how to save the structures with add_struct ? [Re: Helghast] #396003
03/01/12 11:51
03/01/12 11:51
Joined: Jul 2001
Posts: 6,904
H
HeelX Offline
Senior Expert
HeelX  Offline
Senior Expert
H

Joined: Jul 2001
Posts: 6,904
This post from Helghast was particularily helpful to me, because I was struggling with game_save/game_load and structs and now everything works very fine for me. Thank you very much!


Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1