What's wrong with this basic code?

Monkey Forums/Monkey Programming/What's wrong with this basic code?

pinete(Posted 2011) [#1]
Hi all,
maybe someone could help me out checking this piece of basic code and point me where the problem coulb be.
Basically, the image i'm loading doesn't appear on the screen..
Thanks a lot ;)

Import mojo

Class MainGame Extends App

	Field x,y
	Field image1: Image
	Method OnCreate()
		
		SetUpdateRate 60
		x=100
		y=100
		
		image1 = LoadImage ("fi1.png")
		
	End Method
	
	Method OnUpdate()
		x=x+3
	End Method
	
	Method OnRender()
		
		Local r
		Cls 0,0,0
		SetColor 255,255,255
		DrawLine 100,x-100,200,200
		
		'For r = 1 To 100
			DrawImage image1,20,20 'Rnd(1,200),Rnd(1,200) 
		'Next

	End Method
End



Function Main ()
	New MainGame
End



Volker(Posted 2011) [#2]
Works here. Is the image in the filename.data directory?


therevills(Posted 2011) [#3]
Quickly tested... works for me.

What version of Monkey are you using?

What is your folder structure?

What is the image called in your folder? It is case-sensitive...


GfK(Posted 2011) [#4]
Shouldn't that be self.image1 = LoadImage??

Not sure but without Strict mode, wouldn't your code 'as is' create a local object called image1 within OnCreate()?


therevills(Posted 2011) [#5]
Nope - Monkey requires you to declare your variables before you use them with or without Strict.


pinete(Posted 2011) [#6]
Thanks all!
I didn't know it is a must to save all the gfx assets in the folder myappname.data, and it is not created automatically or whatever.. :)
I've created the folder, copies the image and it works!
Thanks so much everybody.
BTW, could you please let me know when it's writen other rules of this kind in the monkey docs?


matt(Posted 2011) [#7]
This particular fact is in docs/gettingstarted.html in the Mojo quick tips section.

You can also look at the structure of the bananas code samples


pinete(Posted 2011) [#8]
thank you very much matt ;)