1 2 3 4 5
13 14
Skilled player (1741)
Joined: 9/17/2009
Posts: 4981
Location: ̶C̶a̶n̶a̶d̶a̶ "Kanatah"
FractalFusion wrote:
jlun2 wrote:
But even after changing the code to this: http://pastebin.com/0eEhyNqW No input is ever set even if the statement was reached: http://i.imgur.com/SZ192E3.png
The line that says
joypad.set({left = 1}) 
should be
joypad.set({Left = true}) 
instead.
Worked now. Thanks! Sorry for the bother.
Site Admin, Skilled player (1254)
Joined: 4/17/2010
Posts: 11478
Location: Lake Char­gogg­a­gogg­man­chaugg­a­gogg­chau­bun­a­gung­a­maugg
The game is Gargoyles, but it can be easily tweaked for any other. Doesn't work outside tastudio, because for normal savestates it needs another (working as well) function - userdata.get/set. Only for the latest interim. Download TastudioCustomLagCounter.lua
Language: lua

laglog = {} function ColorCallback(index, name) if laglog[index]~=nil and name=="MarkerColumn" then return "Red" end end function Lag() local lagcount = 0 local lag = (memory.readbyte(0xF6D4)==0) local frame = emu.framecount() if lag==true then laglog[frame] = true else laglog[frame] = nil end for i=0,frame do if laglog[i]~=nil then lagcount = lagcount+1 end end gui.text(0,48,"Lag: "..lagcount,"black","red") end tastudio.onqueryitembg(ColorCallback) while true do Lag() emu.frameadvance() end
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.
Yagisama
He/Him
Joined: 7/12/2015
Posts: 2
Hello I'm trying to write a simple lua script for Link's Awakening DX that shows the X & Y coordinates on screen but I keep getting an error saying: "Warning: attempted read of 65432 outside the memory size of 32768." Can anyone give me some tips for solving this? I haven't done any kind of programming in years so I'm a bit rusty.
Language: lua

function gameInfo() xcord = memory.readbyte(0xFF98) gui.drawText(5, 5, "X: " .. xcord) end while true do gameInfo() emu.frameadvance() end
Pokota
He/Him
Joined: 2/5/2014
Posts: 779
Memory addresses in BizHawk are relative to the start of the domain (unlike basically every other emulator out there). Say your address in Visual Boy Advance is 0x9234. Bizhawk sees that as being GB WRAM, which has a root offset of 0x8000 - to get the final address that BizHawk can manipulate, you have to remove 0x8000 from the VBA address. That would give you GB WRAM 0x1234. If the address you're trying to work with isn't in the default domain, you'll need to tell the code to change domains. My earlier RNG Strobe has an example of doing that. It looks like the address you're after is going to be HRAM 0x18, so you'll need to do this:
Language: lua

