Post subject: How to strictly record input (no savestate) with FCEU
Joined: 1/8/2009
Posts: 3
I can't find any information that won't change the state of the game, but just do a simple macro without having to make the macro simple and press a button to do it over and over again, and even then, I can't find how to create a macro anywhere. I'm trying to help a friend play FF2 and in doing so, make a movie/macro that automatically makes the character input "a, a, b," so as to attack and cancel in battle. But so far I've only found out that the TAS editor records from the start, and I can't find any information about making a macro that can do this 100 times in succession (de-syncing wouldn't be much of a problem) without loading the state prior to, making the point of the movie moot. If anyone can help it would be appreciated.
Joined: 10/3/2005
Posts: 1332
I'm trying to help a friend play FF2 and in doing so, make a movie/macro that automatically makes the character input "a, a, b," so as to attack and cancel in battle.
I'd use Lua scripting for that. You'll need a recent version of FCEUX, if you don't have one. I understand what the sequence "a, a, b" is for, so I wrote a script to generate the inputs:
--ff2grind.lua
function frameadvance(frames)
  for i = 0, frames or 1 do
	joypad.set(1, joy1)
    FCEU.frameadvance()
	joy1.A = nil
	joy1.B = nil
  end
end

joy1 = {}
for loops = 1, 100 do
  FCEU.speedmode("maximum")
  joy1.A = true
  frameadvance(8)
  joy1.A = true
  frameadvance(42)
  joy1.B = true
  frameadvance(45)
  FCEU.speedmode("normal")
end
Run it in battle and the guy will target an enemy, then the next person cancels. This repeats 100 times, as requested.
Joined: 1/8/2009
Posts: 3
Wow, I didn't think Lua could actually do something like that so conveniently. I'm gonna test it out, and thanks a lot. I think if I look into it a bit more I might be able to set something up for grinding a spell as well, assuming I can read enough into what programming is written there. :D Thanks a lot, a huge help.
Joined: 10/3/2005
Posts: 1332
That code was to give you the basic function, but I wouldn't advise trying to build upon it. Here's something more usable:
--ff2macro.lua
function frameadvance(frames)
	for i = 0, frames or 1 do
		joypad.set(1, joy)
		FCEU.frameadvance()
		joy = {}
	end
end

function press(button, frames)
	joy[button] = true
	frameadvance(30)
end

joy = {}

FCEU.speedmode("maximum")
for loop = 1, 100 do
	press("down")
	press("down")
	press("A")
	frameadvance(20)
	press("A")
	press("A")
	frameadvance(55)
	press("B")
end
FCEU.speedmode("normal")
This script selects the topmost spell in a character's magic collection, targets something with it, cancels the next character's turn, and repeats. As you can probably guess, the "press" function taps any button, and waits for a half-second. A half-second is usually enough of a delay to let the game get ready for more input, but sometimes you need to add more delay with 'frameadvance'. You should be able to use these functions to construct a wide variety of macros. Don't forget to comment out the speedmode("maximum") line when testing.
Banned User
Joined: 12/23/2004
Posts: 1850
Edit: Feh. Nevermind, Dromiceius made this post worthless.
function frameadvance(frames)
    for i = 0, frames or 1 do
		joypad.set(1, joy1)         -- input to use, first frame only
		FCEU.frameadvance()
		joy1.A = nil                -- clears input.
		joy1.B = nil                -- clears input.
    end
end

joy1 = {}
FCEU.speedmode("maximum")
for loops = 1, 100 do
    joy1.A = true       -- button to push for first frame
    frameadvance(8)     -- advance this many frames AFTER pushing button
    joy1.A = true       -- etc
    frameadvance(42)    -- etc
    joy1.B = true       -- etc
    frameadvance(45)    -- etc
end
FCEU.speedmode("normal")
Now commented. In fact, if you wanted, you could even change "for loops = ..." to "while true do" and add "FCEU.pause()" before the final end; after every loop, it would automatically pause, so you could either decide to keep going or end the script.
Perma-banned
Joined: 1/8/2009
Posts: 3
Thanks a whole lot, I haven't put much look into Lua, but indeed, after seeing how a supported game platform can use it, (as well as the help of some of your videos on youtube as well, Xkeeper) I think I can assume it might prove some fun to fool around with on a game I'm looking into speedrunning (TAS and non-TAS) and mucking around with, Little Nemo: Dream Master. Thanks a lot for all of your help, (I also realized I had to download and place the DLL into FCEUX's directory after a moment of clarity.) and I appreciate the quick reply for such a kind of small thing. I figured something like a movie would work, due to my experience stemming from older movie-based recorders like the ones with Nesticle and Gens, but those were pretty unstable too, so I think this is far more accurate to what I'm looking for, and not difficult either. Thanks again.