Uh?
Monkey Forums/Monkey Bug Reports/Uh?
| ||
I am in the process of learning Monkey and was messing around with objects.Class TCreature Field entity:TEntity Field Position:Vector Field size:Vector Field health:Int Method New(ent:TEntity = Null) Self.entity = ent End End Class TPlayer Extends TCreature End Class TBaddie Extends TCreature Field brainSize:int Global baddies:List<TBaddie> Method New(ent:TEntity = Null, bSize:int = 1) Super.New(ent) dfsfnSelf.sdfsdfsdfsdf = bSizefdsfsdfsdf End End Notice the "dfsfnSelf.sdfsdfsdfsdf = bSizefdsfsdfsdf". This compiles and runs fine as part of the larger program, without errors. This can't be right? |
| ||
As far as I know: as long as the main code does not use a method or function it will not be syntax checked. Try to use the method... |
| ||
I does do some checks, for example, if I put a line before "Super." I get an error. As part of the learning process I do regular compiles, to check the syntax as I type, which in this case failed me unfortunately. Not a biggie but maybe this information should be of help to other noobies. :) |
| ||
If you used Strict at the top of your main code the compiler WILL check to make sure its declared. If you leave the code without Strict on top, then the compiler will automatically create the undeclared variables. This, to me, is the lazy way to code :P I prefer to know what s supposed to be allocated and as what during execution. I really don't need any wild code issues due to something like a Character vs character to throw off my application! Here's an example of Strict mode on: Strict Function Main() Print( "Strict mode on... This will cause compiler errors." ) End The above is corrected by doing the following: Strict ' Main needs a variable return type: Int Function Main:Int() Print( "Strict mode on... This will cause compiler errors." ) Return 0 ' Must return some value, 0 is generally it when nothing gets returned End Here's an example of Strict mode off: Function Main() Print( "Strict mode off... This will compile without errors." ) End Hope this helps :) |
| ||
Thank computercoder, I am pretty sure strict was already on, I'll check when I get home though. It's a very handy command for noobies as is kinda corrects you coding style. "Strict" was in after all. |