local HRAM = "HRAM" function gameInfo() memory.usememorydomain(HRAM) xcord = memory.readbyte(0x18) gui.drawText(5, 5, "X: " .. xcord) end while true do gameInfo() emu.frameadvance() end
Adventures in Lua When did I get a vest?
Yagisama
He/Him
Joined: 7/12/2015
Posts: 2
Thank you Pokota! I have no idea what you just told me or what I did, but it works like a charm. Are there any good articles around about this different memory domains? As glad as I am that it's working now I always like to know why and how it works in the end.
Editor, Emulator Coder
Joined: 8/7/2008
Posts: 1156
CrazyTerabyte
He/Him
Joined: 5/7/2005
Posts: 74
I don't know of any specific tutorial or article about it, but it is common design for several pieces of hardware. Let's imagine an hypothetical hardware with 2KB of RAM and 2KB of video memory. In this imaginary hardware, the CPU has a 16-bit address space, which means it can address at most 65536 addresses (on most architectures, each address contains a single byte; but it is possible to design hardware where each address contains whatever amount is convenient). However, even though 64KB is the maximum addressable memory, only 2KB of RAM is actually installed (for whatever reason). What do we do with the remaining 62K addresses? Well, we can map other pieces of the hardware into the same address space. We can map the sound chip in there. We can map the video memory in there. We can map the cartridge ROM in there. We can map the expansion slot in there. So, in this imaginary hardware, we can say we have 2KB of main RAM, which is mapped from position 0 to position 2K; and we have 2KB of video RAM, which is mapped (almost arbitrarily) from position 8K to 10K. This means the second VRAM address is actually the (8K+2)th address in the address space. This also means that when the CPU reads/writes the address 9K, it is actually accessing the address 1K from the VRAM. (Why mapping the VRAM at 8K? Because the people who designed this imaginary hardware chose so. It could have been at 16K, at 4K, or almost anywhere else.) I hope you could follow this description of this imaginary hardware. You will find out that several pieces of hardware (microcontrollers, video-games…) have the same design principles. And just remember that we are talking binary here: 1K means 1024, 2K means 2048,…
Pokota
He/Him
Joined: 2/5/2014
Posts: 779
I'm working on converting Xkeeper's Link's Awakening lua script (and by extension the X-functions resource script) for use with BizHawk, but my ignorance is showing - the version of X-functions I'm forking off of has readword in it, what size does/should that correspond with? E: Never mind; what's in X-functions is just a 2-byte read from what I'm seeing, it's easy enough to replace that out. Okay new problem - I'm getting an exception when I try to run the script that points to line 29 of the Link's Awakening script, but I don't see how evaluating a boolean in an if statement corresponds to "invalid arguments to method call" - does it think nohotkeys is a method? (It's line 30 in what I'm working off of since I inserted memory.usememorydomain("System Bus") as line 2)
Adventures in Lua When did I get a vest?
Skilled player (1741)
Joined: 9/17/2009
Posts: 4981
Location: ̶C̶a̶n̶a̶d̶a̶ "Kanatah"
Regarding lua if statements, are there any ways to compare if 2 conditions are at 2 different values other than a large amount of "and/or"s? Currently, I'm doing something like:
if (memory.readbyte(lift[1]) ~= 2 or memory.readbyte(lift[2]) ~= 2 or memory.readbyte(lift[3]) ~= 2 or memory.readbyte(lift[4]) ~= 2 or memory.readbyte(lift[5]) ~= 2 or memory.readbyte(lift[6]) ~= 2) and (memory.readbyte(lift[1]) == 7 or memory.readbyte(lift[7]) == 7 or memory.readbyte(lift[3]) == 7 or memory.readbyte(lift[4]) == 7 or memory.readbyte(lift[5]) == 7 or memory.readbyte(lift[6]) == 7) then
and it looks really messy and hard to read.
Pokota
He/Him
Joined: 2/5/2014
Posts: 779
You probably should section those tests off into their own functions and test iteratively since you're going through 1-6 in order. Pseudocode below E: Looking back you'll also need to embed another if statement into the loops so that you're skipping over lift[2] when you test for 7, so that'll look like
function test_for_not_2() as boolean
for i, 1, 6
    if (readbyte(lift[i]) ~=2)
        return true
    else
        return false
    end if 
end for
end function

function test_for_7() as boolean
for i, 1, 7
    if i ~= 2
        if (readbyte(lift[i]) == 7) 
            return true
        else
            return false
        end if
    end if
end for
end function

