User File #638757648157501502

Upload All User Files

#638757648157501502 - TAStudio Output Logger Demo Script

KirbyLogger.lua
1 download
Uploaded 16 hours ago by TASeditor (see all 191)
For Kirby's Adventure.
Save this script into the same folder as UserFiles/Info/638757645500544857.
Load KirbyLogger.lua into the Lua Console.
Open TAStudio and run the script.

require("TAStudioLogger")

-- Logs the value from memory for each frame. First argument is logger name, second is a function that returns the value from a memory.read call.
AddLogger("XVel", function () return memory.read_s16_le(0x05B9) end)
AddLogger("YVel", function () return memory.read_s16_le(0x05BD) end)
AddLogger("Flags", function () return memory.read_u8(0x05E1) end)
AddLogger("Xpos", function () return memory.read_u8(0x0083) + memory.read_u8(0x0095)*256 end) -- More complicated expression also possible.


-- Prints the values from the "XVel" log into a new column in TAStudio called "XVel" with a color gradient from red to green for values from 0 to 704; 1.5 modifies the gradient.
-- The argument nil is for text and tells the program to just print the values from "XVel" log. 4 is the number of digits for the new column.
AddPrinter("XVel", "XVel", function(index, value) return ColorGradient(index, math.abs(value), 704, 0xFFFF0000, 0xFF00FF00, 1.5) end, nil, 4)
AddPrinter("YVel", "YVel", function(index, value) return ColorGradient(index, math.abs(value), 880, 0xFFFF0000, 0xFF0000FF, 0.75) end, nil, 4)

-- Adds a column called "DX" into TAStudio and prints the values from the BranchCompareNormalized function as formatted by the third function into TAStudio.
-- BranchCompareNormalized takes the values from log called "Xpos" and subracts the value in branch log "Xpos" and multiplies it by the sign of the value in log "XVel"
AddPrinter("DX", function (index) return BranchCompareNormalized("Xpos", "XVel", index) end, 
			function(index, value) return ColorGradient(index, value, 20, 0xFFFF0000, 0xFF00FF00) end,
			function(value) return tostring((value//256)..":"..string.format("%X", value%256)) end, 4)

flagcolors = {} -- States for Kirby
flagcolors[0] = 0xFFE0E0E0  --  standing
flagcolors[1] = 0xFFE04090  -- walking
flagcolors[2] = 0xFFFF1050  -- running
flagcolors[3] = 0xFFB04090  -- stopping
flagcolors[4] = 0xFF7070FF  -- jumping
flagcolors[5] = 0xFFD030FF  -- falling
flagcolors[6] = 0xFFA070FF  -- ducking
flagcolors[7] = 0xFFE020B0  -- sliding
flagcolors[9] = 0xFFD0D010  -- inhaling
flagcolors[10] = 0xFFD0A010 --  spitting
flagcolors[11] = 0xFFD0A010 --  swallowing
flagcolors[12] = 0xFFE08080 --  powerup use
flagcolors[13] = 0xFFE050FF --  flying

flagtext = {}
flagtext[0] = "stnd"
flagtext[1] = "walk"
flagtext[2] = "run"
flagtext[3] = "stop"
flagtext[4] = "jump"
flagtext[5] = "fall"
flagtext[6] = "duck"
flagtext[7] = "slde"
flagtext[9] = "succ"
flagtext[10] = "spit"
flagtext[11] = "swal"
flagtext[12] = "powr"
flagtext[13] = "fly"

-- A function for the values to display in column "P1 Right"
-- Return the value in "Flags" log if the value in "XVel" is greater than 0 and the value in "Flags" is 1, 2, 3 or 7, else it returns nil
function RightBtnPrinterValue(index)

	local xv = GetLogValue("XVel", index)
	if xv ~= nil and xv > 0 and AnyValueMatching(GetLogValue("Flags", index), {1, 2, 3, 7}) 
	then return GetLogValue("Flags", index)
	end
	
end

-- Same as above, but if "XVel" is less than 0
function LeftBtnPrinterValue(index)

	local xv = GetLogValue("XVel", index)
	if xv ~= nil and xv < 0 and AnyValueMatching(GetLogValue("Flags", index), {1, 2, 3, 7})
	then return GetLogValue("Flags", index)
	end
	
end

-- Returns the value in "Flags" if the value is in values
function FlagPrinterValue(index, values)

	if AnyValueMatching(GetLogValue("Flags", index), values)
	then return GetLogValue("Flags", index)
	end

end

-- Only prints text, if there is a change in the value in the log "Flags"
function FlagColumnText(value, index)

	if Difference("Flags", index) ~= 0
	then return flagtext[value]
	end
	
	return ""

end

-- New Column with the flagcolors table for coloring and FlagColumnText for outputting text
AddPrinter("Flag", "Flags", flagcolors, FlagColumnText, 4)

AddPrinter("P1 Up",    function(index) return FlagPrinterValue(index, {13}) end, flagcolors, "") -- Color column "P1 Up" with the color in colortable if the value in "Flags" is 13
AddPrinter("P1 Down",  function(index) return FlagPrinterValue(index, {6, 7, 11}) end, flagcolors, "")
AddPrinter("P1 Right", RightBtnPrinterValue, flagcolors, "")
AddPrinter("P1 Left",  LeftBtnPrinterValue, flagcolors, "")
AddPrinter("P1 B",     function(index) return FlagPrinterValue(index, {9, 10, 12}) end, flagcolors, "")
AddPrinter("P1 A",     function(index) return FlagPrinterValue(index, {4, 5}) end, flagcolors, "")

InitializeLogger() -- Needed to load files and setting up variables and callbacks

while true do
	
	UpdateLogger() -- Logs values
	
	emu.frameadvance();
end