Author Topic: Small error with Types  (Read 1434 times)

Offline bigsofty

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 2640
    • View Profile
Small error with Types
« 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
« Last Edit: 2011-Mar-16 by bigsofty »
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)

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10719
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: Small error with Types
« Reply #1 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.

Offline bigsofty

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 2640
    • View Profile
Re: Small error with Types
« Reply #2 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
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)

Offline bigsofty

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 2640
    • View Profile
Re: Small error with Types
« Reply #3 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
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

  • Guest
Re: Small error with Types
« Reply #4 on: 2011-Mar-17 »
GPC must have taken offense to literal integers:)

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10719
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: Small error with Types
« Reply #5 on: 2011-Mar-17 »
try constant instead of global. a tad faster.

Offline bigsofty

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 2640
    • View Profile
Re: Small error with Types
« Reply #6 on: 2011-Mar-17 »
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)