Joined: 4/7/2015
Posts: 331
Location: Porto Alegre, RS, Brazil
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
Joined: 4/17/2010
Posts: 11495
Location: Lake Chargoggagoggmanchauggagoggchaubunagungamaugg
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.
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
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 creditsI will finish this ACE soon as possible
(or will I?)
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
Joined: 9/12/2014
Posts: 543
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.
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.
http://tasvideos.org/Bizhawk/LuaFunctions.html
So, simply reserve a slotnumber or file for usage, instead of "save1".
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)
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:
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.
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;
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 creditsI will finish this ACE soon as possible
(or will I?)
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
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.
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 creditsI will finish this ACE soon as possible
(or will I?)
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.
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: 543
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?
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.
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.