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 / Globals, globals, globals... Where are my globals???

Author
Message
flibX0r
23
Years of Service
User Offline
Joined: 14th Feb 2003
Location: Western Australia
Posted: 27th May 2003 16:25
I can actually find my globals. The title is just a quote from "Windows Game Programming for Dummies" by Andre LaMothe (Chapter 12)

I can make globals (after finding out on these forums - thanks guys), but how do you make an array global? I just can't figure it out. Thats the one thing that they didn't cover in detail in the help section :*(

Please help me. My sweet, poor, defenceless animation system depends on it.
"But we couldn't do that Mr Flibble," questioned Rimmer. "Who'd clean up the mess?"
--Twin P4 Xeon 2.0 Ghz, GeForce Quadro4 XGL 128MB, 1Gb DDR RAM, 19" Flat Screen--
Shadow Robert
23
Years of Service
User Offline
Joined: 22nd Sep 2002
Location: Hertfordshire, England
Posted: 27th May 2003 16:29
function MyFunction()
global dim myarray(0)
endfunction

easi eh

Within the Epic battle of the fates the Shadow and the Angel will meet. With it will harbinger the very fight of good vs evil!
flibX0r
23
Years of Service
User Offline
Joined: 14th Feb 2003
Location: Western Australia
Posted: 27th May 2003 16:44
Raven, do you EVER leave the forums??? it seams you are always the first person to reply to anything. Thanks tho

"But we couldn't do that Mr Flibble," questioned Rimmer. "Who'd clean up the mess?"
--Twin P4 Xeon 2.0 Ghz, GeForce Quadro4 XGL 128MB, 1Gb DDR RAM, 19" Flat Screen--
Beta1
23
Years of Service
User Offline
Joined: 28th Dec 2002
Location:
Posted: 27th May 2003 18:08
Am I being dim? I thought arrays were always global?

Kevin Picone
23
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 27th May 2003 18:44
Well they are, providing you don't re-dim the array inside a function. This will screw up the scope..

in that case it only seems happy when you force both dims as global

l8r,
Kevin Picone
[url]www.underwaredesign.com[/url]
Shadow Robert
23
Years of Service
User Offline
Joined: 22nd Sep 2002
Location: Hertfordshire, England
Posted: 27th May 2003 19:06
lol... i don't have a great deal to do when things are compiling or rendering - right now my system is doing both.
suppose i could go watch daytime TV

when you dim arrays outside of a function they're global, but everything within a function is encapsulated unless you tell the program otherwise ... but dbp can be fussy about the local & globals.
so just to be safer than sorry i'd recommend unless you plan to only use values once then you should setup if you want them to be global or local no matter where they are.

i can seem like a pain but it make dbp extra happy

Within the Epic battle of the fates the Shadow and the Angel will meet. With it will harbinger the very fight of good vs evil!
Ian T
23
Years of Service
User Offline
Joined: 12th Sep 2002
Location: Around
Posted: 27th May 2003 19:31
I was under the impressive that if a global was already dim that it couldn't get stupider--

Ahem.

I mean, I was under the impression that if a global was already dimmed that if you altered it inside a function it would change... just like editing an array, which works fine for me.

As in:

Coffee as integer

MyFunction:

Coffee=15

Endfunction

Would set coffee to 15.

But if NOT, then that would explain the problem I'm having reading the player start position from a map file...

--Mouse

Famous Fighting Furball
Shadow Robert
23
Years of Service
User Offline
Joined: 22nd Sep 2002
Location: Hertfordshire, England
Posted: 27th May 2003 21:52 Edited at: 27th May 2003 21:53
no thats really a common mistake... if you want that value to work 100% then you need to do this instead



however if you do



that'll always work god knows why, because arrays should really be just sections of memory like the other values.

as long as you remember a global value declared with global, a local/private value declared as a local ... and then use no designation for values that are really going to be used in that loop

so like



that'll work a treat
reason for encapsulating the funcitons is so you don't have to think ip new names for things all the time.

Within the Epic battle of the fates the Shadow and the Angel will meet. With it will harbinger the very fight of good vs evil!
Ian T
23
Years of Service
User Offline
Joined: 12th Sep 2002
Location: Around
Posted: 28th May 2003 01:23
Ah, thanks, that helps considerably.

Was wonderin why I was having such annoying problems with my code

--Mouse

Famous Fighting Furball

Login to post a reply

Server time is: 2026-07-11 09:30:06
Your offset time is: 2026-07-11 09:30:06