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.

Newcomers AppGameKit Corner / Creating a save game file

Author
Message
Nickkall
7
Years of Service
User Offline
Joined: 19th Jul 2017
Location: Sydney, Australia
Posted: 8th Sep 2018 14:16
Hi all,

I would like to ask a question.

I have made a minecraft kind of game. I have done it so I I have a stack of cloned objects that can be removed or new blocks are created by cloning a set of original blocks.

I have been reading and I cant work out how to save the game into a file.

I am guessing it is either an Array, Memblock or making a text file. Which would be the best way to go about it

Just some other questions I have. Please excuse me if I sound dumb, I am quite new to App Game Kit. And I am not a Computer Programmer. I am learning on the fly.

Is Memblock the equivalent to a data grid?
and
Can I find which ".obj" file a particular Object is using? GetObjectFile or something...

Thanks for reading and I hope you can help.

Nick
smallg
Valued Member
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location: steam
Posted: 8th Sep 2018 14:52
saving depends how you want to do it but writing to a file is the easiest method imo, it's a bit of a tedious process with lots of data but as long as you remember everything and read the file in the same order when loading it everything will work as expected.
i use for loops to store all the data in chunks so all related data is in a readable order and use WriteLine() command to get a file you can read by eye after (requires you convert all info to string when writing but helps a lot for debug purposes).
i.e.
file = OpenToWrite("save.txt")
WriteLine(file,"player info")
WriteLine(file,str(playerposX))
//etc
WriteLine(file,"block info")
for a = 0 to 999
WriteLine(file,str(blockposX[a]))
//etc
next a
CloseFile(file)

memblocks are just bytes of data (0~255) that make up the desired file, you can read exactly how they are created (it depends on the type of file) in the official help

i don't think you can get the name of the file of an object no - i can't imagine why you would need to though, you need to reference that file when first creating the object so it would be impossible to never know it.
life's one big game
spec= 4ghz, 16gb ram, AMD R9 2700 gpu
Icerion
6
Years of Service
User Offline
Joined: 3rd Aug 2018
Location:
Posted: 8th Sep 2018 18:10 Edited at: 8th Sep 2018 20:49
For some reason, I can't get AppGameKit to write files at all. No matter what I try.

And yes, I tried the 'append' parameter. Still didn't work.

How do I fix this?

Thanks!
smallg
Valued Member
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location: steam
Posted: 8th Sep 2018 21:38
are you sure it's not writing the file or is it that you can't find the file?
the default write location is a hidden folder in steamapps, you can set it to another location with SetFolder().
life's one big game
spec= 4ghz, 16gb ram, AMD R9 2700 gpu
Nickkall
7
Years of Service
User Offline
Joined: 19th Jul 2017
Location: Sydney, Australia
Posted: 9th Sep 2018 01:14 Edited at: 9th Sep 2018 01:16
Thanks smallg for the reply. You are right. I do reference the object. that problem solved.

So reading the guides you showed and other info there, I am trying to find the best way to store data like this:



etc etc for many more block (about 10000)

I am not sure if I should Memblocks or Arrays or Types.
Icerion
6
Years of Service
User Offline
Joined: 3rd Aug 2018
Location:
Posted: 9th Sep 2018 01:27
I just tried :



It still won't write.

Thanks!


blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 9th Sep 2018 02:58
AGK will create that file in "Users/Your name/AppData/Local/AgkApps/Your project name/media"

Try SetRawWritePath() to set an absolute write path
Nickkall
7
Years of Service
User Offline
Joined: 19th Jul 2017
Location: Sydney, Australia
Posted: 9th Sep 2018 06:02
I have done it

I used a Type to do it...



This is just a small version. I just need to blow it up to handle 10000 Types rather than 10.
I hope my computer doesn't tell me to go #%$ myself.

Nick
Nickkall
7
Years of Service
User Offline
Joined: 19th Jul 2017
Location: Sydney, Australia
Posted: 9th Sep 2018 06:03
And I am still interested in getting the File Path thing in here answered as well.

I am with you Icerion. I cant get it to work either.

Nick
Bengismo
7
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 9th Sep 2018 10:34 Edited at: 9th Sep 2018 10:38
You can write files quite easily but by default AppGameKit write to a "write" folder which IS NOT your media folder. Its quite well hidden and as blink has posted above...the save location is in the users directory on windows. You can write anywhere you like on windows but you must specify a full raw write path. This is covered in the docs.

Going back to the orginal post that Nikall raised before this thread was derrailled.

I would strongly consider writting all your game objects as types then put them all in a "gamestate" type. You can then just convert this to JSON and save it. Then when you load it again, it creates the correct number of objects/types etc. Everything is filled in for you and you dont need to do any file parsing. Its very powerful. You can easily add new types to your game without rewriting your save function or load function. It just works really well and is expandable.

Plus, json files are easily editable and you can see whats saved versus a binary file where its more difficult to track a missing byte or corrupt data.
Icerion
6
Years of Service
User Offline
Joined: 3rd Aug 2018
Location:
Posted: 9th Sep 2018 10:35
I have my reasons for needing it this way.

Thanks!
smallg
Valued Member
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location: steam
Posted: 9th Sep 2018 17:12
ah yes sorry, appdata folder, not steamapps... still, it's a hidden folder
adding
SetRawWritePath(GetReadPath())
will put the file in your media folder where you read your files from (i.e. open your project at it's own location)
or
SetRawWritePath(GetDocumentsPath())
will put it in a "media" folder in your documents folder
though changing the folder can fail if there is a permissions issue.
life's one big game
spec= 4ghz, 16gb ram, AMD R9 2700 gpu
Icerion
6
Years of Service
User Offline
Joined: 3rd Aug 2018
Location:
Posted: 9th Sep 2018 19:29 Edited at: 9th Sep 2018 19:43
Thanks @smallg! It worked!
Icerion
6
Years of Service
User Offline
Joined: 3rd Aug 2018
Location:
Posted: 9th Sep 2018 19:40 Edited at: 9th Sep 2018 19:43
Edit : Sorry for the double post.

Login to post a reply

Server time is: 2024-11-23 04:52:26
Your offset time is: 2024-11-23 04:52:26