News:

Building a 3D Ray Tracer  By stevmjon

Main Menu

Scope of Constants?

Started by thaaks, December 19, 2005, 02:32:20 PM

Previous topic - Next topic

thaaks

What is the scope of constants?

I have a project made of main.pba, title.pba and game.pba.
Constants that are defined in main.pba have their given value (verified with the debugger).
But they are 0 in title.pba and game.pba.

I think I could work around this by using Globals but is this on purpose?

It's missing in the documentation of Constant's online help...

I thought constants were readonly globals...

Cheers,
Tommy

thaaks

Problem solved!
It does work with Constants. I simply forgot to set the main file (where the constants are defined) as the main file of the project.

Although this should be done automatically by the IDE I think  :rolleyes:

kevin

#2
Left most source is TOP,   Right most source is bottom

I.e

Intro,  Game, Main


>> compiles the code sections as


Intro
..
...
..

Game
..
..
..

Main
..
..
..


Basic enters your program at the TOP and falls through.  The sources are stacked (for want of a better word) from Left to Right in the IDE terms.   If you declare a constant in MAIN, then attempt to use it before it's declared, it'll be dynamically cast as a variable.  


PlayBASIC Code: [Select]
; intro section

; this will print 0, since it's not the constant bellow, but rather a Variable called MyConstant
print MyConstant



; main bit
constant MyConstant=1

; this will print 1 (the constant)
print MyConstant








What you need is your declares on top.


i.e.

MyDeclares,  intro, Game, Main


or



I.e

 Main, Intro,  Game