1 2
5 6 7 8
adelikat
He/Him
Emulator Coder, Site Developer, Site Owner, Expert player (3574)
Joined: 11/3/2004
Posts: 4754
Location: Tennessee
You have movie.playing() and movie.recording() that in conjunction will give you a "is playing" for your while loop In addition there is a movie.getmode() which will return record, playback, nil (or in the next fceux release: finished) that can also get the job done You also have movie.length() for your movie length. Btw, all of this info is in the FCEUX help that comes with FCEUX >_> Look specifically in the Lua Scripting chapter Lua Functions List page
It's hard to look this good. My TAS projects
Skilled player (1827)
Joined: 4/20/2005
Posts: 2161
Location: Norrköping, Sweden
Thanks, and I feel silly for not reading up on lua commands in FCEUX help, I'll make sure to read up on that before asking more questions.
Site Admin, Skilled player (1255)
Joined: 4/17/2010
Posts: 11486
Location: Lake Char­gogg­a­gogg­man­chaugg­a­gogg­chau­bun­a­gung­a­maugg
Is there any script, showing hit-boxes?
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.
Joined: 7/2/2007
Posts: 3960
I'm sure there are plenty, but they're each specific to a single game. Displaying hitboxes relies on looking up position and size information in memory, and memory locations are different for each game.
Pyrel - an open-source rewrite of the Angband roguelike game in Python.
Site Admin, Skilled player (1255)
Joined: 4/17/2010
Posts: 11486
Location: Lake Char­gogg­a­gogg­man­chaugg­a­gogg­chau­bun­a­gung­a­maugg
i need one for battletoads&double dragon engine. sprites there are much smaller then hitboxes (bounding boxes). also i can't find out addresses/values myself moreover, hitboxes there are somehow 3D - standing in the middle of the flour you can hit enemies wich stand much higher or lower... it also might be rather useful to watch hitboxes while aiming the entertainment: character hits air, but enemy suffers!
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.
MarbleousDave
He/Him
Player (13)
Joined: 9/12/2009
Posts: 1560
There could possibly be a lua script for Mega Man, in which you can change weapons using a specific key. But you need to get a particular weapon before you can press the key.
Skilled player (1827)
Joined: 4/20/2005
Posts: 2161
Location: Norrköping, Sweden
Does anyone here know how to read data from a text file in lua? I've googled this and found that I should probably use the ".read"-command, but I can't get the syntax correct. For example: suppose I have a .txt file with 2 numbers, one on each row, and want to load both these numbers and display the maximum with gui.text, how would that script look?
Skilled player (1652)
Joined: 11/15/2004
Posts: 2202
Location: Killjoy
Randil wrote:
Does anyone here know how to read data from a text file in lua? I've googled this and found that I should probably use the ".read"-command, but I can't get the syntax correct. For example: suppose I have a .txt file with 2 numbers, one on each row, and want to load both these numbers and display the maximum with gui.text, how would that script look?
http://tasvideos.org/forum/viewtopic.php?p=270971#270971 Check the 2nd script I made for Shining Soul 2.
Sage advice from a friend of Jim: So put your tinfoil hat back in the closet, open your eyes to the truth, and realize that the government is in fact causing austismal cancer with it's 9/11 fluoride vaccinations of your water supply.
Site Admin, Skilled player (1255)
Joined: 4/17/2010
Posts: 11486
Location: Lake Char­gogg­a­gogg­man­chaugg­a­gogg­chau­bun­a­gung­a­maugg
Why not stick this thread?
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.
Skilled player (1652)
Joined: 11/15/2004
Posts: 2202
Location: Killjoy
feos wrote:
Why not stick this thread?
We have an entire forum area for lua scripts and such - a specific topic per lua issue (related to programming lua scripts) is probably warranted.
Sage advice from a friend of Jim: So put your tinfoil hat back in the closet, open your eyes to the truth, and realize that the government is in fact causing austismal cancer with it's 9/11 fluoride vaccinations of your water supply.
Player (154)
Joined: 5/1/2006
Posts: 150
Here are a few scripts I've made for Ninja Gaiden along with a few questions! After reloading a script a few times emulation slows down, getting progressively worse with successive reloads. Is there something I should be doing differently to prevent this? This one just shows some basic position and speed info and was mainly made as a learning tool, I never actually need to see any of this crap on the game screen.
 local xpix = 0x0086; xsub = 0x0085; ypix = 0x008A; ysub = 0x0087; yspd = 0x0089; screen = 0x00A3; scrnsub = 0x00A2
 local xpos, ypos, scrnpos, yspdd
 local function show_coords()
  yspdd = memory.readbytesigned(yspd)
  xpos = memory.readbyte(xpix) + (memory.readbyte(xsub)/256)
  ypos = memory.readbyte(ypix) + (memory.readbyte(ysub)/256)
  scrnpos = memory.readbyte(screen) + (memory.readbyte(scrnsub)/256)
  gui.text(2,10,"Ryu:" .. xpos)
  gui.text(49,10,"," .. ypos)
  gui.text(205,24,"Y-speed:" .. yspdd)
  gui.text(192,10,"Screen:" .. scrnpos)
 end
 emu.frameadvance()
 gui.register(show_coords)
