Post subject: Need help on lua scripting "pausing the script"
alchemistake
He/Him
Joined: 1/12/2017
Posts: 4
First of all I am total noob on lua and bizhawk right now but I am a good CS student, I know some stuff. I am brute forcing for a save password on a game. As you know brute forcing takes very long time. I want to be able to "pause the script" save the state of the script on a text file, without creating any extra weight to script. Polling for input on each frame was bogging me down from ~240FPS to ~100FPS. Side question, how can I force BizHawk to go over x4 speed?
Amaraticando
It/Its
Editor, Player (158)
Joined: 1/10/2012
Posts: 673
Location: Brazil
Post your script so we can try to figure out a sane way of saving its state.
alchemistake
He/Him
Joined: 1/12/2017
Posts: 4
I didn't finished the script yet, but the idea is that there will be nested loops and I want to store the indices of the loops when I stop the script to do something else with my computer. But basically code is this:
for i=0,60, 1
do
  typeChar(i)
  savestate.saveslot(1)
  for j=0,60, 1
  do
    savestate.loadslot(1)
    typeChar(i)
    savestate.saveslot(2)
    for k=0,60, 1
    do
      savestate.loadslot(2)
      typeChar(i)
      submitTheCode()
    end
  end
end
I want to get i,j,k if something happens to the script (for example unexpected shutdown).
Site Admin, Skilled player (1237)
Joined: 4/17/2010
Posts: 11280
Location: RU
Try event.onexit()
string event.onexit(func luaf, [string name = null])

Fires after the calling script has stopped
Declare the vars outside the loops and store them to a file when the script dies. Dunno if it will work upon emulator crash though, probably not. To insure against that you'd have to constantly dump the numbers to a file (probably overwriting the old ones). And you don't have to specify the step being 1, since it's default.
Warning: When making decisions, I try to collect as much data as possible before actually deciding. I try to abstract away and see the principles behind real world events and people's opinions. I try to generalize them and turn into something clear and reusable. I hate depending on unpredictable and having to make lottery guesses. Any problem can be solved by systems thinking and acting.
alchemistake
He/Him
Joined: 1/12/2017
Posts: 4
Thank you all for your help.
Amaraticando
It/Its
Editor, Player (158)
Joined: 1/10/2012
Posts: 673
Location: Brazil
I made a model that, yet a little hacky due to lack of testing, seems to work fine. There're a few debug prints that you can remove and I tested it without your hidden functions. At least one of them must include emu.frameadvance(), I guess. http://pastebin.com/5XftaV1c