GLBasic forum

Main forum => Bug Reports => Topic started by: AndyH on 2009-Aug-09

Title: Default values for types problem in additional files
Post by: AndyH on 2009-Aug-09
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
Title: Re: Default values for types problem in additional files
Post by: MrTAToad on 2009-Aug-09
Yes, get that here too!
Title: Re: Default values for types problem in additional files
Post by: AndyH on 2009-Aug-10
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.
Title: Re: Default values for types problem in additional files
Post by: Moru on 2009-Aug-10
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
Title: Re: Default values for types problem in additional files
Post by: AndyH on 2009-Aug-10
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.
Title: Re: Default values for types problem in additional files
Post by: Kitty Hello on 2009-Aug-11
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.