1 2
6 7 8 9
Joined: 10/23/2009
Posts: 545
Location: Where?
Language: lua

local function playerinfo(color,player,y) memory = 0x010828 + 0x100 * (player-1) gui.drawText(335,290 + y, color ,"red", "black", 16) gui.drawText(345,310 + y, memory.read_s16_le(memory,"WRAM"),"white","black",16) gui.drawText(430,310 + y, memory.read_s16_le(0x010880,"WRAM"),"white","black",16) gui.drawText(520,310 + y, memory.read_s16_le(0x010860,"WRAM"),"white","black",16) --Find a way to align the text to the right end
So I'm creating this function. As you can see, I'm currently working on it so I can reuse the same function for different players. I've noticed the different players has only an offset between some importants infos. So far I've encountered a couple of problem: 1- I need to be able to do operations in hexademical.However, I'm not sure to know how to do it. I made an attempt with the 2nd line of the quoted code. But the lua console give me thisL
LuaInterface.LuaScriptException: [string "main"]:124: attempt to index global 'memory' (a number value)
2-I'd like also to align the text of the fouth drawtext to the left. I've tried with
    horizalign = 'right', horizalign= "right" "right"
None of them worked. So I'm stumped. Any help would be appreciated!
Editor, Emulator Coder
Joined: 8/7/2008
Posts: 1156
1. why are you assigning a number to 'memory'? That doesn't make any sense. You're overwriting the memory APIs with a _number_. 2. You have documentation saying there's an argument called horizalign, and it's after fontfamily and fontstyle. Why are you trying to skip fontfamily and fontstyle?
Joined: 10/23/2009
Posts: 545
Location: Where?
1-I wanted to create a variable... Guess I chose a terrible name. I'll try a different name. 2-Oh I can't skip an argument? I wasn't aware. Thanks!
Editor, Emulator Coder
Joined: 8/7/2008
Posts: 1156
To everyone I've told to stop using LUA. I've begun testing NLua+KopiLua in place of LuaInterface+Lua. Please evaluate. That means, start using LUA again in buildbot builds.
Editor, Player (163)
Joined: 4/7/2015
Posts: 330
Location: Porto Alegre, RS, Brazil
To solve both of your problems:
Language: lua

local function playerinfo(color,player,y) local address_offset = 0x010828 + 0x100 * (player - 1) gui.drawText(335, 290 + y, color, "red", "black", 16) gui.drawText(345, 310 + y, memory.read_s16_le(address_offset, "WRAM"), "white","black", 16) gui.drawText(430, 310 + y, memory.read_s16_le(0x010880, "WRAM"), "white", "black", 16) gui.drawText(520, 310 + y, memory.read_s16_le(0x010860, "WRAM"), "white", "black", 16, "Courier New", "regular", "right") end
Notice that I changed "memory" by "address_offset" to solve the error, and declared it as local (get used to use local inside your functions). Also, if you just want to align text, currently you have to declare fontsize, fontfamily and fontstyle before, so I used 16 (your size), "Courier New" (drawText default font), "regular" (default). In my opinion, there should be a way to pass them as nil or something like this.
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
Skilled player (1706)
Joined: 9/17/2009
Posts: 4952
Location: ̶C̶a̶n̶a̶d̶a̶ "Kanatah"
zeromus wrote:
To everyone I've told to stop using LUA. I've begun testing NLua+KopiLua in place of LuaInterface+Lua. Please evaluate. That means, start using LUA again in buildbot builds.
I tried drag and dropping a lua file on the interim, and immediately got this error Then BizHawk crashed.
Editor, Emulator Coder
Joined: 8/7/2008
Posts: 1156
you picked a buildbot build at an unlucky time
Skilled player (1706)
Joined: 9/17/2009
Posts: 4952
Location: ̶C̶a̶n̶a̶d̶a̶ "Kanatah"
Sorry about that. Just redownloaded and it worked with getinput now (without crashing yet). I tried this piece of code:
Language: lua

