Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / save and load example

Author
Message
mihaid
14
Years of Service
User Offline
Joined: 24th Feb 2012
Location:
Posted: 1st Aug 2012 18:33
Hello,

I red theory about save and load game in dark basic professional, but please i need a real example, not the minimum simplified example.
I have a game where I pick up many tools, and need to save the player position and tools at a moment. Who can give me an example from a game???

Mihai
Sergey K
22
Years of Service
User Offline
Joined: 4th Jan 2004
Location:
Posted: 1st Aug 2012 18:47
sure. i can help u with it.

but 1st, lemme ask you a question here..

lets say the next code is a notepad text:

can u load it in dbp?
lets say the Player is your own positions (X,Y,Z)
and Object (the number that comes after is the object number) positions X Y Z

the reading steps are:
open the file to read
repeat
line$ = Read Each line of code
ProcessEachLineOfCode(line$)
until end of file

and the last step is the function it self..
function ProcessEachLineOfCode(cmd$)
here you need to split each line into word list.
so you making a function that can split the whole line into words
so instead of:
Player 100 50 10
> you convert it to:
Player
100
50
10

endfunction

if you accomplish this, you will figure out the rest by ur self (trust me, you will )

Advanced Updater for your games!
mihaid
14
Years of Service
User Offline
Joined: 24th Feb 2012
Location:
Posted: 1st Aug 2012 20:47
Thank you very much !!!

Mihai
MrValentine
AGK Backer
15
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 2nd Aug 2012 09:33
Sergey K - that was mega helpful!!!

Well done and thanks for sharing that I did not think about splitting the line...

But would it not be easier to just record the data originally into the same sequence that way saving the splitting of code while loading in...

Kind of the same solution in reverse...



Please let me know of any possible faults in my reverse strategy.

TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 2nd Aug 2012 10:14
You'll also have to save values to the file. For example player health, collected items etc. For those values you should have variables in your program, so just save those to the file with the variable name. Let's say you have the variable Player_Health = 67 and Player_Item_Sword = 1, this is what the file would look like:



Then, like Sergey already said, convert it back to values and assign those values to the variables.

TheComet

Daniel wright 2311
User Banned
Posted: 2nd Aug 2012 22:10
This is what I do to save in my game loops

save



load in a game



my signature keeps being erased by a mod So this is my new signature.
mihaid
14
Years of Service
User Offline
Joined: 24th Feb 2012
Location:
Posted: 4th Aug 2012 20:31
Thank you all very much !!!It's very helpful for me !!

Mihai
mihaid
14
Years of Service
User Offline
Joined: 24th Feb 2012
Location:
Posted: 5th Aug 2012 18:20
I come again with a question:
I applied the last snipped, offered by Daniel,and it's working.
My question is:

If an object it's visible or not, how to save and load???
Thanks in advance

Mihai
Sergey K
22
Years of Service
User Offline
Joined: 4th Jan 2004
Location:
Posted: 5th Aug 2012 18:23
daniel's snippet is very limited. you should make your own script system just like i showed you.
you can make a tamplate of:
ObjName X Y Z Hideen LightOff RX RY RZ Frame
so you can see it like:
Player 10 -50 10 1 0 90 90 0 30

Advanced Updater for your games!
mihaid
14
Years of Service
User Offline
Joined: 24th Feb 2012
Location:
Posted: 5th Aug 2012 19:02
Dear Sergey,

Thank you for your help.
I'm a beginner, and that's why for me it's more difficult to apply your suggestion to my game. I know very well you are right to tell me like this, becose I can learn more, not to apply an example, but sometime, when I try, and try, and try, and...no success, I need a more detailed answer. Anyway, I understood your idea with template, to establis the variables for coordonates, hidden..etc...and I tried, but something is wrong to my code, that's why I hope to find a specific example.

Mihai
Daniel wright 2311
User Banned
Posted: 5th Aug 2012 22:29 Edited at: 5th Aug 2012 22:29
Quote: "If an object it's visible or not, how to save and load???
Thanks in advance"


well, just create a state in your loop to if your object is hiden or not like this

if hideobject1=1 then hide object 1

if hideobject1=0 then show object 1

then save you state for hideobject1 before you load.

my signature keeps being erased by a mod So this is my new signature.
Kezzla
17
Years of Service
User Offline
Joined: 21st Aug 2008
Location: Where beer does flow and men chunder
Posted: 6th Aug 2012 06:56
I use dark data.
It saves a lot of hassle and it's pretty easy to use.

Sometimes I like to use words out of contents
MrValentine
AGK Backer
15
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 6th Aug 2012 06:58
Kezzla... I have that too... Could you help me get aquainted with it¿

