Post subject: lua question
Editor, Expert player (2313)
Joined: 5/15/2007
Posts: 3855
Location: Germany
So I'm not very familiar with lua. In the past I had scripts like these
while true do
    blabla
    snes9x.frameadvance()
end
I can exchange snes9x for vba and gens. But putting in desmume doesn't work for me. What do I have to do?
gocha
Any
Emulator Coder, Former player
Joined: 6/21/2006
Posts: 401
Location: Japan, Nagoya
Gens Lua Documentation wrote:
-- initialization code (if any) goes here

gui.register( function()
  -- put any drawing code you want to do here
end)

emu.registerbefore( function()
  -- put any code you want to run before each frame here
  -- (such as getting/setting the next frame's input or writing to memory)
end)

emu.registerafter( function()
  -- put any code you want to run after each frame here
  -- (such as getting the last frame's input or reading from memory)
end)

emu.registerexit( function()
  -- cleanup code (if any) goes here
end)
Edit: ah, I didn't know that emu.frameadvance() is available on desmume.
I am usually available on Discord server or Twitter.
Emulator Coder, Skilled player (1300)
Joined: 12/21/2004
Posts: 2687
Actually the first way should work in desmume too even if it's not always the recommended way:
while true do
    blabla
    emu.frameadvance()
end
We have been trying to replace the emulator name with "emu" in these cases across multiple emulators because it's kind of pointless to have to change it to match each specific emulator.
Editor, Skilled player (1939)
Joined: 6/15/2005
Posts: 3247
Note that a number of Lua functions that are in other emulators are not in DeSmuME. Yet.
Editor, Expert player (2313)
Joined: 5/15/2007
Posts: 3855
Location: Germany
<mugg> gocha: About lua, I tried your suggestion (emu.register) but it doesn't work. It says the script is returned but still running the registered functions. And I don't know if my script is ok the way it is... <mugg> and I forgot the url of the site you can dump texts and codes in <mugg> (nvm, it's called pastebin) <mugg> http://pastebin.ca/1698518 <- this is the code I want to run <mugg> (maybe it's missing a "/256" but the main problem now is to get the text onscreen <mugg> I managed to get it shown onscreen for a millisecond each frame, then it disappears. Used "while true do", code, "emu.frameadvance()", end.
Emulator Coder, Skilled player (1300)
Joined: 12/21/2004
Posts: 2687
gui.register(function()
  local x = memory.readwordunsigned(0x0204A7CE) + memory.readwordunsigned(0x020BB6B1)
  gui.text(20,55,string.format("X-Co.: %.03f", x))
end)
That's going to put it somewhere near the top-left corner of the bottom screen, by the way. (0,0) is the top-left corner of the bottom screen, (0,-192) is the top-left corner of the top screen, and (256,192) is the bottom-right corner of the bottom screen.
Banned User, Former player
Joined: 12/23/2004
Posts: 1850
nitsuja wrote:
We have been trying to replace the emulator name with "emu" in these cases across multiple emulators because it's kind of pointless to have to change it to match each specific emulator.
I hope there's "emu.system" or something that returns the main type of emulator, since all of the various Lua impelmentations have their own quirks and bugs.
Perma-banned
Editor, Expert player (2313)
Joined: 5/15/2007
Posts: 3855
Location: Germany
while true do
  local x = memory.readwordunsigned(0x0204A7CE) + memory.readwordunsigned(0x020BB6B1)
  gui.text(20,55,string.format("X-Co.: %.03f", x))
  
  emu.frameadvance()
end
"5: attempt to call field 'frameadvance' (a nil value)"
gui.register(function()
  local x = memory.readwordunsigned(0x0204A7CE) + memory.readwordunsigned(0x020BB6B1)
  gui.text(20,55,string.format("X-Co.: %.03f", x))
end)
"script returned but is still running registered functions" Help is appreciated, thanks in advance..
Emulator Coder, Skilled player (1300)
Joined: 12/21/2004
Posts: 2687
MUGG wrote:
while true do
  local x = memory.readwordunsigned(0x0204A7CE) + memory.readwordunsigned(0x020BB6B1)
  gui.text(20,55,string.format("X-Co.: %.03f", x))
  
  emu.frameadvance()
end
"5: attempt to call field 'frameadvance' (a nil value)"
I guess this means you are running the wrong version of DeSmuME. That script works for me in version 0.9.5.
MUGG wrote:
gui.register(function()
  local x = memory.readwordunsigned(0x0204A7CE) + memory.readwordunsigned(0x020BB6B1)
  gui.text(20,55,string.format("X-Co.: %.03f", x))
end)
"script returned but is still running registered functions" Help is appreciated, thanks in advance..
It is supposed to print that message. This script also works for me in 0.9.5. I would expect it to work in 0.9.4+ too but I think most of the Lua stuff was a lot more incomplete in that version (at least it was the last time I tried it) so I'm not sure. I see both scripts draw something like "X-Co.: 66753.000" on the bottom screen.
Editor, Expert player (2313)
Joined: 5/15/2007
Posts: 3855
Location: Germany
Yeah, I'm using 0.9.4+ as I'm having trouble with 0.9.5 (much lag, confusing input display, desynch issues and on top of that I already began working on my movie) I guess I'll use the built-in RAM watch then... :P Thanks again
Emulator Coder, Skilled player (1300)
Joined: 12/21/2004
Posts: 2687
MUGG wrote:
desynch issues
There is only one known desync issue in 0.9.5, and it's there in 0.9.4+ also and in FCEUX (and probably some other emulators. It's fixed in Gens though). It's caused by user error when loading a savestate that isn't part of the current progression while in read-only mode. I have yet to see any other sort of desync in 0.9.5, even if I stress test the savestates to the max by saving and loading a savestate every frame. If you run into any real desync issues, please report them.
MUGG wrote:
confusing input display
You probably find it confusing because there is more information than before. But it's still pretty simple as long as you know this:
The DeSmuME Manual wrote:
View | Display Input Selecting this option displays the emulated input that the emulator is recognizing and sending to the game software. Note that if the input displayed is green, that means the emulator recognized it but did not send it to the game (this will happen if you are not running a game yet, for example). [Any other color means "pressed" as normal.] View | Display Graphical Input Same as Display Input but it is a super-spiffy graphical version.
MUGG wrote:
and on top of that I already began working on my movie
Well, that's an understandable reason.