Default values for types problem in additional files

Previous topic - Next topic

AndyH

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


AndyH

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.

Moru

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

AndyH

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.

Kitty Hello

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.