Kezzla
17
Years of Service
User Offline
Joined: 21st Aug 2008
Location: Where beer does flow and men chunder
Posted: 6th Aug 2012 15:55 Edited at: 6th Aug 2012 16:01
@mrValentine

sure, I only have a basic grasp of it too but its all I needed to effectively use it.

I think the key is to use string data for its operations.

I know it apparently can handle multiple data types but I always get a zero value when I stray from strings.

here is a little example project used to make a database, fill it with data for
number
x position
z position

you can look up the data from lookup tables for
number
xpos
zpos

there are no limits to the number of databases and lookup tables you can create and it cuts out many of the string handling functions you would otherwise have to write for a text file style system.


I used this system for a placement editor I was working on a while back.
great for saving and loading many fields.


again critical element is to remember to input string data and retrieve string data, converting it to whatever it needs to be.
I never got the other data types to work even when I just swapped over the data types.

if you get int and float going then please share.

Sometimes I like to use words out of contents
Seppuku Arts
Moderator
21
Years of Service
User Offline
Joined: 18th Aug 2004
Location: Cambridgeshire, England
Posted: 10th Aug 2012 23:53
If you're still looking for any other examples, I did post this in Code Snippets yesterday, if it'll help.

MrValentine
AGK Backer
15
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 11th Aug 2012 11:38
mega thanks to both of you two

I hope to utilise DData asap...

Seppuku Arts
Moderator
21
Years of Service
User Offline
Joined: 18th Aug 2004
Location: Cambridgeshire, England
Posted: 11th Aug 2012 13:00
Also, for Dark Data, I posted notes here (just for myself really, but you might find them useful).

I did have some difficulty getting my head around it, but hopefully the above explanation should help make it clearer.

Sergey K
22
Years of Service
User Offline
Joined: 4th Jan 2004
Location:
Posted: 11th Aug 2012 14:05
@Seppuku Arts: heh nice man, you got ur own forum now grtz

Advanced Updater for your games!
Seppuku Arts
Moderator
21
Years of Service
User Offline
Joined: 18th Aug 2004
Location: Cambridgeshire, England
Posted: 11th Aug 2012 18:16
Lol, the only 2 people signed up are me and Mr Valentine, it's just there should anybody who visits my blog feel the need to post something.

mihaid
14
Years of Service
User Offline
Joined: 24th Feb 2012
Location:
Posted: 25th Aug 2012 23:03
Hello again,

I need a little help pls !!

I want to save my game at a moment, and I have a variable, which represent the number of ..some object, let's say 3 pieces of stone. I made this 3 stones with make cube....etc.

I save the number 3 as variable, (write long 1, stone), and when I load, cant see again the 3 stones.

I have also dim stone (100), and tried to load like this:

read long 1, stone

for i = 1 to stone
if object exist (20000+ stone)= 1 then delete object 20000+stone
next i

for i = 1 to stone
make object cube 20000+stone, 25
texture object 20000+stone, 1800
position object 20000+ stone, -853, -40+26*stone, -4220
set object collision off 20000+stone
next i


I have this error: object already exist at line............

so...please help me and tell me where is the mistake???

Mihai
Daniel wright 2311
User Banned
Posted: 26th Aug 2012 02:34


YOUR LOOKING FOR SOMETHING LIKE THIS

my signature keeps being erased by a mod So this is my new signature.
mihaid
14
Years of Service
User Offline
Joined: 24th Feb 2012
Location:
Posted: 26th Aug 2012 08:10
sorry, not working, when I load file, it appear only one stone, not three....

Mihai
The Weeping Corpse
14
Years of Service
User Offline
Joined: 19th Sep 2011
Location: United Kingdom
Posted: 26th Aug 2012 09:53 Edited at: 26th Aug 2012 10:02
Make object cube xxx will fail if object xxx already exists.

I think Daniel made a typo. Maybe try this...



or even try this as its cleaner and less prone to mistakes if you make changes to it again...





Daniel wright 2311
User Banned
Posted: 26th Aug 2012 10:08
This is the better bet my friend, thanks the weeping corps



my signature keeps being erased by a mod So this is my new signature.
mihaid
14
Years of Service
User Offline
Joined: 24th Feb 2012
Location:
Posted: 26th Aug 2012 12:15
Sorry, I tried ALL SUGGESTIONS, - NOT WORKING !!!

It create only one object stone, textured ok, but not more

I put here the save&load routines:

save:
if keystate(31)=1
printsavegame=1
if file exist(name$+".dat")=1 then delete file name$+".dat"
open to write 1,name$+".dat"

write long 1,axes
write long 1,grow
write long 1,health
write long 1,hammer
write long 1,timber
write long 1,beam
write long 1,seed
write long 1,mushroom
write long 1,strawberry
write long 1, coffee
write long 1, hideobject8000
write long 1, claybrick
write long 1, sickle
write long 1, tacks
write long 1, stone
write long 1, pickaxe
write long 1, bow


