TYPE is not declared

Previous topic - Next topic

bigtunacan

I'm getting a TYPE is not declared error, but I don't see what is wrong with my code.  I've included the snippets here.

First I created a base animation TYPE; I'm referencing it directly in a few places and it works correctly.
Code (glbasic) Select


TYPE ANIMATION
ID // This is a unique identifier for this particular animation
ANIM_INDEX // This is the sprite index
CURR_FRAME
NUM_FRAMES
NAME$
STEPTIME% // delta step for fixed or absolute time to finish
LAST_UPDATE_TIME
TIMESTEPMODE
LOOPMODE

FUNCTION draw:x%,y%
DRAWANIM self.ANIM_INDEX, self.CURR_FRAME, x%, y%
ENDFUNCTION

FUNCTION init: index%, width%, height%, name$
self.ANIM_INDEX=index%
self.CURR_FRAME=0

LOCAL sx%,sy%
GETSPRITESIZE index, sx%, sy%
self.NUM_FRAMES = sx%/width%
self.NAME$=name$
self.STEPTIME%=100
self.LAST_UPDATE_TIME = MASTERTIMER
self.LOOPMODE=LOOPFOREVER
ENDFUNCTION

FUNCTION anim:
IF(GETTIMERALL() > (self.LAST_UPDATE_TIME + self.STEPTIME%))
self.CURR_FRAME = IIF(self.CURR_FRAME>=(self.NUM_FRAMES-1), 0, self.CURR_FRAME+1)
self.LAST_UPDATE_TIME = GETTIMERALL()
ENDIF
ENDFUNCTION

FUNCTION is_equal: an AS ANIMATION
IF an.ID = self.ID
RETURN TRUE
ELSE
RETURN FALSE
ENDIF
ENDFUNCTION

ENDTYPE


Then I tried to reference the ANIMATION type from within another TYPE; this is where I have the issues

Code (glbasic) Select


TYPE BLOWFISH
STATE%
STATE_START%=0
STATE_TRANSFORM%=1
STATE_BLINK%=2
STATE_FROWN%=3
STATE_HUGE%=4

START AS ANIMATION
TRANSFORM AS ANIMATION
BLINK AS ANIMATION
FROWN AS ANIMATION
HUGE AS ANIMATION

SUB bf_init:
self.START = FILE_LOADANIM("/Animations/enemies/", "blowfish.xml")
self.TRANSFORM = FILE_LOADANIM("/Animations/enemies/", "blowfishtransform.xml")
self.BLINK = FILE_LOADANIM("/Animations/enemies/", "blowfishblink.xml")
self.FROWN = FILE_LOADANIM("/Animations/enemies/", "blowfishfrown.xml")
self.HUGE = FILE_LOADANIM("/Animations/enemies/", "blowfishhuge.xml")

self.STATE = self.STATE_START%

POSX%=0
POSY%=0
ENDSUB

SUB bf_draw:
GOSUB bf_update

SELECT self.STATE
CASE self.STATE_START%
self.START.draw(1,1)
CASE self.STATE_TRANSFORM%
self.TRANSFORM.draw(1,1)
CASE self.STATE_BLINK%
self.BLINK.draw(1,1)
CASE self.STATE_FROWN%
self.FROWN.draw(1,1)
CASE self.STATE_HUGE%
self.HUGE.draw(1,1)
DEFAULT
self.START.draw(1,1)
ENDSELECT
ENDSUB

SUB bf_update:
self.START.anim()
self.TRANSFORM.anim()
self.BLINK.anim()
self.FROWN.anim()
self.HUGE.anim()
ENDSUB

ENDTYPE

kanonet

Types can contain functions, but types can NOT contain subs. Just change your subs to functions, maybe that solves your problem?
Lenovo Thinkpad T430u: Intel i5-3317U, 8GB DDR3, NVidia GeForce 620M, Micron RealSSD C400 @Win7 x64

bigtunacan

DOH!  Thanks; that was my issue.