Unknown identifier

Monkey Forums/Monkey Programming/Unknown identifier

ErikT(Posted 2011) [#1]
Hello, monkey newbie here. I'm trying to convert some blitzmax code to monkey but I get unknown identifier errors all over the place. It seems variables declared as Globals throw errors when I refer to them inside functions that reside in external imported source files. Any ideas how to tackle this?

For example:

---- main.monkey --------

Import entity

Global Ship:TEntity

Class Game2 Extends App

Method OnCreate ()
Init_Entity(Ship, 50, 50)


---- entity.monkey ------

Class TEntity

blahblah

End


Function Init_Entity(P:TEntity, PosX:Int, PosY:Int)

If P = Ship ' This throws an error


therevills(Posted 2011) [#2]
I think your problem is that you are not importing "main" into "entity":

main.monkey:


entity.monkey:



ErikT(Posted 2011) [#3]
That worked. Thanks :) The program compiles now but there's a new problem: the browser returns a null object access error for my Loadimage("ship.png"). I'm pretty sure the paths are ok, I threw the png file into every possible sub-folder of my project folder, heh. Hmmm...


Raz(Posted 2011) [#4]
Guessing somewhat, but do you need to do... Ship = New TEntity()?


therevills(Posted 2011) [#5]
Files are case-sensitive and they need to be in a folder called yourproject.data - so in your example: main.data


ErikT(Posted 2011) [#6]
Guessing somewhat, but do you need to do... Ship = New TEntity()?

Wow, I completely forgot. Now it works, thanks :D


ErikT(Posted 2011) [#7]
Is there a performance hit to speak of for GrabImage? I've been using DrawSubImageRect a lot in blitzmax for sprite sheet drawing, but monkey doesn't seem to have this function so I'll have to resort to GrabImage and SetHandle instead. I'll probably be grabbing images at 30-40 times per loop (at most).


therevills(Posted 2011) [#8]
If you like DrawSubImageRect, use DrawImageRect in Monkey:

Function DrawImageRect( image:Image, x#, y#, srcX, srcY, srcWidth, srcHeight, frame=0 )

Function DrawImageRect( image:Image, x#, y#, srcX, srcY, srcWidth, srcHeight, rotation#, scaleX#, scaleY#, frame=0 )


dave.h(Posted 2011) [#9]
i use DrawImageRect( image:Image, x#, y#, srcX, srcY, srcWidth, srcHeight, frame=0 ) and havent noticed any kind of performance hit.if anything its slightly faster.


ErikT(Posted 2011) [#10]
The thing missing from DrawImageRect as far as I can tell is the option to set handle offsets, so GrabImage and SetHandle look more appealing at the moment, at least for sprites.


slenkar(Posted 2011) [#11]
grabimage only needs to be used to generate new images, then you just draw them as you would any other images.