Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / global variables with multiple source files -or- just how global are they?

Author
Message
Miles Prower
18
Years of Service
User Offline
Joined: 6th Oct 2006
Location: U.S.A.
Posted: 2nd Jun 2008 04:04 Edited at: 2nd Jun 2008 04:08
hey folks.
So I managed to type out a project with four or five thousand lines of code before learning that you could have multiple source files. Awesome. Anyways, I've been messing around with global variables while I break the project into multiple source files, using

(as per what I've gathered from forum scavenging) to do so. The problem is that my source files can't seem to find global variable declared in other source files (the fight engine can't find the structure 'turn' when called). Are global variables incapable of being seen in other source files, or am I not declaring my integers hard enough?


--I can just define turn as a 1-dimensional array to solve the spanning problem, but I cant seem to make for loops like this work


Thx for the help,
Tails


edit - i know i could use
, but is there any way around that?
KISTech
16
Years of Service
User Offline
Joined: 8th Feb 2008
Location: Aloha, Oregon
Posted: 2nd Jun 2008 19:00
It's important to note that DBPro starts with your main source file, and then adds the included files to the END in the order they are included.

So if you create a separate source file that has nothing but your variable declarations in it, then one of the first commands in your Main source file should be to execute that code.

What I've done is just add,

Vars:

to the top of the file, and

Return

to the bottom. Then in my Main source I just

Gosub Vars

Hope that helps.

Benjamin
22
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 2nd Jun 2008 21:27
Quote: "The code that declares a global variable MUST BE EXECUTED."


Only in multiple source files, in a single source file it doesn't:



I'm not sure why it's necessary for the declaration to 'execute' when in another source file. It doesn't really make a lot of sense that the global can only be created at a certain time during execution, as all variable addresses are known before the user code actually starts executing. The only thing that happens at the point of the declaration is the initialization of the variable to zero.

Login to post a reply

Server time is: 2024-11-25 04:48:36
Your offset time is: 2024-11-25 04:48:36