Post subject: Either I'm extremely unlucky, or I'm bad with Lua scripts
Joined: 11/1/2009
Posts: 10
I was trying to make a SMW wall jump bruteforcer Lua script, and I wrote this script:
local sav
sav = savestate.create()
savestate.save(sav)
local groundflag
groundflag = memory.readbyte(0x0077) --0x0077 checks if on ground
local xvel --0x007B
xvel = memory.readbyte(0x007B)
local yvel --0x007D
yvel = memory.readbyte(0x007D)
local input
while (yvel~=6 or yvel~=3) and groundflag<=2 do --if not on ground
	ran=math.random(2) --pick either 1 or 2
	if(ran~=1) then --if it's 1
		input = {B=true} --press B that frame
	else --if not
		input = {} --don't press B
	end
	joypad.set(1, input)
	groundflag = memory.readbyte(0x0077) --reread variables each frame
	xvel = memory.readbyte(0x007B)
	yvel = memory.readbyte(0x007D)
	if(xvel==0) then --if hit wall
		if yvel~=6 or yvel~=3 then --if not cling wall
			savestate.load(sav) --load state
		else --if cling wall
			snes9x.pause() --pause emulator
		end
	end
	snes9x.frameadvance() --advance 1 frame and go to beginning of loop
end
However, when I run the script it never pauses the emulator, which means I never managed to cling the wall. Am I doing something wrong here? I'm using Snes9x1.51v6
marzojr
He/Him
Experienced player (749)
Joined: 9/29/2008
Posts: 964
Location: 🇫🇷 France
Try putting a return after this line:
         snes9x.pause() --pause emulator
Marzo Junior
Joined: 11/1/2009
Posts: 10
marzojr wrote:
Try putting a return after this line:
         snes9x.pause() --pause emulator
I didn't see how that would help, but I tried anyway, and it didn't do anything. Also, could it be that I'm taking a completely wrong approach to this?
Joined: 10/3/2005
Posts: 1332
Your code looks basically correct, so you're probably making an erroneous assumption about how the game works. If I were in your shoes, I'd try commenting out the savestate.load line, and see if the snes9x.pause branch executes later than you expected. Edit: better yet, replace savestate.load with this:
gui.text(8,8, xvel .. " " .. yvel)
And frame-advance through the execution about where you expect the walljump is supposed to happen. Editedit: and of course, check the SMW wiki page if you haven't already.
Joined: 11/1/2009
Posts: 10
Dromiceius wrote:
Edit: better yet, replace savestate.load with this:
gui.text(8,8, xvel .. " " .. yvel)
And frame-advance through the execution about where you expect the walljump is supposed to happen.
Thanks for that. Turns out I'm taking the wrong approach since I'm never able to cling the wall. So yeah, this problem is pretty much solved.