Monkey Strict mode issue - docs ain't helping :/

Community Forums/Monkey Talk/Monkey Strict mode issue - docs ain't helping :/

gameproducer(Posted 2011) [#1]
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.


semar(Posted 2011) [#2]
if you put Strict after all the Imports, does it work ?


gameproducer(Posted 2011) [#3]
Strict needs to be on top. Aka, won't work (gets compile error then, pointing line "Strict")


semar(Posted 2011) [#4]
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


Muttley(Posted 2011) [#5]
Strict mode is... well... strict.

You need to declare Method/Function returns, actually return them, etc.



Last edited 2011


gameproducer(Posted 2011) [#6]
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()".


gameproducer(Posted 2011) [#7]
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


semar(Posted 2011) [#8]
Exactly, try Method OnCreate:int()


gameproducer(Posted 2011) [#9]
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()"


semar(Posted 2011) [#10]
Agreed :)


MikeHart(Posted 2011) [#11]
I was falling over this too and decided not to use strict fro now. Thanks for the info.


Canardian(Posted 2011) [#12]
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


Richard Betson(Posted 2011) [#13]
Here is an example of using Strict for your main/base code:



Hope that helps:)

L8r,

Last edited 2011


slenkar(Posted 2011) [#14]
it seems that only End works

no endif,endfunction,endclass

right?

Last edited 2011

Last edited 2011


gameproducer(Posted 2011) [#15]
@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"


slenkar(Posted 2011) [#16]
oh ok i was using endclass with no space, thanks

hopefully compilation error messages improve in the future


therevills(Posted 2011) [#17]
If you dont want to return anything, use void:

Function Main:Void()
	New MyApp
End Function