Hello there,
I once read in the forum about Save [...] and more.
Now I no longer find the time, however, and want a topic about Save
do how to do best, is like the easiest.
Someone knows what?
As in saving data in your program ? There are many ways of doing it, all depending on what type of program you are writing...
The easiest is writing to an INI file, but data can be easily modified. The best way would be to store as binary data (possibly compressed).
I mean a checkpoint when you put a certain ranges has or what is stored and made you as you can go when you reboot.
So I think what would be the best way?
Would be best to save what you want as quickly as possible, so saving as data would be best, preferably storing as much information as possible in each byte - or perhaps using some compression system.
So, if you have a lot of data that is the same, you could use a RLE compression routine.
Have you a tutorial?
how do you mean?
I mean if you do what is saved from there. O_O
There are no tutorials as its really too specific. There are various topics around that discuss saving data though
I did not see may also what I want.
Seeking a save point. if you verwendent a function which is automatically stored in the program so that one with a butten or what else can load the save point.
Seeking but what what stores over a longer period
not pc shutdown, savepoint deleted
What exactly are you wanting to save? Are you trying to save data like scores, times and stuff or position of players and enemies etc? Are you wanting to create a level editor to save and then reload your map data etc. etc. etc. There are different methods depending on your needs.
Creating a save/reload point is pretty easy if you know what data needs to be saved. If you are more specific, then we can be too.
If you tell us exactly what you need, we can point you in the right direction - don't just say a save button to save progress.
Quote from: JonVelop on 2015-Sep-17I once read in the forum about Save [...] and more.
Perhaps this might help:
Creating a save game file (http://www.glbasic.com/forum/index.php?topic=4717.msg35595#msg35595)
I try the level yu save where it just is not the player's special position but the level where it is appreciated if you change the level should therefore be saved from a map to the next so that you would load the save point in the menu can.
I would also like to make the game for mobile. ;)
Here's a little playable demo, very loosely based on Bouderdash, to show you how you can create a game save state system.
Move the character with cursor keys.
Press 'S' to save game
Press 'L' to load game
This example allows you to save the player's position, current score and the map for the level.
I have kept things fairly simple, using no TYPEs and as basic as you can get. The demo does use arrays to store all of the game data except score.
but it shall not be stored but only when changing the position to the next level. This can be only at the beginning level starts when you continue and I would not push the while but that is automatically saved.
At level Change // Go to the next level
but should be automatically saved only at the starting point.
I hope you can help me :)
Sorry, I'm really not getting what you are asking for. Why/what would you want to save at the beginning of a level?
What type of game are you trying to make? Give an example.
Did you even try to work out what was happening in my demo? Is there no part of that that you could re-purpose.
What is your primary spoken language - maybe if you post in your language we will have someone on the boards who is able to translate?
Sorry, but we can't help if we can't understand.
Have you got any code running? We might be able to have a look and work out what it is you're after.
you should still checking out the example, actully fine eample to look on code how that things working.
if its only a single variable or such, uses INIPUT and INIGET$ commands and also checking out PLATFORMINFO$ command. Its depend of content you want to been saved.
I try to speak better.
an example is Sonic The Hedgehog and Super Mario.
I try a Platformer or Jump 'n' Run.
As is to be saved at the beginning level.
Nothing is saved at the beginning of those games.
Do you mean the level is loaded at the start and once it's beaten you move onto the next?
What do you think is saved at the beginning of the level in Sonic & Mario?
Are you just needing some form of level editor to create, save and load levels (which can be used in-game too)? If so, my example a very basic loading/saving of the level.
I think what you want is to just save the player's progress through your game.
If the player just finished Level 6, you want to save that progress info to a file.
Then the next time the player plays the game, you start him / her from that level.
For that, just save the highest level the player reached to a file.
Each time he finished a new level, update the save file.
When the game starts, read that progress file to know which level to start the player.
You need to know how to read and write to a file for this.
Choose a file name such as "player_level.txt" or something meaningful.
If you want to see some file reading and writing code, take a look at my FILE library (below the following example).
To use it for your problem, try something like:
[EDIT] This doesn't allow for skipping levels, and knowing which levels where done, and which were skipped.
LOCAL playerLevel AS TFile
LOCAL levelAchieved% = 0
playerLevel.name$ = "player_level.txt"
// Read Player Level Progress
FUNCTION PlayerLevelRead:
IF playerLevel.Get()
levelAchieved = playerLevel.data$ // Converts data$ string into a number
ELSE
levelAchieved = 0
LOG("*** Error Getting PlayerLevel! ***")
ENDIF
ENDFUNCTION
// Write Player Level Progress
FUNCTION PlayerLevelWrite:
playerLevel.data$ = levelAchieved
playerLevel.Write()
ENDFUNCTION
// To read the player's progress (such as at the start of the game):
// ('levelAchieved' will now be which level to start with.)
PlayerLevelRead()
// To write new player's progress (such as when he finished a new level):
// (make sure 'levelAchieved' already has the new level number)
PlayerLevelWrite()
My TFile Library code:
//---------------------------------------------------------------------- F i l e
CONSTANT FILE_MODE_APPEND = -1
CONSTANT FILE_MODE_WRITE = 0
CONSTANT FILE_MODE_READ = 1
CONSTANT EOF$ = "<EOF>"
TYPE TFile
fh% // File Handle
name$ // File Name
data$ // File Contents
eof% // File is at end?
// Reads entire file into 'self.data$'. Closes file when finished.
// 'name$' > Optional. Will use previously set 'self.name$' if blank.
// Returns > [TRUE if succeed | FALSE if fail]
FUNCTION Get%: name$=""
IF name$ <> "" THEN self.name$ = name$
self.data$ = ""
LOCAL line$ = ""
IF self.Open(FILE_MODE_READ)
WHILE ENDOFFILE(self.fh) = FALSE
READLINE self.fh, line$
INC self.data$, line$
WEND
CLOSEFILE self.fh
ELSE
LOG(">FIL:{TFile.Get$ } *** Error Getting File: [" + self.name$ + "] ***")
RETURN FALSE
ENDIF
self.Close()
RETURN TRUE
ENDFUNCTION
// Reads the next line in an already opened file. Closes file when end is reached.
// Returns > [line data if succeed | 'EOF$' if fail]
FUNCTION GetLine$:
LOCAL line$
IF ENDOFFILE(self.fh)
line$ = EOF$
self.eof = TRUE
self.Close()
ELSE
self.eof = FALSE
READLINE self.fh, line$
ENDIF
RETURN line$
ENDFUNCTION
// Writes 'self.data$' to file
// 'name$' > Optional. Will use previously set 'self.name$' if blank.
// Returns > [TRUE if succeed | FALSE if fail]
FUNCTION Write%: name$=""
IF name$ <> "" THEN self.name$ = name$
IF self.Open(FILE_MODE_WRITE)
WRITESTR self.fh, self.data$
ELSE
LOG(">FIL:{TFile.Write$ } *** Error Writting File: [" + self.name$ + "] ***")
RETURN FALSE
ENDIF
self.Close()
RETURN TRUE
ENDFUNCTION
// Appends string to end of file.
// 'extra$'> Data to append
// 'name$' > Optional. Will use previously set 'self.name$' if blank.
// Returns > [TRUE if succeed | FALSE if fail]
FUNCTION Append%: extra$, name$=""
IF name$ <> "" THEN self.name$ = name$
IF self.Open(FILE_MODE_APPEND)
INC self.data$, extra$
WRITESTR self.fh, extra$
ELSE
LOG(">FIL:{TFile.Append$ } *** Error Appending File: [" + extra$ + "] ***")
RETURN FALSE
ENDIF
self.Close()
RETURN TRUE
ENDFUNCTION
// Opens file for procesing.
// 'mode%' > [FILE_MODE_APPEND | FILE_MODE_WRITE | FILE_MODE_READ]
// 'name$' > Optional. Will use previously set 'self.name$' if blank.
// Returns > [TRUE if succeed | FALSE if fail]
FUNCTION Open%: mode%, name$=""
IF name$ <> "" THEN self.name$ = name$
self.fh = GENFILE()
self.eof = FALSE
IF OPENFILE(self.fh, self.name$, mode) = FALSE
LOG(">FIL:{TFile.Open } *** Error Opening File: [" + self.name$ + "] ***")
self.eof = TRUE
RETURN FALSE
ENDIF
RETURN TRUE
ENDFUNCTION
// Closes file to further processing
FUNCTION Close%:
IF self.fh >= 0 THEN CLOSEFILE self.fh
self.fh = -1
self.eof = TRUE
ENDFUNCTION
// Checks if file exists
// Returns > [TRUE if exists | FALSE if doesn't]
FUNCTION Exists%:
RETURN DOESFILEEXIST(self.name$)
ENDFUNCTION
// Returns file name portion from a longer file path
// eg. For a 'self.name$' of [C:/Programs/GLBasic/glbasic.exe] will return [glbasic.exe]
// 'slash$' > Optional. Folder Seperator. Use if your path uses '\' instead. Uses '/' as default
FUNCTION GetName$: slash$="/"
LOCAL slash%
slash = REVINSTR(self.name$, slash$)
IF slash <=0 THEN RETURN self.name$
RETURN MID$(self.name$, slash+1)
ENDFUNCTION
ENDTYPE
FUNCTION LOG: message$, add_linefeed% = TRUE, show_time% = TRUE
STATIC datetime% = -1 // Log timer
LOCAL elapsed# // How much time has elapsed since program start (or manual reset)
IF datetime < 0 THEN datetime = GETTIMERALL() // Initialize log timer if not already set
IF message$ = "RESET" THEN datetime = GETTIMERALL() // Manually reset log timer
elapsed = (GETTIMERALL() - datetime) / 1000.0
?IFDEF WIN32
//?IFDEF GLB_DEBUG
//?ENDIF
IF show_time = TRUE THEN DEBUG "[" + FORMAT$(8, 3, elapsed) + "] "
DEBUG message$
IF add_linefeed THEN DEBUG "\n"
?ELSE
INLINE
STDOUT(message_Str);
ENDINLINE
?ENDIF
ENDFUNCTION
That looks a lot like overkill to me!
If all he wants is to save the last level that the user reached then he could have used what was in my source code. If that's the case, he didn't even read through it. The "SCORE" variable would do exactly that (changed to LEVEL). If he didn't read through something using only BASIC commands, then using inline commands is waaaaay OTT.
Yes, but I would just like when the player stops in Level 6 and the game is closed that can start when it starts again in level 6 again.
Villeicht also you can call it in the menu.
The Level Change:
----------------------------------------
IF Map.Tile (self.X + self.Width / 2, self.Y + self.Height / 2) = 2
IF Nexxt $ = "Map2.txt"
ELSEIF Nexxt $ = "Map2.map"
ELSE
Map.Init (Map.Nexxt $)
ENDIF
ENDIF
----------------------------------------
And if in the level should be able to play at the next start on.
How do I build it and how can I retrieve? (CONSTANT?)
Quotees, but I would just like when the player stops in Level 6 and the game is closed that can start when it starts again in level 6 again.
:/
My demo shows EXACTLY that. Did you actually play it? The only difference is that in my demo you click L to LOAD, rather than it starting automatically from where you left off.
Sorry, your demo I've never played
but I want to learn the yes and not copy you can perhaps explain in your demo?
Please :)
test it out. we have explained, then you need to experimentere. This is way to go. The demo was made to show of how its can been done and change what it needs to suit your needs.
Its the best way to explain thing, that is simply a demo with a source code, which is much easier to explain thing. Now its up to you.
QuoteSorry, your demo I've never played
WTF!!!
SERIOUSLY?
What was the point in us trying to give you answers? How do you even know then that your question wasn't answered already?
:blink: :blink: :blink: :giveup:
(yes but I do not mean that. I'm stupid)
To Save-Demo:
The is really good.
My problem is but I have everything in multiple tabs in my project and not all on one side.
How to do that best?
I own the TAP: Player, Map, Menu.
Every time I try:
error: invalid initialization of reference of type 'DGNat&' from expression of type 'DGInt'