[SOLVED] File I/O in HWRM 2.0?

What is the correct way of doing file I/O operations now that the new patch has been released?

from what I understood from my previous discussions with @BitVenom, same as before, but the file must be in the profiles folder, otherwise it will crash (or perhaps only do nothing, I don’t know)

Edit: I’m going to update my rainbow mod in the next few days (if I find the time), so I will experiment on this at the same time

1 Like

Do I need to specify the full system path? Or does the game already know what folder to start in?

I think you have to use the profile: root alias… If I recall. I ran a bunch of tests after the edits, and it was all working great!

If it’s like before, the “base” of the path is the exe, so something like “…\Profiles” should work I suppose

So the Lua openfile(), closefile() and write() functions understand aliases now? They did not in the past.

Ah, sorry - no. They force that one. (to be clear, they force ‘player:’ )

If you attempt to just open ‘test.txt’ - it should end up in the current profile’s folder.

for dofilepath you mean ?
before, we were able to use dofilepah(profiles:myfile.lua) to load a file in the profiles folder or dofilepah(player:myfile.lua) to load a file in the current player folder (so Profile1 for example)

For write() and read(), what should we use ?
previous format was writeto("…/Profiles/myfile.lua") or writeto("…/Profiles/Profile1/myfile.lua")
the current problem is to find the name of the current player folder I think. Before, I would read the local.ini file in the Bin folder but this is not possible anymore from what I understood previously.

Edit : just seen your answer, sorry. This solution is great ! No more need to find the current player folder if it’s like this :slight_smile:

Yes, we need a function for writing files that understands aliases like “profiles” and “player”.

Yeah, dofilepath hasn’t been changed - because it wasn’t any sort of risk, it just runs LUA. Raw file IO being allowed anywhere on the client’s machine though… eh, not really a responsible thing for us to facilitate…

No need for that I think, if writeto(“myfile.lua”) forces the path to the current player folder :slight_smile:
The only thing I wonder is if something like writeto("/subfolder/myfile.lua") would work ? (to create a subfolder to sort files by mod for example) @Bitvenom ?

Yeah, I know… that’s why I didn’t elaborate on the subject when you told me this the first time. And it was even worse with the access we add to exec function (all ms-dos functions like md, delete, etc… :scream: )

No - it can be only a filename. No path navigation at all. I suggest you prefix the files for your mod, etc…

If I can find time I may work in some sort of prefix alias code that auto-slots your files into a path that the Mod is allowed to define at boot. But for now, filename only.

1 Like

ok, good to know. That’s more or less what I was doing at the moment, but I asked anyway, just to be sure :slight_smile:

Show me an example of valid lua read/write, please? I am testing something for this…

This might work.

local WriteFile = "my_file.txt"
local WriteHandle = openfile(WriteFile, "w+")
closefile(WriteHandle)
local WriteHandle = openfile(WriteFile, "a")
local WriteString = "Here is some text."
write(WriteHandle, WriteString)
closefile(WriteHandle)

something I was doing before for example. It found the current player folder and write a file in a subfolder which say that the mod is correctly initialized

readfrom("../../Bin/local.ini");
read();
sui_currentprofilefolder = read();
sui_currentprofilefolder = gsub(sui_currentprofilefolder, "currentprofile=", "");
readfrom();
execute("mkdir ..\\..\\Bin\\Profiles\\"..sui_currentprofilefolder.."\\SnakeUI");
writeto("../../Bin/Profiles/"..sui_currentprofilefolder.."/SnakeUI/SnakeUI.ini");
write("SnakeUI_status = \"Ready !\"\n");
write("sui_currentprofilefolder = \""..sui_currentprofilefolder.."\"\n");
writeto();

In the next patch I had some extra stuff for this, will update once the patch is locked (really, really soon).

3 Likes

Thanks a lot ! (I just updated my previous post with the full logic I used to use before the 2.0 patch)

Hey so uh…

When’s the patch coming?

runs and hides

1 Like