x#=object position x(2)
y#=object position y(2)
z#=object position z(2)
ax#=object angle x(2)
ay#=object angle y(2)
az#=object angle z(2)


write float 1,x#
write float 1,y#
write float 1,z#
write float 1,ax#
write float 1,ay#
write float 1,az#



cx#=camera position x(0)
cy#=camera position y(0)
cz#=camera position z(0)
cax#=camera angle x(0)
cay#=camera angle y(0)
caz#=camera angle z(0)
write float 1,cx#
write float 1,cy#
write float 1,cz#
write float 1,cax#
write float 1,cay#
write float 1,caz#


set text size 36
set cursor 350, 350
print "Game saved"


close file 1
endif

return

load:


if file exist(name$+".dat")=1
open to read 1,name$+".dat"

read long 1, axes
read long 1, grow
read long 1, health
read long 1,hammer
read long 1,timber
read long 1,beam
read long 1,seed
read long 1,mushroom
read long 1,strawberry
read long 1,coffee
read long 1,hideobject8000
read long 1, claybrick
read long 1, sickle
read long 1, tacks
read long 1, stone
read long 1, pickaxe
read long 1, bow


read float 1,x#
read float 1,y#
read float 1,z#
read float 1,ax#
read float 1,ay#
read float 1,az#
position object 2,x#,y#,z#
xrotate object 2,ax#
yrotate object 2,ay#
zrotate object 2,az#


endif


for i = 1 to stone
stoneID = 20000 + stone

if object exist (stoneID)= 1 then delete object stoneID
make object cube stoneID, 25
texture object stoneID, 1800
position object stoneID, -853, -40+26*stone, -4220
set object collision off stoneID
next i

cx#=camera position x(0)
cy#=camera position y(0)
cz#=camera position z(0)
cax#=camera angle x(0)
cay#=camera angle y(0)
caz#=camera angle z(0)
read float 1,cx#
read float 1,cy#
read float 1,cz#
read float 1,cax#
read float 1,cay#
read float 1,caz#
position camera 0,cx#,cy#,cz#
xrotate camera 0,cax#
yrotate camera 0,cay#
zrotate camera 0,caz#


close file 1


return


- Outside of these routines I have :

dim stone (100),

stone = 0 -at beginning, but after some work, increase to 3, 4..etc.


So....please help !!

Mihai
The Weeping Corpse
14
Years of Service
User Offline
Joined: 19th Sep 2011
Location: United Kingdom
Posted: 26th Aug 2012 12:28 Edited at: 26th Aug 2012 13:01
Hi, please can you post the code that actually creates the stones in the first place, before you call save.

mihaid
14
Years of Service
User Offline
Joined: 24th Feb 2012
Location:
Posted: 26th Aug 2012 13:17
Tha main idea is this:

I take a hammer, and I go to a stone place, hit there. First section is in do-loop:


Do

if Mouseclick()=1 and activehammer=1
if object exist(2004)= 0 then load object "hammer.dbo",2004
position object 2004,50,30,100
rotate object 2004, 50, 30, 120
hammerlife =8
endif

If hammerlife > 0
Dec hammerlife
If hammerlife = 4 then gosub backhammer
Endif

Also in do-loop I have the distance to stone place:

for i = 1 to 1
dxpiatra2(i) = abs (object position x (1800+i)-object position x(2))
dypiatra2(i) = abs (object position y (1800+i)-object position y(2))
dzpiatra2(i) = abs (object position z (1800+i)-object position z(2))
distcampiatra2(i) = sqrt(dxpiatra2(i)^2+dypiatra2(i)^2+dzpiatra2(i)^2)
if distcampiatra2(i)<150 then gosub cutpiatra2
next i

Loop

Here is the routine asked to see hammer back initial position

backhammer:
position object 2004,20,-25,100
rotate object 2004, -5, 7, 120
play sound 9754
return

here I work with stone, if distance is ok...

cutpiatra2:
if mouseclick ()=1
hammerhit=hammerhit+1
play sound 9754
play sound 9757
if hammerhit = 20 then gosub takestone

ENDIF
return

here I make first time stone, before save

takestone:
hammerhit = 0
stone = stone +1
make object cube 20000+stone, 25
load image "piatra/piatra2.png", 19999
texture object 20000+stone, 19999
position object 20000+ stone, -853, 26*stone, -4220
set object collision off 20000+stone
return


Thank you for your support

Mihai

Login to post a reply

Server time is: 2026-07-21 20:34:28
Your offset time is: 2026-07-21 20:34:28