custom type function and array gives "call to undefined function" error

Previous topic - Next topic

BdR

While working on my new game (I don't want to reveal too much but it has snakes 8)) I got this precompiler error. I made a custom type, made an array of this type and called a function via an array. Here is an example program that will reproduce the error, I tried it on GLBasic v9.040.
Code (glbasic) Select
CONSTANT SPR_INVADERS = 1

TYPE TInvader
  x%
  y%
  frame%
  FUNCTION Reset:
    self.frame = -1
    self.x = -1
    self.y = -1
  ENDFUNCTION
  //.. etc
ENDTYPE

GLOBAL Invaders[] AS TInvader

FUNCTION InvadersShiftLeft:

  DIM Invaders[11][5]
  LOCAL x%, y%, i%

  // shift one column to left
  FOR x = 0 TO 11-1-1
    FOR y = 0 TO 5-1
      Invaders[x][y] = Invaders[x+1][y]
      Invaders[x+1][y].Reset() // this gives precompiler error "call to undefined function : TInvaders"

      i = x+1
      Invaders[i][y].Reset() // this compiles fine
    NEXT //y
  NEXT //x
ENDFUNCTION

It seems that it gives this error when you put in more than just a single variable between the brackets. I can easily work around it so if it is there for a reason that's fine by me, but it looks like a bug.

MrTAToad

The compiler can get confused with expressions in arrays

Kitty Hello

Use:
Code (glbasic) Select

      ALIAS invi AS Invaders[x+1][y]
      invi.Reset() // this gives precompiler error "call to undefined function : TInvaders"


Sorry.