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 / How to define global types?

Author
Message
Bursar
16
Years of Service
User Offline
Joined: 17th Sep 2008
Location:
Posted: 22nd Sep 2008 16:01 Edited at: 22nd Sep 2008 18:09
I have a dba file in my project that contains a function that creates all my global variables. I call this function at the start of my program, and my variables are all available to me with the right values.

However, when I create a type in my globals file, it doesn't seem to work as I expect. I get the error: cannot find field 'x'

code from globals.dba


code from main.dba


If I move all of the type declaration stuff into main.dba it works as expected, but obviously my code becomes a right mess. If I can move this kind of thing out to a seperate source file, it'd make my life easier.

So is there a way to get types working globally?

[edit -> just noticed a typo in the code, but it doesn't affect the problem
Bursar
16
Years of Service
User Offline
Joined: 17th Sep 2008
Location:
Posted: 22nd Sep 2008 18:01
That's what I do.

There's the globals.dba file, and a funciton in there called init_globals() where I setup my variables.

I call that function in my program before I try to use any of my variables.

All the variables declared in that function work perfectly except for the type declaration.
Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 22nd Sep 2008 19:03
Quote: "Types are always global, but they must be declared prior usage"


Not true. I always put my types at the end of my dba files.

Bursar
16
Years of Service
User Offline
Joined: 17th Sep 2008
Location:
Posted: 22nd Sep 2008 19:08
Zotoaster: Maybe when my posts have been authorised by the mods and this thread makes more sense again () you wouldn't mind maybe pointing out where I've gone wrong?

Thanks.
Bursar
16
Years of Service
User Offline
Joined: 17th Sep 2008
Location:
Posted: 22nd Sep 2008 20:27
The Type declaration is inside the init_globals() function in globals.dba and that function is called immediately after doing stuff like setting the screen res, so well before I get into actually doing anything with my program.

Maybe I need to restructure, but I'm just a bit worried that the compiler is going to be super picky about this stuff and I'll spend ages reorganising my code, and still not be any further forward.

It's not the end of the world to have the type declarations in my main dba file, so I'll probably just live with it until I better understand what's going on.
Rudolpho
18
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 22nd Sep 2008 23:23
Well, I have all my declarations embeded in a subroutine that's called after setting up some constants.
I have several function declarations before my type-including routine, which is actually in my third included source file, and everything works just fine.
Try changing your function to a routine if you don't want to put it at the beginning of your main source (change the function init_globals() line to init_globals: and the endfunction line to return. Then call this using goSub init_globals).

"I kören hörs de brummande busarna Björnligan och Gondolen"
Game pro
20
Years of Service
User Offline
Joined: 21st Mar 2004
Location: Usa
Posted: 26th Sep 2008 21:16 Edited at: 26th Sep 2008 21:18
I usually have all my Global, Types, and Array declarations in my Main source file. Then I set Function Main() at the end. The rest of my source files just hold all the different functions for the game.

Check out my dev forums at:
http://z15.invisionfree.com/ProjectRWP
calcyman
17
Years of Service
User Offline
Joined: 31st Aug 2007
Location: The Uncertainty Principle
Posted: 28th Sep 2008 17:44
Quote: "Well, I have all my declarations embeded in a subroutine that's called after setting up some constants."


Subroutines can also be called in #included files, as well as the main source file.

The optomist's right, The pessimist's right.

Login to post a reply

Server time is: 2024-09-27 20:22:05
Your offset time is: 2024-09-27 20:22:05