User File #638476644181040600

Upload All User Files

#638476644181040600 - GBA Candy Land lua script

candy-land-search.lua
System: Game Boy Advance
49 downloads
Uploaded 4/2/2024 2:20 PM by Winslinator (see all 25)
Helps determine what title screen start frames yield the best RNG for a TAS.
--start tells the game what frame to press "Start" on the main menu; t is the frame after which the game is considered taking too long to play out and the next start frame should be tested
start = 585
t = 5675

while true do

	--read the active player's current position (a number between 1 and 134—the number of spaces on a Candy Land board)
	pos = mainmemory.read_u8(0x3C1C)
	
	--save a state every time the current start frame is encountered
	if emu.framecount() == start
	then
		savestate.saveslot(1)		
	end
	
	--The below just signals a bunch of inputs to register at specific frames to navigate through all the menus
	if (emu.framecount() == 477) or (emu.framecount() == start) or (emu.framecount() == start+40) or (emu.framecount() == start+41)
	then
		joypad.set({["Start"]=true})
	end
	if (emu.framecount() == 513) or (emu.framecount() == start+1) or (emu.framecount() == start+39) or (emu.framecount() == start+76) or (emu.framecount() == start+77) or (emu.framecount() == start+150) or (emu.framecount() == start+152) or (emu.framecount() == start+154) or (emu.framecount() == start+190) or (emu.framecount() == start+192) or (emu.framecount() == start+194) or (emu.framecount() == start+196)
	then
		joypad.set({["A"]=true})
	end
	if (emu.framecount() == start+113) or (emu.framecount() == start+114) or (emu.framecount() == start+153) or (emu.framecount() == start+155)
	then
		joypad.set({["Right"]=true})
	end
	
	--If either player has not reached the end by a certain time, reset and test the next start frame
	if emu.framecount() > t + 270
	then
		--If the position value still reads 0, that means "Candy Land" failed to initialize. There is therefore a problem with our menu navigation input sequence above; output the start frame and the text "FAIL" to signal that it needs to be fixed.
		if pos == 0
		then
			console.log(start,"FAIL")
		end
		start = start + 1
		savestate.loadslot(1)
	end
	
	--if any player reaches the final space, output the start frame and current frame, as it warrants further investigation
	if pos == 134
	then
		t = emu.framecount()
		console.log(start,t)
		start = start + 1
		savestate.loadslot(1)
	end
	
	emu.frameadvance()
end