Post subject: Lua help please
Joined: 10/2/2015
Posts: 91
I want to write a lua script that counts the number of frames an input is pressed in a movie... what am i doing wrong here?
Language: lua

local upCount = 0 while true do table = movie.getinput(emu.framecount()) if (table.up) then upCount = upCount+1 print(upCount) end emu.frameadvance() end
I didn't kill donkey, I saved it. Current projects: Misc Donkey hacks :) Past projects: Pacifist DKC1 DKC1 Entrance randomizer DKC2 Entrance randomizer DKDC (a troll hack of DKC1) DKC1 Enemy randomizer (among other things)
Editor, Player (69)
Joined: 6/22/2005
Posts: 1050
Try capitalizing up:
Language: Lua

if (table.Up) then
It looks like you can get the proper names of the buttons by doing something like
Language: Lua

table = movie.getinput(emu.framecount()) print(table)
Obviously, you don't need to do this every frame once you know the names for whatever system you're working with.
Current Projects: TAS: Wizards & Warriors III.
Editor, Player (175)
Joined: 4/7/2015
Posts: 331
Location: Porto Alegre, RS, Brazil
I made a code that store all inputs from player 1 and print the input table only when movie ends
Language: lua

local input_count = { ["A"] = 0, ["B"] = 0, ["Down"] = 0, ["L"] = 0, ["Left"] = 0, ["R"] = 0, ["Right"] = 0, ["Select"] = 0, ["Start"] = 0, ["Up"] = 0, ["X"] = 0, ["Y"] = 0 } while emu.framecount() < movie.length() do table = movie.getinput(emu.framecount()) if table["P1 A"] then input_count["A"] = input_count["A"] + 1 end if table["P1 B"] then input_count["B"] = input_count["B"] + 1 end if table["P1 Down"] then input_count["Down"] = input_count["Down"] + 1 end if table["P1 L"] then input_count["L"] = input_count["L"] + 1 end if table["P1 Left"] then input_count["Left"] = input_count["Left"] + 1 end if table["P1 R"] then input_count["R"] = input_count["R"] + 1 end if table["P1 Right"] then input_count["Right"] = input_count["Right"] + 1 end if table["P1 Select"] then input_count["Select"] = input_count["Select"] + 1 end if table["P1 Start"] then input_count["Start"] = input_count["Start"] + 1 end if table["P1 Up"] then input_count["Up"] = input_count["Up"] + 1 end if table["P1 X"] then input_count["X"] = input_count["X"] + 1 end if table["P1 Y"] then input_count["Y"] = input_count["Y"] + 1 end if emu.framecount() == movie.length() - 1 then print(input_count) end emu.frameadvance() end
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
Amaraticando
It/Its
Editor, Player (159)
Joined: 1/10/2012
Posts: 673
Location: Brazil
It's not a good practice to overwrite the variable table.
Masterjun
He/Him
Site Developer, Skilled player (1988)
Joined: 10/12/2010
Posts: 1185
Location: Germany
I agree with Amaraticando. This should have been the first thing mentioned here, as it could prevent future problems. Overwriting the table table effectively voids the whole library for table manipulation for the rest of the program, which you don't want to do.
Warning: Might glitch to credits I will finish this ACE soon as possible (or will I?)
Joined: 10/2/2015
Posts: 91
Ok, I see your point guys. Then why do we use this line?
table = joypad.get(1)
Or should we not?
I didn't kill donkey, I saved it. Current projects: Misc Donkey hacks :) Past projects: Pacifist DKC1 DKC1 Entrance randomizer DKC2 Entrance randomizer DKDC (a troll hack of DKC1) DKC1 Enemy randomizer (among other things)
Masterjun
He/Him
Site Developer, Skilled player (1988)
Joined: 10/12/2010
Posts: 1185
Location: Germany
We should not.
Warning: Might glitch to credits I will finish this ACE soon as possible (or will I?)
Editor, Player (175)
Joined: 4/7/2015
Posts: 331
Location: Porto Alegre, RS, Brazil
Oh yea I forgot to post the code I used to test and showed to you in the discord server, there I corrected it simply by using
Language: lua

input_table = joypad.get(1)
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