This is for macro'd 30hz wall-climbing. It could be a bit smarter: interrupting the 'jump, grab, jump...' pattern throws it off, and it doesn't account the different values for which direction Ryu is facing during damage flicker. But it does what it's supposed do to nicely enough.
local qpress,ryuface,ysub
while true do
  qpress=input.get()
  ryuface=memory.readbyte(0x0084)
  ysub=memory.readbyte(0x0087)
    if qpress.Q then
     if ysub == 0 and ryuface == 68 then
      joypad.set(1, {left=1, right=1})
      end
     if ysub == 0 and ryuface == 4 then
      joypad.set(1, {up=1, down=1, left=1}) 
      end
     if ysub > 0 and ryuface == 68 then
      joypad.set(1, {left=1, A=1})
      end	 
     if ysub > 0 and ryuface == 0 then
      joypad.set(1, {left=1, A=1})
      end	 
     if ysub > 0 and ryuface == 4 then
      joypad.set(1, {right=1, A=1})
      end
     if ysub > 0 and ryuface == 64 then
      joypad.set(1, {right=1, A=1})
      end
    end
 emu.frameadvance()
end
This is where the speed thing becomes an issue, since I've been modifying and reloading stuff like this a lot. (in this example i was cycling a not-really-RNG to see which values resulted in ryu getting hit by a tossed ax if he followed a specific path, then writing the value to a .txt file if he did get hit(yeah i know 'attempt' is totally redundant here, but this is just an easily-edited template for the general approach i've been taking to finding if some particular desired outcome is even possible before attempting to manipulate anything))
local attempt = 0
local globtim = 0
local frame = 1
local gothit
results = io.open("NGresults.txt", "w")
NGtest = savestate.create()
savestate.save(NGtest)
while attempt <= 256 do
  attempt=attempt+1
  memory.writebyte(0x00BF, globtim)
  frame=emu.framecount()
   while frame < 20919 do
    frame=emu.framecount()
	gothit=memory.readbyte(0x0095)
	 if gothit == 60 then
	  results:write(globtim,",")
	  end
    emu.frameadvance()
   end
  globtim=globtim+1
  savestate.load(NGtest)
  gui.text(4,10,"" .. attempt)
  gui.text(4,20,"" .. globtim)
end
results:close()
And finally, this grotesquery... It's supposed to, in a pretty basic manner, do what I described in this post. One thing I'm not clear on is why it doesn't update like the show_coords example above.
local bg_obj1 = 0x0300; bg_obj2 = 0x0301; bg_obj3 = 0x0302; bg_obj4 = 0x0303; bg_obj5 = 0x0304; bg_obj6 = 0x0305
local xpos=0; cycle=0
local function view_bg()
 while cycle < 22 do
  Column01A = memory.readbyte(bg_obj1); Column01B = memory.readbyte(bg_obj2); Column01C = memory.readbyte(bg_obj3); Column01D = memory.readbyte(bg_obj4); Column01E = memory.readbyte(bg_obj5); Column01F = memory.readbyte(bg_obj6)
  gui.text(xpos,8,"" .. Column01A); gui.text(xpos,16,"" .. Column01B); gui.text(xpos,24,"" .. Column01C); gui.text(xpos,32,"" .. Column01D); gui.text(xpos,40,"" .. Column01E); gui.text(xpos,48,"" .. Column01F); xpos=xpos+12
  bg_obj1=bg_obj1+6;bg_obj2=bg_obj2+6;bg_obj3=bg_obj3+6;bg_obj4=bg_obj4+6;bg_obj5=bg_obj5+6;bg_obj6=bg_obj6+6;cycle=cycle+1
 end
