Copying and comparing TYPES?

Previous topic - Next topic

bigtunacan

I'm not trying to reference the type definition so much as I am trying to reference an INSTANCE of the the type definition.  Like Slydog said; it is a huge waste of memory to have to create many copies in memory of the same object; this is what I'm trying to avoid.  I'm releasing on so low end Android devices too so my memory is cherished resource. 

@Kitty Hello,
     I just tried the ALIAS command and it doesn't seem to work quite right.  Maybe it has problems when trying to alias to TYPEs rather than a simple data type? but definitely was not correctly pointing to the object :(

kanonet

ALIAS works correct for me:
QuoteLOCAL a AS Tmytype
ALIAS b AS a
This works too:
QuoteLOCAL a AS Tmytype
ALIAS b AS a.id
But ALIAS has one limitation, this does not work:
QuoteLOCAL a AS Tmytype
LOCAL b AS Tmytype
ALIAS b.a AS a

Did you try the last one or had problems with one of the other samples? Basically atm you can just store a pointer in a variable with normal datatype (you dont need to define it before the alias, its local by default), but you cant store the pointer in a type, which would be great.
Lenovo Thinkpad T430u: Intel i5-3317U, 8GB DDR3, NVidia GeForce 620M, Micron RealSSD C400 @Win7 x64

Kitty Hello

Alias makes a variable that points to (=reference) whats right of the "as" argument. You cannot hold references in types. Also reference pointers might break if you point into an array element and reallocate the container (dimpush, dimdel, ...)

bigtunacan

Here is my fully implemented TYPE
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


I create my first TYPE like so
Code (glbasic) Select

UBIFALLSPR = FILE_LOADANIM("/Animations/Ubi/", "falling" + UBI_INDEX + ".xml")


After this I do my alias

Code (glbasic) Select

ALIAS UBISTATE AS UBIFALLSPR


In an update statement I call UBISTATE.anim() so that whatever I'm currently pointing to should animate.

When I call UBISTATE.draw(x,y) nothing shows up on screen.

If I do the same directly as UBIFALLSPR.draw(x,y) it shows up fine and is animating correctly (anim is still called on UBISTATE); so it seems something is being corrupted.