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.

DarkBASIC Professional Discussion / Dim's Globals, Includes and broomsticks

Author
Message
JSN
22
Years of Service
User Offline
Joined: 8th Nov 2003
Location: 127.0.0.1
Posted: 4th Dec 2003 11:11
Mooorning....

Here's a reasonably simple question for this time of the morning (well, 08.58 if you live in a sunny december wales!!)

My project is growing day by day, and naturally over the course of time I'm putting routines as seperate routines.

I've done this by selecting "Add New" in the files section and copy-and-pasting from my main code. So far so good.

Because I was doing this, I "THOUGHT" I'd need to use the #include command, but I've a huge amount of problems with this (either this is a bug, or more than likely I've been using it wrong). However, I've learnt that by simply having the file in the Files section, they are automatically appended in the code. Can be frustrating when I get an error on Line 431 and my main code is actually 200 lines, but still, I digress...

The routines I've placed in seperate files are modular, so I can carry them from project to project, but I wanted to know about the variables they use.

For example, I have a parallax starfield, which uses two arrays starX() and starY(). I would have 'liked' these variables to be dedicated to the filename "starfield.dba", but if I place them in there, all elements for the array are set to 0. Placing the array in the main program, and it works.

Whilst I can get it working, it seems a little messy that I have to define all these variables at the start of any project I do.

I also tried putting the arrays in the starfield.dba file, and TRIED to find a way of having these arrays as global, but I can't see any command that allows this (e.g. Global starX(50) )

Please DON'T flame me (like another particular thread here...!) saying that it's a BASIC language, so what can I expect. I would have thought it's a lack of learning on my part, but if it can't be done, or I'm simply going about this wrong, it would be nice to know of any alternatives.

Many thanks...

-----

~ J ~
OSX Using Happy Dude
22
Years of Service
User Offline
Joined: 21st Aug 2003
Location: At home
Posted: 4th Dec 2003 11:28
Quote: "However, I've learnt that by simply having the file in the Files section, they are automatically appended in the code. Can be frustrating when I get an error on Line 431 and my main code is actually 200 lines, but still, I digress..."

Indeed it can be annoying...

Quote: "I also tried putting the arrays in the starfield.dba file, and TRIED to find a way of having these arrays as global, but I can't see any command that allows this (e.g. Global starX(50) )"

Try doing a GLOBAL DIM startX(50)


Mirrors are more fun than television. Well, that was fun, in a not-so-fun sort of way...
JSN
22
Years of Service
User Offline
Joined: 8th Nov 2003
Location: 127.0.0.1
Posted: 4th Dec 2003 11:34
Quote: "Try doing a GLOBAL DIM startX(50)"


I'm having one of those days, I just know it...

I tried this at 06:30 this morning, didn't work, tried it now...

Yep...!!!!

Thanks TCA

-----

~ J ~
JSN
22
Years of Service
User Offline
Joined: 8th Nov 2003
Location: 127.0.0.1
Posted: 4th Dec 2003 11:36
Actually, I should say, I don't get an error, but I don't get any results at all.

-----

~ J ~
JSN
22
Years of Service
User Offline
Joined: 8th Nov 2003
Location: 127.0.0.1
Posted: 4th Dec 2003 11:39 Edited at: 4th Dec 2003 11:40
OK, I now have it working exactly how I want this, hopefully anyone having this kind of problem will learn, hence I'm passing this on...

If I have Global Dim starX(10) OUTSIDE of any functions in the seperate file, it don't work.

If I call a function called "Initialise_StarField", and place the Global Dim starX(10) in there, then call initialise_starfield from my main prog, it works.

Well I am a happy bunny, thanks again TCA.

-----

~ J ~
OSX Using Happy Dude
22
Years of Service
User Offline
Joined: 21st Aug 2003
Location: At home
Posted: 4th Dec 2003 12:01
I think I had the same problem (more or less) - a global dim would only work in the main source file... This was outside a function.
Make sure you have latest Patch.


Mirrors are more fun than television. Well, that was fun, in a not-so-fun sort of way...
JSN
22
Years of Service
User Offline
Joined: 8th Nov 2003
Location: 127.0.0.1
Posted: 4th Dec 2003 12:29
Yeah, I've got the latest patch, had a few trial and errors to see if I'm doing it right, and I've found out I don't need the Global in the function, just a simple Dim in the initialisation function in the 'append' (I won't say include) file works.

I wonder if it's anything to do with the file being actually appended to the main document?

-----

~ J ~
OSX Using Happy Dude
22
Years of Service
User Offline
Joined: 21st Aug 2003
Location: At home
Posted: 4th Dec 2003 12:34
Hard to say really...

At least it works now...


Mirrors are more fun than television. Well, that was fun, in a not-so-fun sort of way...
JSN
22
Years of Service
User Offline
Joined: 8th Nov 2003
Location: 127.0.0.1
Posted: 4th Dec 2003 12:49
Yeah, and the modular format of it now means I can port it straight away to other projects (just tested and it works).

Wooo hooooo....!

Thanks again TCA

-----

~ J ~
OSX Using Happy Dude
22
Years of Service
User Offline
Joined: 21st Aug 2003
Location: At home
Posted: 4th Dec 2003 12:54
My pleasure...


Mirrors are more fun than television. Well, that was fun, in a not-so-fun sort of way...
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 4th Dec 2003 19:33
The thing that you have to keep in mind with DBPro's arrays is that they are dynamically allocated at run-time by the DIM command itself.

If the execution path never runs through the DIM, the memory is never allocated.

Login to post a reply

Server time is: 2026-07-26 20:16:59
Your offset time is: 2026-07-26 20:16:59