end
emu.frameadvance()
gui.register(view_bg)
I started writing it with .readbyterange and tables in mind, but then I realized I had no idea what I was doing. Also, displaying it in hexadecimal and with zeroes with the single-digit values would have been ideal, but as someone whose only prior programming experience is some pretty basic BASIC from over a decade ago I'm finding the Lua documentation to be somewhat esoteric. Edit: on IRC amaurea kindly explained string.format, field widths, and how to get zero padding (and some other stuff!), which leaves my only remaining real question about the slowdown issue with multiple reloads. Edit2: It occurred to me that declaring the variables outside the function and then counting them to infinity was kind of moronic, so here's my glorified hex-viewer fixed:
local function view_bg()
local bg_obj1 = 0x0300; bg_obj2 = 0x0301; bg_obj3 = 0x0302; bg_obj4 = 0x0303; bg_obj5 = 0x0304; bg_obj6 = 0x0305
local xpos=0; cycle=0
 while cycle < 21 do
  Column01A = memory.readbyte(bg_obj1); Column01B = memory.readbyte(bg_obj2); Column01C = memory.readbyte(bg_obj3)
  Column01D = memory.readbyte(bg_obj4); Column01E = memory.readbyte(bg_obj5); Column01F = memory.readbyte(bg_obj6)
  gui.text(xpos,8,string.format("%02x",Column01A)); gui.text(xpos,16,string.format("%02x",Column01B)); gui.text(xpos,24,string.format("%02x",Column01C))
  gui.text(xpos,32,string.format("%02x",Column01D)); gui.text(xpos,40,string.format("%02x",Column01E)); gui.text(xpos,48,string.format("%02x",Column01F))
  bg_obj1=bg_obj1+6;bg_obj2=bg_obj2+6;bg_obj3=bg_obj3+6;bg_obj4=bg_obj4+6;bg_obj5=bg_obj5+6;bg_obj6=bg_obj6+6
  cycle=cycle+1; xpos=xpos+12
 end
end
emu.frameadvance()
gui.register(view_bg)
Post subject: One more request
Site Admin, Skilled player (1255)
Joined: 4/17/2010
Posts: 11486
Location: Lake Char­gogg­a­gogg­man­chaugg­a­gogg­chau­bun­a­gung­a­maugg
How to convert framecount to common time display format for lua script - hours:minutes:seconds:miliseconds? Just like the frames option does: 1:09:03.47
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.
Skilled player (1827)
Joined: 4/20/2005
Posts: 2161
Location: Norrköping, Sweden
Here's my attempt (there's probably a simpler way but this seems to work). It always displays two digits for hours, minutes and seconds, and you can choose how many decimals to display on the second timer (currently 2):
while true do

local function displayer()

mf=movie.framecount()

hours=math.floor(mf/216000)
mf=mf-216000*hours

if hours<10 then hoursadd="0" else hoursadd="" end

mins=math.floor(mf/3600)
mf=mf-3600*mins

if mins<10 then minsadd="0" else minsadd="" end

-- number of decimals in second
numdec=2 

sec=math.floor((10^numdec)*mf/60 + 0.5)/(10^numdec)

if sec<10 then secadd="0" else secadd="" end

gui.text(10,160,hoursadd .. hours .. ":" .. minsadd .. mins .. ":" .. secadd .. sec)


end

gui.register(displayer)

   FCEU.frameadvance()
end
Former player
Joined: 2/19/2007
Posts: 424
Location: UK
How about this?
while true do
	local secs = math.floor(movie.framecount()/60)
	local frames = movie.framecount()-secs*60
	gui.text(10,160,string.format("%s:%02d",os.date("!%H:%M:%S",secs),frames))
	FCEU.frameadvance()
end
If you don't like the :60 format for the frames within the second, you can easily change that by replacing the gui.text line with
gui.text(10,160,string.format("%s.02d",os.date("!%H:%M:%S",secs),math.floor(600/frames)))
But I prefer the first one.
Site Admin, Skilled player (1255)
Joined: 4/17/2010
Posts: 11486
Location: Lake Char­gogg­a­gogg­man­chaugg­a­gogg­chau­bun­a­gung­a­maugg
The second variant freezes milliseconds. Yes, i need milliseconds, not frames after "." and to have them always as 2 digits, either ".00" or, say, ".70". EDIT:
Language: lua

while true do secs = math.floor(movie.framecount()/60) millisecs = math.floor((movie.framecount()-secs*60)*100/60) gui.text(1,160,string.format("%s.%02d",os.date("!%H:%M:%S",secs),millisecs)) FCEU.frameadvance() end
Is this fair? I don't remember if I shall round the third millisec digit up or not round at all (how does the site count that?).
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.
Former player
Joined: 2/19/2007
Posts: 424
Location: UK
feos wrote:
The second variant freezes milliseconds.
Sorry about that. If you really need milliseconds, I recommend this:
while true do
  local mins = math.floor(movie.framecount()/3600)
  local secs = movie.framecount()/60-mins*60
  gui.text(10,160,string.format("%s:%05.2f",os.date("!%H:%M",mins*60),secs))
  FCEU.frameadvance()
