Page 1 of 1
File Reading/Writing [Solved]
Posted: Thu Apr 02, 2015 4:59 pm
by Noobasaurus
I recall that someone else posted a similar question once, but I can't seem to find it. I want to read and write data to a file so that it can be loaded the next time the person plays, but I believe I read somewhere that those functions are disabled. I tried this:
Code: Select all
file = io.open("test.txt", "w")
file:write("Hello World")
file:flush()
file:close()
and it gives me this error:
Code: Select all
Message Severity: 3
C:\Battlefront2\main\Battlefront2\Source\LuaHelper.cpp(312)
CallProc failed: (none):0: attempt to call field `open' (a nil value)
stack traceback:
(none): in function `ScriptPostLoad'
Does anyone know of a way I can read and write simple values to a text file from lua? I know that it's possible in GC but I don't really want to go there.
Re: File Reading/Writing
Posted: Thu Apr 02, 2015 5:51 pm
by razac920
I thought at one point I saw a map which initially had only a campaign mode unlocked, but after playing through the campaign a conquest mode was also unlocked, but I cannot remember the name of this map -- At any rate I do not know how this is done, but it seems like some sort of file reading/writing must be involved.
Alternatively, Maveritchell's Spira: Besaid map made use of a save/load feature, so if you are willing to give the player the controls to make changes in future playthroughs, that is an option as well.
Re: File Reading/Writing
Posted: Thu Apr 02, 2015 6:17 pm
by Noobasaurus
Thanks. I took a look at Mav's Spira: Besaid and it looks like the save feature is only available in one playthrough (when you exit the game you have to start over). I'm looking for something that is more like the first save you mentioned, where somehow the player's progress is saved so that in the next session it can be used again.
I remember in a certain Rancor map where once you beat the level on a certain difficulty, it would give you the password to unzip the other maps. Is this what you were talking about, or was it something else?
Re: File Reading/Writing
Posted: Thu Apr 02, 2015 6:22 pm
by razac920
I don't THINK so, but it's been several years and I don't remember very well. I THINK the main focus of the map was the campaign, and upon successfully completing the campaign one could play conquest -- or alternatively, there was a separate installation instruction to have conquest unlocked by default. But I'm not 100% sure about this, and a quick search through campaign maps didn't ring any bells for me, so no clue which map it could be.
Re: File Reading/Writing
Posted: Thu Apr 02, 2015 7:09 pm
by Marth8880
I was the one who posted the question regarding Lua's I/O library.
http://www.gametoast.com/viewtopic.php?f=27&t=29535
Re: File Reading/Writing
Posted: Fri Apr 03, 2015 12:15 am
by Noobasaurus
Ah, thanks. I'll poke around for a while.
EDIT: Got it working. Awesome stuff. Thanks guys!
Re: File Reading/Writing [Solved]
Posted: Fri Apr 03, 2015 1:02 am
by [RDH]Zerted
There's a couple different ways to go about it. For future reference when people find this topic, which way did you do it?
Re: File Reading/Writing [Solved]
Posted: Fri Apr 03, 2015 1:25 am
by Noobasaurus
I did it using your script, SaveAndLoadUtils. It stumped me for about 5 hours hours but then I realized that the callbacks and data encoding/decoding functions were outside of the ScriptPostLoad.