local Map = {} function assign_multi(string,...) for i, v in ipairs(arg) do Map[v] = string end end assign_multi("Bandit's Hideout",98,99,100,101,102,103,104) console.log(Map[99])
It worked with previous versions of BizHawk (including 2.0 on the download page) but in the interim it gave:
NLua.Exceptions.LuaScriptException: [string "main"]:3: bad argument #1 to 'ipairs' (table expected, got nil)
Amaraticando
It/Its
Editor, Player (158)
Joined: 1/10/2012
Posts: 673
Location: Brazil
Well, arg is nil. Maybe this version of Lua doesn't support arg for varargs. Try table.pack https://www.lua.org/manual/5.2/manual.html#pdf-table.pack
Skilled player (1706)
Joined: 9/17/2009
Posts: 4952
Location: ̶C̶a̶n̶a̶d̶a̶ "Kanatah"
Amaraticando wrote:
Well, arg is nil. Maybe this version of Lua doesn't support arg for varargs. Try table.pack https://www.lua.org/manual/5.2/manual.html#pdf-table.pack
I wrote this:
Language: lua

temp = table.pack(98,99,100,101,102,103,104) console.log(temp[2])
And it gave the error:
NLua.Exceptions.LuaScriptException: [string "main"]:1: attempt to call field 'pack' (a nil value)
Editor, Emulator Coder
Joined: 8/7/2008
Posts: 1156
Change `arg` to `{...}` FYI: Currently there is a great deal of grief caused by the 25% performance of kopilua. Don't get too attached to this, I dont know what's going to happen yet. Thanks for testing it though.
Post subject: Ram watch adddresses
Ludko444
He/Him
Joined: 11/6/2016
Posts: 8
Hi. Is possible add to lua script which addresses will open in ram watch ?
Skilled player (1706)
Joined: 9/17/2009
Posts: 4952
Location: ̶C̶a̶n̶a̶d̶a̶ "Kanatah"
On BizHawk 2.1.0, this code gives an error
Language: lua

file = io.open("test.txt", "a") io.output(file) io.write("Hi\n") io.close(file)
NLua.Exceptions.LuaScriptException: [string "main"]:4: bad argument #1 to 'close' (FILE* expected, got nil)
On the previous versions, it works fine. Can someone please help? Edit :Works with Luainterface, but then apparently it has memory leaks.
Amaraticando
It/Its
Editor, Player (158)
Joined: 1/10/2012
Posts: 673
Location: Brazil
If io.open returns nil, it means that the file doesn't exist of that Lua cannot open it. In this context, maybe the 1st is the case. Where's test.txt? In the same folder of BizHawk or in the same folder of the script? Try to pass the absolute path to see if it works.
Editor, Emulator Coder
Joined: 8/7/2008
Posts: 1156
bug in kopilua ("a" doesnt work). fixed and patch pushed to upstream. PAPERWORK.
Skilled player (1706)
Joined: 9/17/2009
Posts: 4952
Location: ̶C̶a̶n̶a̶d̶a̶ "Kanatah"
Amaraticando wrote:
If io.open returns nil, it means that the file doesn't exist of that Lua cannot open it. In this context, maybe the 1st is the case. Where's test.txt? In the same folder of BizHawk or in the same folder of the script? Try to pass the absolute path to see if it works.
On luainterface, it creates the file on the script directory. I changed the script to
Language: lua

file = io.open("C:\Users\User\Google Drive\Lua\BizHawk\not game\test.txt", "a") io.output(file) io.write("Test\n") io.close(file)
and it gives the error:
NLua.Exceptions.LuaScriptException: [string "main"]:3: standard output file is closed
I tried the same with "w", but this time made the "test.txt" actually exist to begin with, and it sorta works. As in:
Language: lua

file = io.open("test.txt", "w") io.output(file) io.write("Hi\n") io.close(file)
Works, but if I changed it to "C:\Users\User\Google Drive\Lua\BizHawk\not game\test.txt" it gives the same error as above.
zeromus wrote:
bug in kopilua ("a" doesnt work). fixed and patch pushed to upstream. PAPERWORK.
Thanks. Also would like to note "\n" appears to be broken in Nlua/kopilua.
Language: lua

