Strange. I didn't see any thread about general purpose lua stuff here. I figure I'd create one.
In creation of this thread, I will start off by posting a quick script to help with handling the analog input using the main PSXjin window, instead of that clunky analog control window.
Download analog.luaLanguage: lua
local keys, lastkeys= input.get(),input.get()
local function UpdateKeys() lastkeys= keys; keys= input.get() end
local function Press(k) return keys[k] and (not lastkeys[k]) end
local function Limits(v,l,h) return math.max(math.min(v,h),l) end
local function GuiTextRight(x,y,t,c)
x= x - #tostring(t)*4
gui.text(x,y,t,c)
end
local CA= {
xleft= 128, xright= 128,
yleft= 128, yright= 128
}
local function ResetAnalog()
CA.xleft= 128; CA.xright= 128
CA.yleft= 128; CA.yright= 128
end
local StickyAnalog= true
local function HandleAnalog()
joypad.setanalog(1,CA)
if not StickyAnalog then ResetAnalog() end
end
emu.registerbefore(HandleAnalog)
local function ControlAnalog()
UpdateKeys()
if keys.leftclick then
CA.xleft= Limits(CA.xleft + keys.xmouse - lastkeys.xmouse, 0,255)
CA.yleft= Limits(CA.yleft + keys.ymouse - lastkeys.ymouse, 0,255)
gui.line(keys.xmouse,
keys.ymouse,
keys.xmouse - CA.xleft + 128,
keys.ymouse - CA.yleft + 128, 0x0040FFFF)
end
if keys.rightclick then
CA.xright= Limits(CA.xright + keys.xmouse - lastkeys.xmouse, 0,255)
CA.yright= Limits(CA.yright + keys.ymouse - lastkeys.ymouse, 0,255)
gui.line(keys.xmouse,
keys.ymouse,
keys.xmouse - CA.xright + 128,
keys.ymouse - CA.yright + 128, -0x00BFFF01)
end
if Press("insert") then StickyAnalog = not StickyAnalog end
if Press("delete") then ResetAnalog() end
local color= -0x00000001
if StickyAnalog then color= 0x00FF80FF end
GuiTextRight(70, 5,CA.xleft, color)
GuiTextRight(70,13,CA.yleft, color)
GuiTextRight(90, 5,CA.xright,color)
GuiTextRight(90,13,CA.yright,color)
end
gui.register(ControlAnalog)
while true do
emu.frameadvance()
end
Well... That was the main point of my creating this thread, to share this code. But an entire thread dedicated to this one thing felt out of place, so I'll make it a general-purpose thread instead.
So, uh... Someone find something to discuss...? I mainly wanted to share that code.