end
I haven't tested this, but the point here is that we do the seconds and their fraction through %f, and only do the hours and minutes through os.date.
Post subject: Still actual
Site Admin, Skilled player (1255)
Joined: 4/17/2010
Posts: 11486
Location: Lake Char­gogg­a­gogg­man­chaugg­a­gogg­chau­bun­a­gung­a­maugg
Can lua detect if emulator is in PAL mode? If no, how about that feature in future?
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.
Site Admin, Skilled player (1255)
Joined: 4/17/2010
Posts: 11486
Location: Lake Char­gogg­a­gogg­man­chaugg­a­gogg­chau­bun­a­gung­a­maugg
How can I calculate screen scrolling speed if there's no one in RAM? There are 3 speeds for it: 1 pixel per frame, 2 ppf and 3 ppf. Need some function to get the comparison to every previous value (simply "n = current - previous").
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.
Editor, Skilled player (1202)
Joined: 9/27/2008
Posts: 1085
feos wrote:
How can I calculate screen scrolling speed if there's no one in RAM? There are 3 speeds for it: 1 pixel per frame, 2 ppf and 3 ppf. Need some function to get the comparison to every previous value (simply "n = current - previous").
Language: lua

local LastVal= 0 local function Fn() local Val= memory.readbyte(0x0000) -- Insert the appropriate value gui.text(1,10,Val - LastVal) LastVal= Val end while true do Fn() emu.frameadvance() end
EDIT: Whoops, forgot the LastVal= Val line. Replace memory.readbyte with memory.readword if you know it's a 2-byte value and not 1-byte. If there are two bytes in different locations, not simply next to each other, you'd need memory.readbyte() for the low value and memory.readbyte()*256 for the high value. Add them together, naturally. Obviously, I don't know what address you're thinking of. Just stick in the address you want.
Site Admin, Skilled player (1255)
Joined: 4/17/2010
Posts: 11486
Location: Lake Char­gogg­a­gogg­man­chaugg­a­gogg­chau­bun­a­gung­a­maugg
How can I iterate values from several arrays in one command, like that:
gui.text( array1, array2, array3 )
to take x and y from separate tables as well as the text?
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.
Emulator Coder, Site Developer, Former player
Joined: 11/6/2004
Posts: 833
How about...
Language: lua

for i=1..#array1 do gui.text( array1[i], array2[i], array3[i] ) end
Where each array is identically sized and one is all X coordinates, all Y coordinates, and all text messages.
Site Admin, Skilled player (1255)
Joined: 4/17/2010
Posts: 11486
Location: Lake Char­gogg­a­gogg­man­chaugg­a­gogg­chau­bun­a­gung­a­maugg
I want to diaplay on the screen some sentence. And if it's too long to fit in the screen, is it possible to automatically break the line? Like, detect the number of symbols in the string and find 'space' to break after?
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.
Emulator Coder, Skilled player (1113)
Joined: 5/1/2010
Posts: 1217
feos wrote:
I want to diaplay on the screen some sentence. And if it's too long to fit in the screen, is it possible to automatically break the line? Like, detect the number of symbols in the string and find 'space' to break after?
Number of characters in string can be found out using the # operator (#string_variable) As for finding space, one could try to use some string function (the ones with names starting with 'string.'), see the Lua reference manual. Or just read one char at time using string.sub(string_variable, character_index, character_index). Note: The indexes start at 1, not 0.
Ambassador, Experienced player (709)
Joined: 7/17/2004
Posts: 985
Location: The FLOATING CASTLE
Looks like a bug got introduced in 2.1.5 affecting rectangle drawing. The graphics inside a rectangle are offset, shifted up about 10 pixels or so. This didn't happen in 2.1.4. I've shared this lua with others and they see the same issue. I think it happens with any rectangle, but definitely with my crystalis hitbox lua. lua code a few posts from the end of the thread here: http://tasvideos.org/forum/viewtopic.php?t=390
AnS
Emulator Coder, Experienced player (728)
Joined: 2/23/2006
Posts: 682
TheAxeMan wrote:
Looks like a bug got introduced in 2.1.5 affecting rectangle drawing. The graphics inside a rectangle are offset, shifted up about 10 pixels or so. This didn't happen in 2.1.4. I've shared this lua with others and they see the same issue. I think it happens with any rectangle, but definitely with my crystalis hitbox lua. lua code a few posts from the end of the thread here: http://tasvideos.org/forum/viewtopic.php?t=390
http://tasvideos.org/forum/viewtopic.php?p=297025#297025
1 2
5 6 7 8