filwac
He/Him
Joined: 12/12/2009
Posts: 29
Location: Forever floating in a secret world
maybe i'm not looking hard enough, maybe i'm just blind, but i can't find how to create macros. closest i've found is http://tasvideos.org/LuaScripting/Macros.html but it just tells me how to autohold. an example of what i need would be (down)(up)(down)(blank)repeat [part of slow fall in metroid fusion/zero mission]
Waiting takes too long
Editor, Expert player (2329)
Joined: 5/15/2007
Posts: 3933
Location: Germany
sav=savestate.create(3)
savestate.save(sav)
This works in snes9x but not in VBA 24-m. Why? It just tells me the savestate failed. Without this I can't use savestate.load(object) either since I can't create any objects that I can forward my script to.
random = math.random(12)

if random == 1 then joypad.set(1,{A=1})
elseif random == 2 then joypad.set(1,{A=1})
elseif random == 3 and z == 1 then joypad.set(1,{down=1})
elseif random == 4 then joypad.set(1,{down=1})
elseif random == 5 then joypad.set(1,{down=1})
elseif random == 6 then joypad.set(1,{B=1})
elseif random == 7 then joypad.set(1,{B=1})
elseif random == 8 then joypad.set(1,{right=1})
elseif random == 9 then joypad.set(1,{right=1})
elseif random == 10 then joypad.set(1,{left=1})
elseif random > 10 then joypad.set(1,{A=0}) end
This is how I create random input. How can I make it have more than one button per frame?
Editor, Expert player (2073)
Joined: 6/15/2005
Posts: 3282
Lua savestates in VBA are messed up. You can only use internal savestates (savestate.create() without any number), and the savestates are inconsistent (they don't track the opcount accurately) so it may cause desync. About joypad.set, I'm not sure what the question is, but joypad.set cannot be stacked. Create one table, add all the buttons you want to it, then call joypad.set with that table at the end.
Editor, Expert player (2329)
Joined: 5/15/2007
Posts: 3933
Location: Germany
How do I create such a table? Please provide a sample script that I can use.
Editor, Expert player (2073)
Joined: 6/15/2005
Posts: 3282
Something like this.
local t={}

r1=math.random(2)
r2=math.random(2)

if r1==1 then t.right=1 end
if r2==1 then t.down=1 end

joypad.set(1,t)
You can also use, say, t["right"] instead of t.right. This is good for using a variable to reference a table key, as well as when referencing a table key which is the string of a number (using t.9 doesn't work, for example; it must be t["9"]; also, it is different from t[9]).
Active player (264)
Joined: 4/15/2010
Posts: 197
Location: England
Language: Lua

local key_table = {} local randint = math.random(12) if randint == 1 then key_table["A"] = true; key_table["B"] = true; end if randint == 2 then key_table["right"] = true end -- etc.. joypad.set(1, key_table)
Something like this you want, maybe? :) However if you want multiple keys to be set at random, then maybe something like:
Language: Lua

local key_table = { ["A"] = false, ["B"] = false } -- etc.. for k, v in pairs(key_table) do local set = math.random(2) if set == 2 then key_table[k] = true end end joypad.set(1, key_table)
Sorry if I misunderstand. Both scripts are untested but the idea is there. :p
Retired smw-96, smw any%
Editor, Expert player (2329)
Joined: 5/15/2007
Posts: 3933
Location: Germany
I need some lua help. How can I make a lag counter based off my character's speed or position addresses? So that I can count how many times my addresses haven't updated Thanks in advance
Player (153)
Joined: 5/1/2006
Posts: 150
MUGG wrote:
I need some lua help. How can I make a lag counter based off my character's speed or position addresses? So that I can count how many times my addresses haven't updated Thanks in advance
Something simple to compare the values from the previous frame should be all you need. Here's an example of something I used once to check for when the screen-scrolling was interrupted:
Language: lua

while true do scroll=memory.readbyte(0x00A3) if scroll == oldscroll then gui.text(120,100,"!!!!!!!!!!!!!!!!!","red") bleh=bleh+1 gui.text(0,8,"" .. bleh) end emu.frameadvance() oldscroll=scroll end
Though something less simple might be needed, depending on how your game calculates positions.
Editor, Expert player (2329)
Joined: 5/15/2007
Posts: 3933
Location: Germany
Thanks very much. I even managed to make the counter reset when loading a state with this method (which was previously impossible because VBA's savestate lua functions don't work).
Language: lua

oldcount = 0 oldscroll = 0 while true do gui.opacity(0.59) gui.drawbox(84,6,156,19, "black","black") gui.opacity(0.9) framecount = vba.framecount() scroll=memory.readwordsigned(0x02038730)+memory.readwordsigned(0x02038750)+memory.readwordsigned(0x02038824) if scroll == oldscroll then gui.text(90,8,"***** *****","red") lag=lag+1 end gui.text(117,10,"" .. lag) if framecount < oldcount then lag = lag - lag end vba.frameadvance() oldscroll=scroll oldcount = framecount end
Editor, Expert player (2329)
Joined: 5/15/2007
Posts: 3933
Location: Germany
I want to write a script that can display enemy names in Super mario land 2 in a list on screen. This picture describes my approach. http://i.imgur.com/iBBQTS5.png The problem is that I'm unable to display stuff in a list. I saw this kind of for loop in an old Daffy duck lua script by Scepheo. But in that case, enemy screen positions were used to display stuff on screen. But this time around I can't see a way to tell the slots apart (give them numbers like slot 1, slot 2, slot 3 etc. and therefore give them positions, for example: gui.text(10,10+slotnumber, "stuff that varies per slot") ) The example script that I saw by Scepheo:
Language: Lua

for i = 0xDF00, 0xDFFF, 16 do if memory.readbyte(i+0) ~= 0 then local inv = memory.readbyte(i+10) local hp = memory.readbyte(i+11) local x = memory.readbyte(i+13) local y = memory.readbyte(i+14) gui.text(x - 16, y - 24, "hp: " .. hp) gui.text(x - 16, y - 16, "inv: " .. inv) end end
I appreciate your help. If there's no solution maybe I'll handle each enemy slot on its own. But that would mean not being able to display stuff properly in order (from top to bottom).
Editor, Skilled player (1202)
Joined: 9/27/2008
Posts: 1085
gui.text(10,10+slotnumber, "stuff that varies per slot") slotnumber is some integer from 0 to whatever, in steps of 1 (0,1,2,3, ...), correct? Without a multiplier, you're just drawing the next number one pixel down, most likely putting it mostly on top of the previous number. Try slotnumber*7. So... gui.text(10,10+slotnumber*7, "stuff that varies per slot") Now each change of one to slotnumber changes position by seven pixels. Is this what you wanted?
Editor, Expert player (2329)
Joined: 5/15/2007
Posts: 3933
Location: Germany
No. My question is how to define "slotnumber" (in a for loop, if possible).
Patashu
He/Him
Joined: 10/2/2005
Posts: 4043
Make slotnumber a local starting at 0 initialized outside of the for loop, and add 1 to it every pass through the for loop.
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
Editor, Expert player (2329)
Joined: 5/15/2007
Posts: 3933
Location: Germany
Make slotnumber a local starting at 0 initialized outside of the for loop, and add 1 to it every pass through the for loop.
Please explain, how would I do this? I'm just bad at lua... (and still bad at programming in general) There's also another question. In the past I could never write something like
if a == b AND c == d then gui.text(10,10,"true") end
How can I make an if statement with two or more conditions?
Editor, Skilled player (1202)
Joined: 9/27/2008
Posts: 1085
Language: lua

for slotnumber = 0 , 15 do -- or pick some other values local address = 0xDF00 + 16*slotnumber -- insert stuff relating to what you're doing end --Multiple conditions if if (a == b) and (c == d) then --code end
I have suggested one way to define slotnumber, and a way to pull an address out of it. I recall that the logical keywords overtakes comparison operators, so use parentheses around every desired condition to fight this order of operation. Lua has some tricky syntax at times.
Editor, Expert player (2329)
Joined: 5/15/2007
Posts: 3933
Location: Germany
Is it possible to write an external .txt file with lua in VBA? Can someone provide an example script? I would like to write one new line each frame.
ventuz
He/Him
Player (125)
Joined: 10/4/2004
Posts: 940
MUGG wrote:
Is it possible to write an external .txt file with lua in VBA?
I did made a fun lua script that allowed me to create infinite custom levels for GB Hyper Lode Runner by exporting level datas to .txt and importing them as well. But it was a mess and I don't have it anymore on this PC. Sorry no sample, take a look at "file:" and "io." in lua reference manual.
Editor, Player (54)
Joined: 12/25/2004
Posts: 634
Location: Aguascalientes, Mexico
I've used io library to dump information using the SNES9x. First you use io.output() to create a file, io.write() to write in it and io.close() to close it when you finish it. I used the following example to create a watch file instead of me having to manually create it, which was tedious. (I think I had to later revise it, but that's not the point here, just to show how you can use it...):
Language: LUA

