Post subject: Bizhawk lua question
Joined: 9/12/2014
Posts: 539
Location: Waterford, MI
With ds games, theres a lot of good games on there with 1 simple problem: a lot of games require the touchscreen to aim and such. I wanted to tas 007 bloodstone on ds but I don't like the aiming using the touch screen. The D pad and the A,B,X,Y keys do the same thing to benefit left and right hand users. So if I were to map A,B,X,Y to aiming controls, it would also move the character as well. So I guess somehow remove the A,B.X.Y key from the movie replacing with some touch control. I don't know how to do any of that.. So could someone provide some type of assistance here?
Joined: 9/12/2014
Posts: 539
Location: Waterford, MI
Im trying to do it myself but I'm having trouble:
while true do
	local x = 106
	local y = 116
	local btns = joypad.get()
	if btns["X"] == true then
		btns["Touch Y"] = y
		joypad.set(btns["Touch"])
		y = y+1
	end
	if y > 200 then
		y = 106
	end
	emu.frameadvance()
end
The log in the console doesn't really help.. can anyone spot what I'm doing wrong?
Editor, Player (174)
Joined: 4/7/2015
Posts: 331
Location: Porto Alegre, RS, Brazil
I guess your your joypad.set() is wrong, try this:
Language: lua

while true do local x = 106 local y = 116 local btns = joypad.get() if btns["X"] == true then btns["Touch Y"] = y joypad.set(btns) -- <<<<<< should pass the whole input table y = 106 end emu.frameadvance() end
Also what it's supposed to do? Because that x,y declaration in the start of the loop seems unnecessary, they could be declared before the loop (global variables). Because the way it is now, the loop start with y = 116, then increase 1, then in the next loop it gets back to 116, doesn't make much sense.
Games are basically math with a visual representation of this math, that's why I make the scripts, to re-see games as math. My things: YouTube, GitHub, Pastebin, Twitter
Joined: 9/12/2014
Posts: 539
Location: Waterford, MI
I tried declaring it globally so it would make sense but couldn't figure that out either even with Google. I guess I used Global instead of global. What it's supposed to do is, when pressing the X button, y would be set to 116, touch at that location, increase by 1. If it reaches 200, it resets back to 116. This is used for aiming in the y axis. Next obstacle is the emu.frameadvance(). Since it's automatic, I can't freeze the emulator manually. If I omit emu.frameadvance(), it would crash the emulator. I guess that's because Lua is on the same thread as the emu is.
Editor, Player (174)
Joined: 4/7/2015
Posts: 331
Location: Porto Alegre, RS, Brazil
InfamousKnight wrote:
I tried declaring it globally so it would make sense but couldn't figure that out either even with Google. I guess I used Global instead of global.
Just declare them with local but on the "root" of the script, outside the loops or functions, like:
Language: lua

local x = 106 local y = 116 while true do --etc
InfamousKnight wrote:
What it's supposed to do is, when pressing the X button, y would be set to 116, touch at that location, increase by 1. If it reaches 200, it resets back to 116. This is used for aiming in the y axis.
If i understood correctly, let's say on frame 1 you press X, y will be set to 116, touch, then increse 1 (117 now), then the frame advance, what should happen? if you press X again it should touch at 117 then increase to 118?
InfamousKnight wrote:
If I omit emu.frameadvance(), it would crash the emulator.
You can't omit emu.frameadvance(), the script should always have it inside the while loop in order to run while you're playing, otherwise the while loop will try to loop forever in the current frame, hence the crash.
Games are basically math with a visual representation of this math, that's why I make the scripts, to re-see games as math. My things: YouTube, GitHub, Pastebin, Twitter
Emulator Coder, Judge, Experienced player (720)
Joined: 2/26/2020
Posts: 773
Location: California
InfamousKnight wrote:
Next obstacle is the emu.frameadvance(). Since it's automatic, I can't freeze the emulator manually. If I omit emu.frameadvance(), it would crash the emulator. I guess that's because Lua is on the same thread as the emu is.
emu.frameadvance() doesn't prevent you from pausing BizHawk, it just gives back control to BizHawk and won't return to the script until the frame advances (so the script is paused while BizHawk is paused)
Joined: 9/12/2014
Posts: 539
Location: Waterford, MI
brunovalads wrote:
InfamousKnight wrote:
What it's supposed to do is, when pressing the X button, y would be set to 116, touch at that location, increase by 1. If it reaches 200, it resets back to 116. This is used for aiming in the y axis.
If i understood correctly, let's say on frame 1 you press X, y will be set to 116, touch, then increse 1 (117 now), then the frame advance, what should happen? if you press X again it should touch at 117 then increase to 118? .
Yes, the idea is to use controls instead of the touch screen for aiming. 007 bloodstone ds uses the touch screen for aiming. The X,Y,A,B controls also move the player so they would have to be erased from the input log to prevent them from moving the player.
Editor, Player (174)
Joined: 4/7/2015
Posts: 331
Location: Porto Alegre, RS, Brazil
I suppose this would work:
Language: lua

local x = 106 local y = 116 while true do local btns = joypad.get() if btns["X"] == true then btns["Touch Y"] = y joypad.set(btns) y = y+1 end if y > 200 then y = 116 end emu.frameadvance() end
Tho i'm having issue with joypad.set(), it's kinda freezing the inputs forever.
Games are basically math with a visual representation of this math, that's why I make the scripts, to re-see games as math. My things: YouTube, GitHub, Pastebin, Twitter
Editor, Expert player (2072)
Joined: 6/15/2005
Posts: 3282
I'm not sure using joypad.get() in order to joypad.set() something else works as a rebinding option. (If I ever tried something like that in the past, I'm pretty sure it has never worked for me.) If all you want to do is rebind keyboard keys so that pressing them operates the touch screen, use input.get() to get which keyboard keys are pressed, then calculate how the touch screen should be operated and joypad.set() that.