Small error with Types

Previous topic - Next topic

bigsofty

"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
Cheers,

Ian.

"It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration."
(E. W. Dijkstra)

Kitty Hello

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.

bigsofty

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
Cheers,

Ian.

"It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration."
(E. W. Dijkstra)

bigsofty

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
Cheers,

Ian.

"It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration."
(E. W. Dijkstra)

MrTAToad

GPC must have taken offense to literal integers:)

Kitty Hello

try constant instead of global. a tad faster.

bigsofty

It is? Nice tip, thanks!

Cheers,


Ian
Cheers,

Ian.

"It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration."
(E. W. Dijkstra)