Gamestudio Links
Zorro Links
Newest Posts
Newbie Questions
by AndrewAMD. 12/05/23 10:56
Zorro Trader GPT
by TipmyPip. 12/04/23 11:34
Square root rule
by Smallz. 12/02/23 09:15
RTest not found error
by TipmyPip. 12/01/23 21:43
neural function for Python to [Train]
by TipmyPip. 12/01/23 14:47
Xor Memory Problem.
by TipmyPip. 11/28/23 14:23
Training with command line parameters
by TipmyPip. 11/26/23 08:42
Combine USD & BTC Pairs In Asset Loop
by TipmyPip. 11/26/23 08:30
AUM Magazine
Latest Screens
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Who's Online Now
6 registered members (AndrewAMD, alibaba, fairtrader, ozgur, TipmyPip, Quad), 622 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
fairtrader, hus, Vurtis, Harry5, KelvinC
19019 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Saving/Loading Structs #111471
02/09/07 14:49
02/09/07 14:49
Joined: Jul 2006
Posts: 783
London, UK
sheefo Offline OP
User
sheefo  Offline OP
User

Joined: Jul 2006
Posts: 783
London, UK
Another question about structs

Is it possible to save/load a struct to/from a file in Lite-C? I just want to dump a struct in a file and load it later on, like you can do in C++.
I don't know how because GameDev is down, so if it is possible can someone show me code...?

I would really appreciate it.

Re: Saving/Loading Structs [Re: sheefo] #111472
02/09/07 22:16
02/09/07 22:16
Joined: Jul 2006
Posts: 783
London, UK
sheefo Offline OP
User
sheefo  Offline OP
User

Joined: Jul 2006
Posts: 783
London, UK
OK, if I promise not to ask another question about structs, will that convince you to reply?

Re: Saving/Loading Structs [Re: sheefo] #111473
02/10/07 02:45
02/10/07 02:45
Joined: Jul 2000
Posts: 27,967
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,967
Frankfurt
file_save("struct.bin",&mystruct,sizeof(mystruct));

http://manual.conitec.net/afile_save.htm

Re: Saving/Loading Structs [Re: jcl] #111474
02/10/07 13:31
02/10/07 13:31
Joined: Jul 2006
Posts: 783
London, UK
sheefo Offline OP
User
sheefo  Offline OP
User

Joined: Jul 2006
Posts: 783
London, UK
Thank you. But how can I use this to save multiple structs to the same file, or an array containing struct pointers? When I save an array of structs it turns out as 0 bytes.

I need to know how to load the multiple structs from the file as well.

My idea is to have one struct called HEADER which holds the some data, then I wanted to fill the rest of the file with PLAYER struct I got to handle players in my RTS. They are stored in an array "PLAYER* players[8];".
I then wanted to, when loading, read the header and ensure that the attribute 'application_name' matches my constant 'APPLICATION_NAME', and the 'application_version' is below the constant 'APPLICATION_VERSION'. Then I can continue loading all player structs.

Can you help me with this?

Re: Saving/Loading Structs [Re: sheefo] #111475
02/10/07 16:23
02/10/07 16:23
Joined: Sep 2003
Posts: 9,859
F
FBL Offline
Senior Expert
FBL  Offline
Senior Expert
F

Joined: Sep 2003
Posts: 9,859
Pointers most likely will have to be reinitialized after loading, as the memory areas they point to might be different.

Maybe you can put all structs into a buffer first?
http://manual.conitec.net/aadd_buffer.htm
But I think it's only used for external files...


no idea...

Re: Saving/Loading Structs [Re: FBL] #111476
02/11/07 16:50
02/11/07 16:50
Joined: Jul 2000
Posts: 27,967
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,967
Frankfurt
Correct, saving struct pointers won't make much sense.

For saving struct content, you can put the structs in a "mother struct", like this

typedef struct MOTHER { CHILD1 child1; CHILD2 child2; ... } MOTHER;

where CHILD1, CHILD2 etc. are other structs, and then save the mother struct.

Two remarks:

- You can not save engine objects this way - you need game_save for that.
- You can also use game_save with SV_STRUCT for saving your structs.

Re: Saving/Loading Structs [Re: jcl] #111477
02/11/07 18:45
02/11/07 18:45
Joined: Jul 2006
Posts: 783
London, UK
sheefo Offline OP
User
sheefo  Offline OP
User

Joined: Jul 2006
Posts: 783
London, UK
I like the idea of using 'game_save'. So let me get this right:
- use 'add_struct' on all structs I want to save
- use 'game_save' using SV_STRUCT and all structs I added will be saved to a file

Thats all?

Re: Saving/Loading Structs [Re: sheefo] #111478
02/12/07 16:21
02/12/07 16:21
Joined: Jul 2000
Posts: 27,967
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,967
Frankfurt
Yes, that's the idea behind add_struct.

Re: Saving/Loading Structs [Re: jcl] #111479
02/12/07 17:24
02/12/07 17:24
Joined: Jul 2006
Posts: 783
London, UK
sheefo Offline OP
User
sheefo  Offline OP
User

Joined: Jul 2006
Posts: 783
London, UK
I ran into another problem now, 'game_save' doesn't work. I am sure it is a bug, I posted a topic in Bug Hunt http://www.coniserver.net/ubbthreads/sho...;vc=#Post728343


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

Gamestudio download | chip programmers | 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