Monkey Strict mode issue - docs ain't helping :/
Community Forums/Monkey Talk/Monkey Strict mode issue - docs ain't helping :/| 
 | ||
| Example taken from Docs, this works: 
Import mojo.app
Import mojo.graphics
Import mojo.input
Class MyGame Extends App
	Field x:Int=0
	Field y:Int=0
	Field playerShipSprite:Image
		
	Method OnCreate()
		'Load any images and sounds here
		'ship.png must be found in your project's .data folder
		playerShipSprite=LoadImage("ship.png")
		SetUpdateRate 30
		End
	
	Method OnUpdate()
		x=MouseX
		y=MouseY
	End
	
	Method OnRender()
		Cls
		DrawImage playerShipSprite,x,y
	End
End
Function Main()
	New MyGame
End
But when I add THIS to the beginning: Strict It stops on "Method OnCreate" and says "syntax error" Try for example this: Strict Import mojo Function Main:Int() New MyApp Return 0 End Function Class MyApp Extends App Method OnCreate() End Method Method OnUpdate() End Method Method OnRender() End Method End Class If you remove "Strict", it works just fine. | 
| 
 | ||
| if you put Strict after all the Imports, does it work ? | 
| 
 | ||
| Strict needs to be on top. Aka, won't work (gets compile error then, pointing line "Strict") | 
| 
 | ||
| Hum, may be is the content of the method OnCreate then. What happens if you comment out all the commands in the methods ? May be it does need a return type in each method, like in the Main:int() So may be Method OnCreate:int() would do the trick ? Last edited 2011 | 
| 
 | ||
| Strict mode is... well... strict. You need to declare Method/Function returns, actually return them, etc. Last edited 2011 | 
| 
 | ||
| Works: Strict Import mojo Function Main:Int() New MyApp Return 0 End Function Class MyApp Extends App End Class Doesn't work: Strict Import mojo Function Main:Int() New MyApp Return 0 End Function Class MyApp Extends App Method OnCreate() End Method End Class Gets "compile error" on line "Method OnCreate()". | 
| 
 | ||
| Ah, you wrote it while I was typing! :) Gotcha. Thanks. EDIT, yeh, so this works: Strict Import mojo Function Main:Int() New MyApp Return 0 End Function Class MyApp Extends App Method OnCreate:Int() Return 0 End Method End Class Last edited 2011 Last edited 2011 | 
| 
 | ||
| Exactly, try Method OnCreate:int() | 
| 
 | ||
| Yeh, well would be GOOD that Docs would use Strict mode. For example, when you check out OnCreate documentation, it has: "Method OnCreate()" No, "Method OnCreate:int()" | 
| 
 | ||
| Agreed :) | 
| 
 | ||
| I was falling over this too and decided not to use strict fro now. Thanks for the info. | 
| 
 | ||
| Shouldn't it say also "Return 0:Int", since that has been always a problem in BlitzMax that it guesses the wrong number types, or perhaps that should be then ExtremeStrict. Or perhaps declaring a "Global Zero:Int=0:Int" variable would be better, then the compiler might notice that you are using the same memory location, and doesn't need to check the memory location for each copy/pasted 0 in the code seperately. Last edited 2011 | 
| 
 | ||
| Here is an example of using Strict for your main/base code: Hope that helps:) L8r, Last edited 2011 | 
| 
 | ||
| it seems that only End works no endif,endfunction,endclass right? Last edited 2011 Last edited 2011 | 
| 
 | ||
| @Lumooja, I'm always amazed about your goddamn eagle eyes ;) ... although in this case, "Return 0" seems to work just fine. @slenkar: "End Class" works fine, so does "End Function" | 
| 
 | ||
| oh ok i was using endclass with no space, thanks hopefully compilation error messages improve in the future | 
| 
 | ||
| If you dont want to return anything, use void: Function Main:Void() New MyApp End Function |