File Reading/Writing [Solved]

In this forum you will find and post information regarding the modding of Star Wars Battlefront 2. DO NOT POST MOD IDEAS/REQUESTS.

Moderator: Moderators

Post Reply
Noobasaurus
Droid Pilot Assassin
Droid Pilot Assassin
Posts: 2006
Joined: Tue Aug 17, 2010 5:56 pm

File Reading/Writing [Solved]

Post 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.
Last edited by Noobasaurus on Fri Apr 03, 2015 12:15 am, edited 1 time in total.
razac920
2nd Lieutenant
2nd Lieutenant
Posts: 365
Joined: Sun Jan 16, 2011 12:42 am

Re: File Reading/Writing

Post 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.
Noobasaurus
Droid Pilot Assassin
Droid Pilot Assassin
Posts: 2006
Joined: Tue Aug 17, 2010 5:56 pm

Re: File Reading/Writing

Post 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?
razac920
2nd Lieutenant
2nd Lieutenant
Posts: 365
Joined: Sun Jan 16, 2011 12:42 am

Re: File Reading/Writing

Post 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.
Marth8880
Resistance Leader
Posts: 5042
Joined: Tue Feb 09, 2010 8:43 pm
Projects :: DI2 + Psychosis
Games I'm Playing :: Silent Hill 2
xbox live or psn: Marth8880
Location: Edinburgh, UK
Contact:

Re: File Reading/Writing

Post 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
Noobasaurus
Droid Pilot Assassin
Droid Pilot Assassin
Posts: 2006
Joined: Tue Aug 17, 2010 5:56 pm

Re: File Reading/Writing

Post by Noobasaurus »

Ah, thanks. I'll poke around for a while.

EDIT: Got it working. Awesome stuff. Thanks guys!
User avatar
[RDH]Zerted
Gametoast Staff
Gametoast Staff
Posts: 2982
Joined: Sun Feb 26, 2006 7:36 am
Projects :: Bos Wars AI - a RTS game
Games I'm Playing :: SWBF2 and Bos Wars
xbox live or psn: No gamertag set
Location: USA
Contact:

Re: File Reading/Writing [Solved]

Post 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?
Noobasaurus
Droid Pilot Assassin
Droid Pilot Assassin
Posts: 2006
Joined: Tue Aug 17, 2010 5:56 pm

Re: File Reading/Writing [Solved]

Post 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.
Post Reply