Author Topic: Graphic bug I can't understand!  (Read 5410 times)

Offline Moru

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1781
    • View Profile
    • Homepage
Re: Graphic bug I can't understand!
« Reply #15 on: 2010-Jul-29 »
It has been working now for a while again so I started using it.

MrTAToad

  • Guest
Re: Graphic bug I can't understand!
« Reply #16 on: 2010-Jul-29 »
Quote
don't do that in GLB (assigning a value when initialising/defining variables) as this is only guaranteed to work when used in conjunction with the RGB() function...
Constants should be used for things like that...
« Last Edit: 2010-Jul-29 by MrTAToad »

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: Graphic bug I can't understand!
« Reply #17 on: 2010-Jul-29 »
You can assign GLOBAL a = foo(), but you are not able to use strings or any of the GLBasic commands inside. The problem is, that this foo() is called in the constructor _before_ the GLBasic engine is set up, whereas
GLOBAL g
g=foo() // this assignement is done during runtime.

MrTAToad

  • Guest
Re: Graphic bug I can't understand!
« Reply #18 on: 2010-Jul-29 »
You can assign GLOBAL a = foo(), but you are not able to use strings or any of the GLBasic commands inside. The problem is, that this foo() is called in the constructor _before_ the GLBasic engine is set up, whereas
GLOBAL g
g=foo() // this assignement is done during runtime.
I tried that, but the program didn't actually run :)

Code: GLBasic [Select]
GLOBAL a%=foo()

DEBUG a%
END

FUNCTION foo%:
        RETURN 12
ENDFUNCTION

Offline okee

  • Dr. Type
  • ****
  • Posts: 324
    • View Profile
Re: Graphic bug I can't understand!
« Reply #19 on: 2010-Jul-29 »
Regarding the scope of Global Local
From tests this is what i gathered:

2 files in a project
main.gbas //the main code file
include.gbas //included file

Global  declared in main.gbas is available to main.gbas and include.gbas
Global declared in include.gbas must have an assignment otherwise the compiler throws variable is not explicitly defined error
once declared with an assignment it's available to main.gbas and include.gbas

Local declared outside a function/sub in main.gbas is only available to functions/subs in main.gbas
Local outside a function/sub in include.gbas  is not allowed

Also using GENSPRITE() as described in the manual
Code: GLBasic [Select]
GLOBAL gImgFoo = GENSPRITE(); LOADSPRITE "foo.png", gImgFoo
used to cause problems when declaring and assigning has this changed ?
or do we still have to do
Code: GLBasic [Select]
GLOBAL gImgFoo
gImgFoo = GENSPRITE()


okee
Android: Samsung Galaxy S2 -  ZTE Blade (Orange San Francisco) - Ainol Novo 7 Aurora 2
IOS: 2 x Ipod Touch (1G)

MrTAToad

  • Guest
Re: Graphic bug I can't understand!
« Reply #20 on: 2010-Jul-29 »
RGB is the only command that be used with variable initialisation.

Offline matchy

  • Prof. Inline
  • *****
  • Posts: 1543
    • View Profile
Re: Graphic bug I can't understand!
« Reply #21 on: 2010-Jul-29 »
Oh yeah! Even this works...
Code: GLBasic [Select]
CONSTANT rnd_color=RGB(RND(255),RND(255),RND(255))
CONSTANT rnd_red=RND(255)