User File #638740451358732477

Upload All User Files

#638740451358732477 (unlisted) - pictionary print word.lua

pictionary print word.lua
Game: Pictionary ( NES, see all files )
0 downloads
Uploaded 11 hours ago by warmCabin (see all 30)
--reads the word to be guessed from RAM, returned as an ASCII string
--Uses readbyterange, which is actually kind of annoying! Mostly because Lua.
--Also note that Pictionary pads all words to 16 chars, and this function leaves those spaces in.
--All the code here ingores spaces anyway, so there's no point in trimming anything.
local function readWord()
	local word = memory.readbyterange(0x0448, 16)
	local ret  = ""
	for i=1,#word do
		local c = word:sub(i,i):byte() --ith character, as a byte.
		if c == 0x28 then --space
			ret = ret.." "
		elseif c>=0x0A and c<= 0x23 then --it's a letter
			ret = ret..string.char(c-0x0A+65) --convert byte from Pictionary encoding to ASCII, then concatenate
		else
			ret = ret.."." --dot for unknown characters, just like the hex editor
		end
	end
	return ret
end

local function main()
  gui.text(5, 10, readWord())
end
emu.registerafter(main)