1 2
10 11 12 13 14
Editor, Player (132)
Joined: 4/7/2015
Posts: 328
Location: Porto Alegre, RS, Brazil
feos wrote:
client.pause_av()
Yea I would suggest that, with something like this (I took Yoshi's Island for example)
Language: lua

local prevent_1st_frame = true local is_paused_prev -- to call client.pause_av()/unpause_av() only once when pausing/unpausing the game local is_paused while true do is_paused = mainmemory.read_u8(0x0B10) == 1 -- Yoshi's Island (Snes) pause flag if not prevent_1st_frame then if is_paused and is_paused ~= is_paused_prev then client.pause_av() end if not is_paused and is_paused ~= is_paused_prev then client.unpause_av() end end prevent_1st_frame = false is_paused_prev = is_paused emu.frameadvance() end
Note: you can't start capturing with this, you must do this manually first. In theory it should pause the A/V capture when I pause the game, and unpause the capture when I unpause the game. But it's not working well, it pauses the capture and do not return capturing when client.unpause_av() is called, it crashes instead. Update: opened an issue.
Games are basically math with a visual representation of this math, that's why I make the scripts, to re-see games as math. My things: YouTube, GitHub, Pastebin, Twitter
Site Admin, Skilled player (1234)
Joined: 4/17/2010
Posts: 11251
Location: RU
Make a bug ticket.
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.
Editor, Expert player (2310)
Joined: 5/15/2007
Posts: 3854
Location: Germany
I noticed a problem with my time calculation script. At 60 FPS it seems to work properly, but at 59.7275005696058 FPS, it will output 178 frames -> 2.97 179 frames -> 3.99 180 frames -> 3.01
Language: Lua

local totimeseconds = function(frames,fps) hours = math.floor((frames/fps)/3600) mins = math.floor((frames/fps)/60)%60 secs = math.floor(((frames/fps-mins*60)*100+0.5)/100) %60 ms = (frames % fps)/60 * 100 returnvalue = string.format("%02d.%02d",secs,ms) return returnvalue end
Could someone give me a script that correctly outputs the time in min:sec.ms format? Thanks
Masterjun
He/Him
Site Developer, Skilled player (1968)
Joined: 10/12/2010
Posts: 1179
Location: Germany
You want to do the rounding you do at secs everywhere, otherwise only one of the values gets rounded and the other one is off (as you have seen). So just introduce a new variable where all other values are calculated from.
Language: lua

local function totimeseconds(frames,fps) ---- option 1, cutting off: ---- 2.994 -> 2.99 ---- 2.996 -> 2.99 --local fullsecs = frames/fps ---- option 2, rounding at half steps: ---- 2.994 -> 2.99 ---- 2.996 -> 3.00 local fullsecs = math.floor(((frames/fps)*100)+0.5)/100 local hours = math.floor(fullsecs/3600) local mins = math.floor(fullsecs/60)%60 local secs = math.floor(fullsecs%60) local ms = math.floor(fullsecs*100)%100 return string.format("%02d:%02d:%02d.%02d",hours,mins,secs,ms) end
At 59.7275005696058 FPS it will give proper results: 178 frames -> (2.9802... seconds) -> 00:00:02.98 179 frames -> (2.9969... seconds) -> 00:00:03.00 180 frames -> (3.0136... seconds) -> 00:00:03.01
Warning: Might glitch to credits I will finish this ACE soon as possible (or will I?)
Editor, Expert player (2310)
Joined: 5/15/2007
Posts: 3854
Location: Germany
Thanks Masterjun, I could make my comparison video thanks to your quick help!
Editor, Expert player (2310)
Joined: 5/15/2007
Posts: 3854
Location: Germany
How can I add days to Masterjun's code?
Patashu
He/Him
Joined: 10/2/2005
Posts: 4000
I think this is correct:
Language: lua

local function totimeseconds(frames,fps) ---- option 1, cutting off: ---- 2.994 -> 2.99 ---- 2.996 -> 2.99 --local fullsecs = frames/fps ---- option 2, rounding at half steps: ---- 2.994 -> 2.99 ---- 2.996 -> 3.00 local fullsecs = math.floor(((frames/fps)*100)+0.5)/100 local days = math.floor(fullsecs/(3600*24)) local hours = math.floor(fullsecs/3600)%24 local mins = math.floor(fullsecs/60)%60 local secs = math.floor(fullsecs%60) local ms = math.floor(fullsecs*100)%100 return string.format("%02d:%02d:%02d:%02d.%02d",days,hours,mins,secs,ms) end
My Chiptune music, made in Famitracker: http://soundcloud.com/patashu My twitch. I stream mostly shmups & rhythm games http://twitch.tv/patashu My youtube, again shmups and rhythm games and misc stuff: http://youtube.com/user/patashu
Joined: 9/12/2014
Posts: 535
Location: Waterford, MI
Hey guys, I made this old script to manipulate rng by paying attention to the screen for the result and I don't know what to change for it to work in bizhawk:
local HPAddr=0x0B2
local HP
local num=true
save1 = savestate.create()
savestate.save(save1)
while num do
 HP=memory.readword(HPAddr)
 if HP == 100 then
   savestate.load(save1)
   emu.frameadvance()
   savestate.save(save1)
 end
 print(HP)
 joypad.set(1,{A=true})
 emu.frameadvance()
 emu.frameadvance()
end
It says the create function doesn't exist. Its a simple script used to brute force frame based rng in a turn based game.
Amaraticando
It/Its
Editor, Player (157)
Joined: 1/10/2012
Posts: 673
Location: Brazil
It seems your previous emulator had a function to create a new savestate object prior to use. In BizHawk, you simply save and/or load states from filepaths or numbers.
savestate.load void savestate.load(string path) Loads a savestate with the given path savestate.loadslot void savestate.loadslot(int slotnum) Loads the savestate at the given slot number (must be an integer between 0 and 9) savestate.save void savestate.save(string path) Saves a state at the given path savestate.saveslot void savestate.saveslot(int slotnum) Saves a state at the given save slot (must be an integer between 0 and 9)
http://tasvideos.org/Bizhawk/LuaFunctions.html So, simply reserve a slotnumber or file for usage, instead of "save1".
Darth_Marios
He/Him
Joined: 5/11/2015
Posts: 106
Its possible to pause (not stop) a playback at a specific frames with a lua script? If yes, how?
Amaraticando
It/Its
Editor, Player (157)
Joined: 1/10/2012
Posts: 673
Location: Brazil
I can't test, but the doc says: You can pause by issuing client.pause() You can verify the current frame with emu.framecount().
Lil_Gecko
He/Him
Player (94)
Joined: 4/7/2011
Posts: 520
Yes I've used it many times so I can confirm.
if emu.framecount() == whatevernumberyouwant then client.pause()
else emu.frameadvance()
end;
Darth_Marios
He/Him
Joined: 5/11/2015
Posts: 106
So - since im a bit noob about lua scripting - how the script would like? For instance, if we have 10.000 frames playback, and i want to stop it at 5.000, how would it be? And i can repeat the script to pause on other frames too? (if i want to pause it at 7.000 frames fater the first pause at 5.000 for example)
Skilled player (1703)
Joined: 9/17/2009
Posts: 4952
Location: ̶C̶a̶n̶a̶d̶a̶ "Kanatah"
Given numbers in Lua are only 64 bit for BizHawk, how does one "simulate" signed 16/32 bit operations? I'm supposed to do this:
Shift the 11-bit signed offset of the instruction left one bit. Sign-extend the result to 32 bits Adding this to the contents of the PC (which contains the address of the branch instruction plus 4).
However, using
bit11 = bit.check(result,11) and 1 or 0
if bit11 == 1 then
		for i = 13,31 do
			result = bit.set(result,i)
		end
end
Gave a 64 bit binary number (or in another words, a very large number). How would I set the number size in lua, or at least simulate a smaller number size? Edit: Example: Number was 0x7F8 (0111 1111 1000) Shift left gives 0xFF0 (1111 1111 0000) Sign extend this (making bits 12-31 == 1) on a calculator gives: 0xFFFF FFF0 (1111 1111 1111 1111 1111 1111 1111 0000‬) which is -16. In lua, it instead gives 4294967282 (32 0's followed by 1111 1111 1111 1111 1111 1111 1111 0000). I know I can naively just make it extend to 64 bits, but is there a better way to do that independent of the underlying default lua integer type? Edit2: Right now, came up with this thing:
local result = bit.lshift(Offset11, 1)
if bit.check(result, 11) then
	result = bit.bor(-4096,result)	--writing as 0xFFFF FFFF FFFF F000 doesn't work
	result = result - 0x100000000	--??
end
This looks incomprehensible in comparison to sign extension. Any better generalized way to do this? Generalized as in works for other integer sizes.
Lil_Gecko
He/Him
Player (94)
Joined: 4/7/2011
Posts: 520
Darth Marios wrote:
So - since im a bit noob about lua scripting - how the script would like? For instance, if we have 10.000 frames playback, and i want to stop it at 5.000, how would it be? And i can repeat the script to pause on other frames too? (if i want to pause it at 7.000 frames fater the first pause at 5.000 for example)
Language: lua

while true do if emu.framecount() == 5000 or emu.framecount() == 12000 then client.pause(); end; emu.frameadvance(); end;
EDIT : As an alternative, if there's many points you want to pause you can do :
Language: lua

t={5000,12000,22000,34000,41000}; -- add as many frames as you want a=#t; while true do for i=0,a do if emu.framecount() == t[i] then client.pause(); end; end; emu.frameadvance(); end;
Editor, Expert player (2310)
Joined: 5/15/2007
Posts: 3854
Location: Germany
#t
table.getn(t)
Are these two the same? If not, which has better performance?
Masterjun
He/Him
Site Developer, Skilled player (1968)
Joined: 10/12/2010
Posts: 1179
Location: Germany
The only Lua version where both the # operator and the table.getn function exist is 5.1. They both do the same thing. In future versions, only the # operator can be used (because the table.getn function is deprecated and was only left in for compatibility).
Warning: Might glitch to credits I will finish this ACE soon as possible (or will I?)
Editor, Expert player (2310)
Joined: 5/15/2007
Posts: 3854
Location: Germany
For my love2d project I need a function that checks if a bit is set in a hex number. It needs to be a pure Lua implementation (Lua 5.1). The lua documentation wasn't much help so far. (...) Edit: Nevermind, found a solution which was listed on that linked page.
function bit(p)
  return 2 ^ (p - 1)  -- 1-based indexing
end

-- Typical call:  if hasbit(x, bit(3)) then ...
function hasbit(x, p)
  return x % (p + p) >= p       
end
CrazyTerabyte
He/Him
Joined: 5/7/2005
Posts: 74
MUGG wrote:
For my love2d project I need a function that checks if a bit is set in a hex number. It needs to be a pure Lua implementation (Lua 5.1). The lua documentation wasn't much help so far. (...)
There is a simple solution, using bitwise arithmetic (the same solution can be implemented in essentially any programming language):
function hasbit(number, bit)
  return (number & (1 << bit)) ~= 0
end
If you do a bitwise-AND between two numbers, only the bits that were set on both inputs will be set on the output. In special, if you do AND against a number that only has one bit set, then effectively you are testing that single bit. If the result is zero, that bit was zero; otherwise that bit was one. And how can you address one single bit? By powers of 2, which can be written by exponentiation or by doing doing bit shifts.
2**0  ==  1 << 0  == 1
2**1  ==  1 << 1  == 2
2**2  ==  1 << 2  == 4
2**3  ==  1 << 3  == 8
2**4  ==  1 << 4  == 16
...
If you are curious to learn more, watch this video: https://www.youtube.com/watch?v=F8kx56OZQhg And have fun while coding! :)
Masterjun
He/Him
Site Developer, Skilled player (1968)
Joined: 10/12/2010
Posts: 1179
Location: Germany
CrazyTerabyte wrote:
MUGG wrote:
For my love2d project I need a function that checks if a bit is set in a hex number. It needs to be a pure Lua implementation (Lua 5.1). The lua documentation wasn't much help so far. (...)
There is a simple solution, using bitwise arithmetic
For reference, Lua 5.1 doesn't have bitwise operators (they were implemented in Lua 5.3). So the two functions MUGG posted are the workaround for that. At the end it's the same solution.
Warning: Might glitch to credits I will finish this ACE soon as possible (or will I?)
CrazyTerabyte
He/Him
Joined: 5/7/2005
Posts: 74
Masterjun wrote:
For reference, Lua 5.1 doesn't have bitwise operators (they were implemented in Lua 5.3). So the two functions MUGG posted are the workaround for that. At the end it's the same solution.
Oops, my mistake, I should have checked, sorry about that!
Joined: 11/4/2015
Posts: 3
I made a lua script for Majora's Mask that does various things (Items/Invincibility/Infinite Jump). One of the things that you can do is be able to see which Heart Pieces that you've picked up, which is useful if you're like me and you forget where they all are or forget which ones you've picked up or if you've taken a break and come back and don't remember what you've done. https://pastebin.com/K6EUMhy7
Joined: 9/12/2014
Posts: 535
Location: Waterford, MI
Hello, does anyone know of a way to attach camera angle to the car bumper? For instance, in the toca tas, when you turn, the camera slowly catches up. I would like to see it stay on the back side as I find it more amusing. Will this cause desyncs though? Im not very good with finding memory addresses. But I would imagine this is more than just finding the x y z address for both the car and the camera. Anyone know where to start?
Player (146)
Joined: 5/9/2011
Posts: 25
mainmemory.readbyterange nluatable mainmemory.readbyterange(int addr, int length) Reads the address range that starts from address, and is length long. Returns the result into a table of key value pairs (where the address is the key).
Was trying to load and print an array using bizhawk's readbyterange. Was unable to do so until i tried printing the keys. The documentation appears to be incorrect. rng_state = mainmemory.readbyterange(0x02D1, 16) The keys here are 0-15 and not 0x02D1-0x02E0, as the documentation seems to indicate.
Editor, Expert player (2310)
Joined: 5/15/2007
Posts: 3854
Location: Germany
I need a script that reads lines in text file A.txt, and checks if they are present in text file B.txt. If not, the lines are deleted from A.txt. I figured someone good can come up with a solution in 1 min so I don't have to spend 30 mins working on it. :P Thanks in advance.
1 2
10 11 12 13 14