LiEnby / chovy-gm

At long last. GameMaker 8.1 to PSP!
GNU Lesser General Public License v2.1
42 stars 4 forks source link

Trying to read or write a file seems to be freezing the game #8

Closed mejeve closed 2 years ago

mejeve commented 4 years ago

I have a game which is running a few filed read and write functions. For example

//Eg.1.Checking if file exists
file_exists("tntbf.sav")

//Eg.2 Opening a file
load = file_text_open_read("tntbf.sav")

//Eg.3 Writing to a file
save = file_text_open_write("tntbf.sav")
file_text_write_string(save,"Save Data.")
file_text_writeln(save)

As soon as this happens the game is freezing. So, I had to comment out the file writing part. Is there supposed to be a safe/allowed location I'm supposed to write to or is file access not permitted on the PSP or the GML interpreter?

How do I save stuff and track user progress? Is there a PSP API avaialable for saving games?

LiEnby commented 4 years ago

maybe you have to specify the whole path- like ms0:/PSP/SAVEDATA/WHATEVER

if not i can look into how Karoshi handles saving if you want..

mejeve commented 4 years ago

That'd be helpful(Checking how Karoshi does this). Since I don't even know how the PSP handles save files. I'm not really sure if it's as easy as writing files to the save path. Maybe it has an API or something. Thanks!

LiEnby commented 4 years ago

{

ini_open("data.ini")

ini_write_real("Save Data","Level",min(max(global.levelnum,1),50))
ini_write_real("Save Data","Coins",global.coins)
if variable_global_exists("lastroom") ini_write_real("Save Data","Room",global.lastroom)
else ini_write_real("Save Data","Room",1)
ini_write_real("Save Data","Music",global.playmusic)
ini_write_real("Save Data","Sound",global.playsound)
ini_write_real("Save Data","Unlock1",global.unlocked1)
ini_write_real("Save Data","Unlock2",global.unlocked2)

ini_close()

}
       load_data È  ini_open("data.ini")

global.level_continue = ini_read_real("Save Data","Level",-1)
global.coins_continue = ini_read_real("Save Data","Coins",0)
global.room_continue = ini_read_real("Save Data","Room",0)
global.playmusic = ini_read_real("Save Data","Music",1)
global.playsound = ini_read_real("Save Data","Sound",1)
global.unlocked1 = ini_read_real("Save Data","Unlock1",0)
global.unlocked2 = ini_read_real("Save Data","Unlock2",0)

ini_close()

also found

    objPSPOverwrite w   var f;

ini_open("data.ini")
f=ini_read_real("Save Data","Level",0)
ini_close()

if f=0 or f=1 room_goto_next()

from karoshi

i wrote a simple test in GM81 on a create event:

ini_open("data.ini");
ini_write_real("abc","adb",1337);
ini_close();

and it works!

however the file saved seems to have some sort of encryption.. and is labeled "SECURE.BIN" but hey its something.

mejeve commented 4 years ago

Is there a way to check if this the first time creating the ini? Does opening the ini without creating it create an empty file or an exception/error or does it create a new .ini file?

however the file saved seems to have some sort of encryption.. and is labeled "SECURE.BIN" but hey its something.

Do you mean ini_open("data.ini") doesn't work due to the encryption?

LiEnby commented 4 years ago

no- its likely an encrypted archive or something.

you can stil open ("data.ini") but the actural file written to the memory stick is an encrypted "SECURE.BIN" file for some reason

mejeve commented 4 years ago

Looks like the ini is created as soon as you use the open function if it doesn't already exist.

From the docs:

https://docs.yoyogames.com/source/dadiospice/002_reference/file%20handling/ini%20files/index.html This opens an ini_file for reading and/writing. If the ini_file does not exist at the location you are checking, GameMaker: Studio may create one, but only if you write data to it. If you have only read information from the ini file, then the default values for the read function will be returned, but the ini file will not actually be created.