Author Topic: Default values for types problem in additional files  (Read 2486 times)

Offline AndyH

  • Dr. Type
  • ****
  • Posts: 383
    • View Profile
    • http://www.ovine.net/
The ability to assign a default value to a type works for functions when it is in the main (first) GBAS file, but if you declare in an additional file you get an error.

Try this code:
Code: (glbasic) [Select]
TYPE TEST
t = RGB(255,255,255)
ENDTYPE

First in the main file, it will compile, then add a second file to your GLB project and move it in there.  I get this error (on V7 RC2):

Code: (glbasic) [Select]
*** Configuration: WIN32 ***
precompiling:
GPC - GLBasic Precompiler V.7.029 SN:4cca05d9 - 3D, NET
"second file.gbas"(7) error : command not inside function or sub

MrTAToad

  • Guest
Yes, get that here too!

Offline AndyH

  • Dr. Type
  • ****
  • Posts: 383
    • View Profile
    • http://www.ovine.net/
That is fixed now, but I have this function in my type:

TYPE ....
blah = GENSPRITE()
ENDTYPE

This is causing GLB to crash when it runs.

Offline Moru

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1786
    • View Profile
    • Homepage
Never use functions in your declarations. I'm not even using the RGB() one :-). Instead I declare a value that should not happen, for example -1 and when I start using this value I check if it's -1 and then I stuff in the value I want there.

Code: (glbasic) [Select]
FUNCTION Paint: color = -1
    IF color = -1 then color = RGB(255, 128, 0)
ENDFUNCTION

Offline AndyH

  • Dr. Type
  • ****
  • Posts: 383
    • View Profile
    • http://www.ovine.net/
I want to eliminate calling a set-up routine.  I was hoping to use the default values as a constructor, so when I create an instance of the type it will be loaded with some meaningful information.

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10732
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
RGB is the only function that can go in a TYPE default value. Please do not call a function to do that, since it might be called before main() and thus, result in a bad crash.