Post subject: lua forms and canvas issue
Joined: 12/11/2017
Posts: 3
I'm having trouble with lua. I'm trying to get a picture to display and i keep getting attempt to call field 'drawImage' (a nil value). Getting the same kind of error whether I use forms or lua canvas and I can't figure out why.
local pokedex = forms.newform(280, 360, "Kanto Pokedex")

while true do
	local opponent = memory.read_u8(0xCFE5)
	
	if opponent == 36 and pkmnHP ~= 0 then
		forms.drawImage(pokedex, "16.png", 10, 10)
	elseif opponent == 165 and pkmnHP ~= 0 then
		forms.drawImage(pokedex, "19.png", 10, 10)
	end
	emu.frameadvance()
end
Post subject: Re: lua forms and canvas issue
Amaraticando
It/Its
Editor, Player (158)
Joined: 1/10/2012
Posts: 673
Location: Brazil
Telephia wrote:
I'm having trouble with lua. I'm trying to get a picture to display and i keep getting attempt to call field 'drawImage' (a nil value). Getting the same kind of error whether I use forms or lua canvas and I can't figure out why.
There's no function called drawImage in table forms. Check this http://tasvideos.org/Bizhawk/LuaFunctions.html
Joined: 12/11/2017
Posts: 3
Yes there is? https://imgur.com/a/ZVBp7 Thats both in forms and LuaCanvas. So unless the documentation is horribly wrong...
Masterjun
He/Him
Site Developer, Skilled player (1971)
Joined: 10/12/2010
Posts: 1179
Location: Germany
Um yeah, Amaraticando, the very page you linked does have the drawImage in the forms tab. Good job on that! :D So Telephia, your error (obviously) means that there is no drawImage function in your forms table. You can try print(forms) to see all the values (functions) it has. Maybe you're using an old version of BizHawk which didn't implement the function yet? Maybe you didn't post the full script and accidentally overwrite the forms variable somewhere? In any case, there would be a follow-up bug: To use drawImage in the first place, you need to create a PictureBox with forms.pictureBox and use the returned variable as the first argument in the drawImage function (instead of using the variable from the forms.newform).
Warning: Might glitch to credits I will finish this ACE soon as possible (or will I?)
Amaraticando
It/Its
Editor, Player (158)
Joined: 1/10/2012
Posts: 673
Location: Brazil
Ops, I probably was in the wrong 'tab' of the page. Sorry...
Joined: 12/11/2017
Posts: 3
Ok that did it! I had an older version and didn't realize it. And the thing with the pictureBox. Thanks so much for the help! And yeah, I figured that was probably it Amaraticando. No worries. Problem solved ^^