GLBasic forum

Main forum => Bug Reports => Topic started by: bigsofty on 2011-Mar-16

Title: Small error with Types
Post by: bigsofty on 2011-Mar-16
"sprSheets[]" are an array of advanced types.

using...

Code (glbasic) Select
LOCAL ss AS TSprSheet
DIMPUSH self.sprSheets[], ss
self.sprSheets[-1].create("sprites1.png") // .Create


causes...
Code (glbasic) Select

precompiling:
GPC - GLBasic Precompiler V.7.861 SN:114ddfeb - 3D, NET
"..\LIBS\sprites_lib.gbas"(528) error : call to undefined function : TSprSheet


Changing...

Code (glbasic) Select
self.sprSheets[-1].create("sprites1.png")
to...
Code (glbasic) Select
self.sprSheets[LEN(self.sprSheets[])-1].create("sprites1.png")
produces the same error.

but removing the "-1"(self.sprSheets[LEN(self.sprSheets[])].create("sprites1.png")), it compiles fine but is of no use.

Using...
Code (glbasic) Select
LOCAL L = LEN(self.sprSheets[])-1
self.sprSheets[L].create("sprites1.png")

...works, but is not as neat. Oh, and BOUNDS does not work either(When the LEN is swapped for it).

Cheers,

Ian


Full lib, as it is...

Code (glbasic) Select
// Spr Sheet Type

TYPE TSprSheet
name$ // Filename
sprnum% // GLB Sprnum holding texture
w% // Width
h% // Height
tw% // Tile Width
th% // Tile Height
trn% // Has alpha layer

FUNCTION create: filename$, tileW%=0, tileH%=0
LOCAL s% = GENSPRITE()
LOADSPRITE filename$, s%
self.name$ = filename$
self.sprnum% = s%
GETSPRITESIZE s%, self.w%, self.h%
ASSERT ((self.w% = 0) OR (self.w% = 0)) // File not open!
self.tw% = tileW%
self.th% = tileH%
ENDFUNCTION
ENDTYPE



TYPE TSprBank
sprSheets[] AS TSprSheet

FUNCTION blah:
LOCAL ss AS TSprSheet
DIMPUSH self.sprSheets[], ss
self.sprSheets[-1].create("sprites1.png") // .Create
///... stopped coding here.
ENDFUNCTION

ENDTYPE
Title: Re: Small error with Types
Post by: Kitty Hello on 2011-Mar-16
Poor GPC compiler. Feed with stuff he can't digest. Pre-chew it, please:

Code (glbasic) Select

ALIAS lastsheet AS self.sprSheets[-1]
lastsheet.create("sprites1.png") // .Create


The GPC sometimes has a hard time with complex expressions to find the resulting type. If you ALIAS a part of of, usually it gets the grip and works.
Title: Re: Small error with Types
Post by: bigsofty on 2011-Mar-16
Thanks for that culinary suggestion there Gernot! ;)

I'm not sure I want to use ALIAS as the final Type will have lots of methods within it and it could get a bit messy if I have to ALIAS a lot in the parent code.

I'll have a rethink, thanks any ways.


Ian
Title: Re: Small error with Types
Post by: bigsofty on 2011-Mar-16
This works...

Code (glbasic) Select
global lastOne% = -1
...
self.sprSheets[lastOne].create("sprites1.png") // .Create


Hehe, looks a little weird but feels better.

Cheers,


Ian
Title: Re: Small error with Types
Post by: MrTAToad on 2011-Mar-17
GPC must have taken offense to literal integers:)
Title: Re: Small error with Types
Post by: Kitty Hello on 2011-Mar-17
try constant instead of global. a tad faster.
Title: Re: Small error with Types
Post by: bigsofty on 2011-Mar-17
It is? Nice tip, thanks!

Cheers,


Ian