Post subject: Lua Read then Write to File
CyZnRg
He/Him
Joined: 4/28/2018
Posts: 1
I am running a lua script or series of scripts that read from various memory addresses, do math, and then display the results as gui.text. I am wondering how I can output those same results to an external file separate from the emulator instead - ideally with a static line that updates for each so it doesn't constantly write with a carriage return like the console - so I can view them without overlaying them on my emulator window(s). I tried various I/O commands within the scripts but they all print to the console. I am uncertain whether this is even possible, or whether the choice of commands I was using are just incorrect. This would be useful because more information could be viewed at the same time as well as function as a sort of RAM Watch with math included. It would also leave the emulator screens free of text and potential garbage, and perhaps allow saving of particular information for future reference.
Masterjun
He/Him
Site Developer, Expert player (2047)
Joined: 10/12/2010
Posts: 1185
Location: Germany
Use the I/O library in Lua itself.
Language: lua

file = io.open("coolfile.txt","w") file:write("cooltext\n") file:close()
There might be some better way to make a static line that updates rather than keep closing and reopening the file, maybe something with file:seek("set").
Warning: Might glitch to credits I will finish this ACE soon as possible (or will I?)
Player (98)
Joined: 12/12/2013
Posts: 380
Location: Russia
I would prefer having hotkey for saving this info into file. Or, having same/other hotkey for printing this info into console. Just because constant-writing to disk isn't good idea, because I don't know any app which able to refresh file runtime. and if you need to capture some moment, it will run away because of fps. in case if you need just single frame, you'll have to pause and seek for frame. similarly you can do same with those hotkeys. but with hotkeys you'll avoid spam in disk or console. if you anyways working in frame by frame mode, you can just add some separators into your console, to make things clear, and avoid using files again. For example:
Language: lua

print(string.format("===Frame %d", emu.framecount())) -- separation print(string.format("HP: %d X: %d Y: %d", HP, X, Y)) print(string.format("SpeedX: %d SpeedY: %d", SpeedX, SpeedY)) ....
Editor, Reviewer, Skilled player (1361)
Joined: 9/12/2016
Posts: 1646
Location: Italy
r57shell wrote:
I would prefer having hotkey for saving this info into file.
Language: lua

if input.get()["x"] then file:write("cooltext\n") end
r57shell wrote:
Or, having same/other hotkey for printing this info into console.
Language: lua

if input.get()["y"] then console.log("cooltext") end
my personal page - my YouTube channel - my GitHub - my Discord: thunderaxe31 <Masterjun> if you look at the "NES" in a weird angle, it actually clearly says "GBA"