if ((test_for_not2() == true) and (test_for_7() == true) then
    do a thing
end if 
This should stop each test as soon as it finds a true, but from what I'm seeing you just need one of each anyway. E: does Lua do type declarations for functions? I forget.
Adventures in Lua When did I get a vest?
Editor, Player (54)
Joined: 12/25/2004
Posts: 634
Location: Aguascalientes, Mexico
jlun2 wrote:
Regarding lua if statements, are there any ways to compare if 2 conditions are at 2 different values other than a large amount of "and/or"s? Currently, I'm doing something like:
if (memory.readbyte(lift[1]) ~= 2 or memory.readbyte(lift[2]) ~= 2 or memory.readbyte(lift[3]) ~= 2 or memory.readbyte(lift[4]) ~= 2 or memory.readbyte(lift[5]) ~= 2 or memory.readbyte(lift[6]) ~= 2) and (memory.readbyte(lift[1]) == 7 or memory.readbyte(lift[7]) == 7 or memory.readbyte(lift[3]) == 7 or memory.readbyte(lift[4]) == 7 or memory.readbyte(lift[5]) == 7 or memory.readbyte(lift[6]) == 7) then
and it looks really messy and hard to read.
I don't understand why you are comparing if address is not a 2 but later if is a 7. If it's a 7 it cannot be a 2 (so the first part makes no sense to me), or are you trying to compare the bits?
I'm the best in the Universe! Remember that!
Skilled player (1741)
Joined: 9/17/2009
Posts: 4981
Location: ̶C̶a̶n̶a̶d̶a̶ "Kanatah"
samurai goroh wrote:
I don't understand why you are comparing if address is not a 2 but later if is a 7. If it's a 7 it cannot be a 2 (so the first part makes no sense to me), or are you trying to compare the bits?
Er...oops. Here's a different part that probably shows off what I meant better:
if (memory.readbyte(lift[1]) == 6 or memory.readbyte(lift[2]) == 6 or memory.readbyte(lift[3]) == 6 or memory.readbyte(lift[4]) == 6 or memory.readbyte(lift[5]) == 6 or memory.readbyte(lift[6]) == 6) and (memory.readbyte(lift[1]) == 1 or memory.readbyte(lift[2]) == 1 or memory.readbyte(lift[3]) == 1 or memory.readbyte(lift[4]) == 1 or memory.readbyte(lift[5]) == 1 or memory.readbyte(lift[6]) == 1) then
Also, thanks Pokota for your suggestion!
Pokota
He/Him
Joined: 2/5/2014
Posts: 779
Samurai Goroh: That first one's not an invalid test - if any of the entries are a 2 (except for entry 7), then it can't succeed, and at least one entry that isn't entry 2 has to be a 7 for it to succeed. jlun2: That second one is actually one if easier than the first one since you're not jumping around in the array - it can be done with just one function.
--this code doesn't actually work, by the way, or at the very least doesn't work as intended.
function test_is_present(array array, int target) as Boolean
for each i in array,
    if (readbyte(array[i]) == target) then
        return true
    else
        return false
    end if
end for 
end function

if ((test_is_present(lift, 1) == true) and (test_is_present(lift, 6) == true)) then
    magic()
end if
and you just flip a true to a false in the if around magic if you need the tested value to not be there.
Adventures in Lua When did I get a vest?
Editor, Player (54)
Joined: 12/25/2004
Posts: 634
Location: Aguascalientes, Mexico
Oh right, I was reading it as all values on the list must be true, but it's any of them (probably got confused with the AND between the 2 values and ignored the OR) But shouldn't the code be more like:
local function test(lift, value)
    local result = false
    for each i in lift do
        if memory.readbyte(lift[i]) == value then
            result = true
            break
        end
    end
    return result
end

if ( test(lift, 1) and test(lift, 6) ) then
    --Insert code here
end
I'm the best in the Universe! Remember that!
Pokota
He/Him
Joined: 2/5/2014
Posts: 779
Ah crap, you're right. How I wrote it would break without iterating if it ever comes up false, which isn't the desired behavior. This is what I get for writing code without testing it.
Adventures in Lua When did I get a vest?
Masterjun
He/Him
Site Developer, Skilled player (1988)
Joined: 10/12/2010
Posts: 1185
Location: Germany
This is for all the people that don't like the default font. I made these two functions (just copy paste them in your code) which is adding a black border around your text, so you can see it better. But: This increases the amount of text calls by a factor of 9, so don't spam it (though, I didn't have any problems, to be honest).
Warning: Might glitch to credits I will finish this ACE soon as possible (or will I?)
creaothceann
He/Him
Editor
Joined: 4/7/2005
Posts: 1874
Location: Germany
Masterjun wrote:
increases the amount of text calls by a factor of 9
How about increasing the background font a bit and moving it so that it's centered in the actual text? It won't look perfect but that's not really needed here imo.
Active player (476)
Joined: 2/1/2014
Posts: 928
Been trying to help DwangoAC out but now I need your guys' help.
        [LuaMethodAttributes(
            "openmovie",
            "opens the Movie selected"
        )]
        public static bool OpenMovie(string path)
        {
            if (path != "")
            {
                if (MovieService.IsValidMovieExtension(path))
                {
                    GlobalWin.MainForm.LoadMoviesFromRecent(path);
                    return true;
                }
                else if (MovieImport.IsValidMovieExtension(Path.GetExtension(path)))
                {
                    string errorMsg;
                    string warningMsg;
                    var movie = MovieImport.ImportFile(path, out errorMsg, out warningMsg);
                    if (!string.IsNullOrEmpty(errorMsg))
                    {
                        // TODO: Lua console print: conversion error
                        return false;
                    }
                    else
                    {
                        GlobalWin.MainForm.StartNewMovie(movie, false);
                        return true;
                    }
                }
                else
                {
                    // TODO: Not a valid Movie
                    return false;
                }
            }
            return false;
        }
I wrote this function within BizHawk to deal with automatically loading the movie files (since there would be multiple movie files to run within a single directory). And My LUA script:
client.openrom("C:\\Users\\Mike\\Desktop\\[GameName]")
BasePath = "C:\\Users\\Mike\\Desktop\\Test\\"
for dir in io.popen([[dir "C:\Users\Mike\Desktop\Test" /b]]):lines() do 

-- play movie, (turbo, disable rewind, high frame skip), check address

	FullPath = (BasePath .. dir)
	console.writeline(FullPath)
	
	isSingleMovieLoaded = client.openmovie(FullPath)
	while isSingleMovieLoaded == false do
		-- wait??
	end
        -- now we're good to proceed.
	while movie.isloaded == true do
		writeLog("good.\n");
			if memory.read_u8(0x2C) == 1 then
				client.pause()
                                -- if address found, grab framecount and dir and write it to judging table
	                        -- emu.framecount
			end
		emu.frameadvance()
	end

	-- movie.stop
end
Right now, it just goes through all the files and thats it. I would like it to speed through a single movie file at a time and wait until the movie is loaded then unpause or start advancing frames.
Masterjun
He/Him
Site Developer, Skilled player (1988)
Joined: 10/12/2010
Posts: 1185
Location: Germany
creaothceann wrote:
Masterjun wrote:
increases the amount of text calls by a factor of 9
How about increasing the background font a bit and moving it so that it's centered in the actual text? It won't look perfect but that's not really needed here imo.
Increasing font size only works with gui.drawText and doing it like you said looks even worse than normal. The only other idea would be using the same size but making it bold. This is how it looks. It's a bit better than normal but you can still only use it with gui.drawText.
Warning: Might glitch to credits I will finish this ACE soon as possible (or will I?)
Pokota
He/Him
Joined: 2/5/2014
Posts: 779
Does BizHawk support fonts installed to the system at all? I want to say there are some outlined fonts that come with Windows (haven't had a Mac ever and I don't have a Linux station at the moment). Solarplex: Why is this two while blocks instead of a nested if true do while? As written if it comes up false you're getting an infinite loop. Oh you're probably iterating through until it does become true. But couldn't that be done using an if-else statement nested inside a big while loop instead of two separate while loops? Nope I'm still a dumb. When do you call the playback for the movie file?
Adventures in Lua When did I get a vest?
Active player (476)
Joined: 2/1/2014
Posts: 928
Possibly, everything i try either skips over them or freezes. I even breakpointed inside the lua functions to see if isloaded gets trigger and it doesnt.
Pokota
He/Him
Joined: 2/5/2014
Posts: 779
Hmm... you're testing isSingleMovieLoaded for the false block but you're testing movie.isLoaded for the true block. Why the difference? Still a dumb, you're making sure it's just one movie before you start trying to play it back.
Adventures in Lua When did I get a vest?
Active player (476)
Joined: 2/1/2014
Posts: 928
Right now I am only using one movie file, I do however need to fix the bizhawk function for opening a bk2 movie because for some reason its not understanding that filetype. but it does work(loading i mean) when I load a fm2 that gets converted to bk2.
Pokota
He/Him
Joined: 2/5/2014
Posts: 779
Hmm... the impression I get is that there's a code interaction here that I can't see because it relies on code I... uhh, can't see. Try some rubber duck debugging when you get a chance.
Adventures in Lua When did I get a vest?
CrazyTerabyte
He/Him
Joined: 5/7/2005
Posts: 74
Pokota wrote:
Ah crap, you're right. How I wrote it would break without iterating if it ever comes up false, which isn't the desired behavior. This is what I get for writing code without testing it.
Hey, just an idea, maybe you want to edit your previous code adding a comment saying the code does not work; just to avoid confusing people who are still learning programming that might end up reading it.
1 2 3 4 5
13 14