Post subject: Trouble with lua joypad.set
Joined: 5/26/2014
Posts: 7
I have a main loop like this:
while true do
  -- Only read the next frame of data if the last one was used
  if input_was_used and not finished then
    read_next_frame() -- sets buttons, X, and Y variables
    input_was_used = false
  end
  
  if not finished then
    joypad.set(buttons, 1)
    console.log(string.format('Buttons : %s', table.tostring(buttons)))
    local analogs = { ["X Axis"] = X, ["Y Axis"] = Y }
    joypad.setanalog(analogs, 1)
  end
  
  if finished then
    console.log("Movie finished")
    client.pause()
    return
  end
  
  emu.frameadvance()
end
The log statements indicate that the 'buttons' table is being populated correctly, for example key "Start" gets value true (boolean). However, the button data never gets passed to the emulator. The analog data DOES get passed to the emulator, just not the button data. This is for N64 ... Mario Kart 64 ROM Am I using joypad.set wrong?
Joined: 5/26/2014
Posts: 7
I found that using the null controller worked. Use keys like "P1 Start" and set them using joypad.set(buttons). The BKM format page has a typo for N64: http://tasvideos.org/Bizhawk/BKMFormat.html It lists the format as: Flag UDRLBAZSLRudlr xxx, yyy other controllers I think it should be UDLR at the start.
Experienced player (608)
Joined: 10/23/2004
Posts: 706
Sully, I have a script that will work with the bizhawk format to feed input in from course selection. I also found the race timer for when the ghost begins recording. I will check later this evening
Current Project: - Mario Kart 64
Joined: 5/26/2014
Posts: 7
Hey Drew, I got it to work. (Dex Save / Memory Pack file) -> Controller inputs with lag frames missing Then I run a lua script similar to the m64->bkm script that comes with BizHawk. This corrects the lag frames issue. It starts at Power On, navigates through the menus, starts a race, and then starts the ghost data on the correct frame. So I tried it with a LR 1:38.97 ghost and it synced perfectly, so it appears as if the race is being raced live.
Experienced player (608)
Joined: 10/23/2004
Posts: 706
Excellent! I found some good memory addresses like x, y, z coordinates. I wonder how hard it would be to find the course ghosts input.
Current Project: - Mario Kart 64
Post subject: Re: Trouble with lua joypad.set
Editor, Expert player (2079)
Joined: 6/15/2005
Posts: 3282
SeanSullivan86 wrote:
I have a main loop like this:
while true do
  -- Only read the next frame of data if the last one was used
  if input_was_used and not finished then
    read_next_frame() -- sets buttons, X, and Y variables
    input_was_used = false
  end
  
  if not finished then
    joypad.set(buttons, 1)
    console.log(string.format('Buttons : %s', table.tostring(buttons)))
    local analogs = { ["X Axis"] = X, ["Y Axis"] = Y }
    joypad.setanalog(analogs, 1)
  end
  
  if finished then
    console.log("Movie finished")
    client.pause()
    return
  end
  
  emu.frameadvance()
end
The log statements indicate that the 'buttons' table is being populated correctly, for example key "Start" gets value true (boolean). However, the button data never gets passed to the emulator. The analog data DOES get passed to the emulator, just not the button data. This is for N64 ... Mario Kart 64 ROM Am I using joypad.set wrong?
Hi SeanSullivan86. I tested the following code in BizHawk and it presses the Start button on Controller 1, as shown by input display. So I think that giving the key "Start" with a value of true and using joypad.set(key,1) is supposed to work. It might appear to be one frame late.
key={}
while true do
 key["Start"]=true
 joypad.set(key,1)
 emu.frameadvance()
end
By the way, console.log(joypad.getimmediate()) can be used instead of console.log(string.format('Buttons : %s', table.tostring(buttons))) (I haven't seen your full program though, so I don't know if it works in your context). I also fixed the wiki page for N64 movie data in BKM.