file = io.open("Test.txt","w") io.output(file) for i = 1, 5 do io.write(i.."\n") end io.close(file)
Outputs "12345" when opened in notepad, yet copy-pasting it to this chat actually makes it newline. In luainterface, notepad displays as 1 2 3 4 5 instead.
Masterjun
He/Him
Site Developer, Skilled player (1971)
Joined: 10/12/2010
Posts: 1179
Location: Germany
jlun2 wrote:
Outputs "12345" when opened in notepad, yet copy-pasting it to this chat actually makes it newline. In luainterface, notepad displays as 1 2 3 4 5 instead.
DOS/Windows vs UNIX/Linux type newline shenanigans. Windows uses \r\n whereas Linux uses \n. The built-in notepad in Windows doesn't show single \n. Quick user-side solutions: - get a better notepad - write \r\n The difference is that the old Lua automatically replaced \n to \r\n.
Warning: Might glitch to credits I will finish this ACE soon as possible (or will I?)
Editor, Emulator Coder
Joined: 8/7/2008
Posts: 1156
old lua opened text files with the mode given, which in this case was "w" which means "write text" which means \n is translated to \r\n in windows. Looks like kopilua messed this all up. I suggest you never use "a" or "w" or "b" as they're stupid. Use "wb" and "rb" and "ab" (I think) and use \n and a text editor which can read \n In fact, .net doesn't even seem to be capable of opening streams in text mode. That's good news, because it's stupid. I would say I will continue to fix kopilua to match lua but I don't know if in the long run I will be able to guarantee it in small details like this. And in this case, it's too small a detail. I don't want to fix it when there's such an obvious workaround. Let's wait until it makes bigger trouble. You can write it up as a bug though if you want. It wouldnt be hard for someone else to tackle by writing a wrapper around .net's stream to do the text translating and return it from kopilua's fopen Everything else you wrote was too confusing on account of your composing it as a reply to Amaraticando and maybe combining two tests into one that I can't understand it. However, lua should be capable of creating the file when "a" is specified. So too should nlua after the modifications I made earlier. If you have a bug other than \r\n please write it so it isn't confusing
Amaraticando
It/Its
Editor, Player (158)
Joined: 1/10/2012
Posts: 673
Location: Brazil
jlun2 wrote:
Language: lua

file = io.open("C:\Users\User\Google Drive\Lua\BizHawk\not game\test.txt", "a")
Be careful while writing windows paths in your scripts. \ is an escape character and can change your string. TASVideos parser even makes it blue in the code. You can pick one of the options below:
Language: lua

local path1 = "C:\\Users\\User\\Google Drive\\Lua\\BizHawk\\not game\\test.txt" local path2 = [[C:\Users\User\Google Drive\Lua\BizHawk\not game\test.txt]] -- better
Skilled player (1706)
Joined: 9/17/2009
Posts: 4952
Location: ̶C̶a̶n̶a̶d̶a̶ "Kanatah"
Thanks for the help. I encountered something weird for input:
Language: lua

function inputdelay(inputs, delay) local is = input.get() local start = false if inputs ~= nil and (is[tostring(inputs)] ~=nil) then console.log(is) --debugging while (delay > 0) do emu.frameadvance() delay = delay -1 end start = true return start end return start end local toggle = 0 while true do if inputdelay("C",10) then toggle = 1 console.log("Hi C") elseif inputdelay("V",10) then toggle = 0 console.log("Hi V") end if toggle == 1 then gui.drawText(20,20,"Test") end gui.drawText(20,30,"Toggle "..toggle) emu.frameadvance() end
If I press "C", it displays "test". If I press "V", it doesn't. However, if I pressed C,V and down, right at the same time, the next time I press C or V again it doesn't register; toggle doesn't even change. I'm using 2.1.1 nlua if it helps.
Editor, Emulator Coder
Joined: 8/7/2008
Posts: 1156
Did you edit this post? It should have been fixed a few days ago
Skilled player (1706)
Joined: 9/17/2009
Posts: 4952
Location: ̶C̶a̶n̶a̶d̶a̶ "Kanatah"
zeromus wrote:
Did you edit this post? It should have been fixed a few days ago
Oh. Must've used an old BizHawk version by mistake. Sorry about that.
Skilled player (1650)
Joined: 7/1/2013
Posts: 433
Is there a method to change the orientation (i.e. rotate) lua's displayed output?
Editor, Emulator Coder
Joined: 8/7/2008
Posts: 1156
no, but depending on what functions youre using to draw (they dont all work the same, its a pretty schizo bunch of APIs) you might could draw to an offscreen image (or even a file) and then draw that onto the screen after passing it to some external program for rotating.. good luck. put it on the github bug tracker and maybe itll get done some day, although no promises itll work like you want or be done in a timely manner
Editor, Expert player (2313)
Joined: 5/15/2007
Posts: 3855
Location: Germany
I'm writing a game in lua code for fun. Question: Does using a lua canvas object provide more performance or is it ok to just draw stuff to the emu screen? I tried around with lua canvas but it seems lua canvas functions, such as LuaCanvas.drawRectangle(), haven't been implemented in 1.12.0, and I'm reluctant to try versions beyond that. edit: Is it possible to assign a function to a table, as opposed to the function result?
1 2
6 7 8 9