Page 1 of 1

Loading & Unloading levels/worlds

PostPosted: Sun May 19, 2013 5:27 pm
by DragonRift
My question is:
How you you handle loading & unloading Worlds/Levels in GE?

No one has really been able to answer this clearly.

Re: Loading & Unloading levels/worlds

PostPosted: Sun May 19, 2013 6:24 pm
by lcl
As most things, this can be done in multiple ways.
Here's some of them:

-separate .ged files exported as .dat files, loaded by using LoadGame();
-all levels in one .ged separated by activation regions for avoiding lag
-make a level editor for the game, make it to make the levels as files, which the game them reads and then generates the levels

As for building a level one usually uses tiles or clones (clones only when using exterior files for storing the level data). This goes for 2D platformer games, it really depends on what kind of game you are making.

In future, it would be easier to answer your questions if they were more specific, since things can always be done in many ways, but not all are efficient in all cases.

Re: Loading & Unloading levels/worlds

PostPosted: Sun May 19, 2013 7:26 pm
by DragonRift
lcl wrote:As most things, this can be done in multiple ways.
Here's some of them:

-separate .ged files exported as .dat files, loaded by using LoadGame();
-all levels in one .ged separated by activation regions for avoiding lag
-make a level editor for the game, make it to make the levels as files, which the game them reads and then generates the levels

As for building a level one usually uses tiles or clones (clones only when using exterior files for storing the level data). This goes for 2D platformer games, it really depends on what kind of game you are making.

In future, it would be easier to answer your questions if they were more specific, since things can always be done in many ways, but not all are efficient in all cases.


in my context, each level is a "world" on my game and players will be able to travel between worlds, but I will be selling additional worlds via DLC and players will be able to chose which worlds they want included in the game when they start a new game.

Re: Loading & Unloading levels/worlds

PostPosted: Sun May 19, 2013 10:58 pm
by knucklecrunchgames
This may or may not help,

On the main menu there is elect world, but one of them says DLC, the player clicks into that and the game loads this DLC menu saying select your DLC world you wanna play.
Hope it helps, BTW I agree for the DLC, I'm all over it

Re: Loading & Unloading levels/worlds

PostPosted: Mon May 20, 2013 1:01 am
by DragonRift
knucklecrunchgames wrote:This may or may not help,

On the main menu there is elect world, but one of them says DLC, the player clicks into that and the game loads this DLC menu saying select your DLC world you wanna play.
Hope it helps, BTW I agree for the DLC, I'm all over it


I don't see this anywhere.

Re: Loading & Unloading levels/worlds

PostPosted: Mon May 20, 2013 7:53 pm
by DragonRift
Ok, I now know how to Save/Load however the question now is:

Is there a way to share data between .dat files?

Re: Loading & Unloading levels/worlds

PostPosted: Mon May 20, 2013 7:56 pm
by skydereign
You do so by saving and loading variables to a file. As long as both dat files can read the file, they can pass data to each other.

Re: Loading & Unloading levels/worlds

PostPosted: Mon May 20, 2013 8:01 pm
by DragonRift
skydereign wrote:You do so by saving and loading variables to a file. As long as both dat files can read the file, they can pass data to each other.


Then this File can be easily Modified externally if I am not correct.

Re: Loading & Unloading levels/worlds

PostPosted: Mon May 20, 2013 8:06 pm
by skydereign
In a way yes. You don't have to store it in human readable form, as well as you can put in checksums to prevent tampering. But the file will need to exist, as that is the only way of passing data out of a game in gE.

Re: Loading & Unloading levels/worlds

PostPosted: Mon May 20, 2013 8:07 pm
by DragonRift
skydereign wrote:In a way yes. You don't have to store it in human readable form, as well as you can put in checksums to prevent tampering. But the file will need to exist, as that is the only way of passing data out of a game in gE.


I see in the script that there is fopen, etc, are these C based or GE based so I know where to do my research.

Edit: C++ Ref

fclose
Close file (function )

freopen
Reopen stream with different file or mode (function )

setbuf
Set stream buffer (function )

setvbuf
Change stream buffering (function )

tmpfile
Open a temporary file (function )

tmpnam
Generate temporary filename (function )

I am trying to understand how to store stuff like Variable Information to/from flat files. Would you guys be able to help explain this stuff in detail in reference to how GE handles this since I see that I am not the only one in the community asking about this stuff.

Re: Loading & Unloading levels/worlds

PostPosted: Mon May 20, 2013 8:12 pm
by skydereign
If you are using fopen you are dealing with FILE*, which is C. Alternatively, you could use saveVars/loadVars which are gE built in, that save variables using save groups.

Re: Loading & Unloading levels/worlds

PostPosted: Mon May 20, 2013 8:14 pm
by DragonRift
DragonRift wrote:I am trying to understand how to store stuff like Variable Information to/from flat files. Would you guys be able to help explain this stuff in detail in reference to how GE handles this since I see that I am not the only one in the community asking about this stuff.


Could you assist with this?

Re: Loading & Unloading levels/worlds

PostPosted: Mon May 20, 2013 8:19 pm
by skydereign
Okay, first off, gE uses C, so C++ functions won't work. Also, really there is nothing special about file io in gE, so tutorials for how to do it in C will work just fine in gE.
Code: Select all
http://www.cprogramming.com/tutorial/cfileio.html


The general idea for writing to a file is you open a file with fopen. You write into that file with fprintf, and you close that file with fclose. Reading from a file is very similar, you open the file with fopen (mode set to r this time). You use the reverse operation, in this case fscanf is the opposite of fprintf. And again close the file when you are done.

Re: Loading & Unloading levels/worlds

PostPosted: Mon May 20, 2013 8:30 pm
by DragonRift
skydereign wrote:Okay, first off, gE uses C, so C++ functions won't work. Also, really there is nothing special about file io in gE, so tutorials for how to do it in C will work just fine in gE.
Code: Select all
http://www.cprogramming.com/tutorial/cfileio.html


I think this is actually what I was looking for, because I am making a game where you are having to go in and out of different levels and are switching between side view and top view game modes. But the game needs to retain information between these state changes. I also wanted to have a local binary file database system for storing information like DLC Items unlocked in games. I realize a file can be hacked if someone really wanted to but most general users do not have the ability to do this.

And if hacking files became an issue then a person could enforce DRM but I would like to avoid taking that step.