local function watch_file() io.output("Final Fantasy V (P).wch") local index = 0x80 local address = 0x7E2200 local size = "b" local Type = "h" local zero = 0 local notes = "" for i=0, index-1 do io.write( string.format( "%5X %6X %s %s %i %s\n", i, address+i, size, Type, zero, notes) ) end io.close() end
I'm the best in the Universe! Remember that!
Editor, Expert player (2329)
Joined: 5/15/2007
Posts: 3933
Location: Germany
Thanks. I want to create an input display now. For this I have written a luascript that writes a line whenever input changes.
Language: Lua

(...) keytable = joypad.get(1) if keytable.left then left = "true" else left = "false" end if keytable.right then right = "true" else right = "false" end if keytable.down then down = "true" else down = "false" end if keytable.up then up = "true" else up = "false" end if keytable.start then start = "true" else start = "false" end if keytable.select then select = "true" else select = "false" end if keytable.a then a = "true" else a = "false" end if keytable.b then b = "true" else b = "false" end (...) if lagcount ~= vba.lagcount() or leftbefore ~= left or rightbefore ~= right or upbefore ~= up or downbefore ~= down or startbefore ~= start or selectbefore ~= select or abefore ~= a or bbefore ~= b then (...) io.write( 'FINAL'..changes..' = vid5.trim('.. framecount_last_valchange..','.. frames..') .Part('.. lagcount..','.. left ..','..right..','.. up..','.. down..','.. a..','.. b..','.. start..','..select..')\n') (...)
This works when inputting buttons to the emulator manually. But it does not work with pre-recorded movies. Is there a way to make it work? Otherwise, is there a way to convert my movie file to the information I need?
Editor, Expert player (2329)
Joined: 5/15/2007
Posts: 3933
Location: Germany
EDIT: I was told there is no way to make it work. I have solved my problem in the meantime.
Editor, Expert player (2329)
Joined: 5/15/2007
Posts: 3933
Location: Germany
I have a new inquiry to make. Survival Kids has a glitch that potentially leads to another ACE, similar to Super Mario Land 2's pause glitch. Those glitches would make the game execute code not from ROM but from other places such as SRAM, RAM, WRAM etc. My question is would it be feasible to use a script that checks if any of those addresses are being executed each frame? For SML2, I only checked a dozen addresses that really mattered (because I knew which one mattered). With Survival Kids I don't know which addresses matter. EDIT:
Language: lua

function hex(num,dig) local dig = dig or 4 --assume 4 digits if not given local hexstr = '0123456789ABCDEF' local s = '' --while num > 0 do while dig > 0 do -- use digit instead so there is padding local mod = math.fmod(num, 16) s = string.sub(hexstr, mod+1, mod+1) .. s num = math.floor(num / 16) dig = dig - 1 end if s == '' then s = '0' end return s end while true do t="" for i=0xC000,0xCFFF,0x0001 do memory.registerexec(i, function () vba.print(hex(i).." executed!") t = t .. hex(i) .. " executed\n" end) end gui.text(2,0,t,"orange") emu.frameadvance() end
Looks like this is what I wanted although it's reaaally slow.
Masterjun
He/Him
Site Developer, Skilled player (1987)
Joined: 10/12/2010
Posts: 1185
Location: Germany
Don't put the memory.registerexec in the while true loop. You only have to call it once (not every frame) for every address. Also, in some emulators you can specify the number of bytes you want to look at, for example:
Language: lua

memory.registerexec(0xC000, 0x0FFF, function () --stuff end)
Warning: Might glitch to credits I will finish this ACE soon as possible (or will I?)