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 / Global Variables driving me crazy!

Author
Message
FieldDoc
23
Years of Service
User Offline
Joined: 30th May 2003
Location: London, UK
Posted: 8th Jun 2003 15:12
OK, i'm trying to set some variables at the top of my code so that they can be used by the main code AND functions as well without having to passed to them.

At the top of the code i'm writing something like this:



However, when I run the program in DeBug mode and look at the values of the variables i'm getting really bizarre numbers allocated to them like '14354360' for example! WTF?!
I wanna be able to use the variables in a function, e.g.:



What am I doing wrong?
Life is like a penis:
When it's soft you can't beat it, when it's hard you get screwed.
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 8th Jun 2003 15:20
Yes, you can use an array as a global variable - but I find that it's best not to (assuming that you are using DBPro).

Do it like this instead:



Then use it like this:

Rob K
Retired Moderator
23
Years of Service
User Offline
Joined: 10th Sep 2002
Location: Surrey, United Kingdom
Posted: 8th Jun 2003 15:33
@FieldDoc

Arrays are global anyway - there is no need to use the "global" statement on them.

"However, when I run the program in DeBug mode and look at the values of the variables i'm getting really bizarre numbers allocated to them like '14354360' for example! WTF?! "

The debugger cannot read individual values from arrays. What you need to do is to define a global variable of the same type as your array, eg global debug_value

Then when running the debugger, to get a value from an array, go into the CLI (the leftmost tab), type in debug_value = arrayname(index) and then go into the variable watcher and look at debug_value.

Do you want Windows menus in your DBP apps? - Get my plugin: http://snow.prohosting.com/~clone99/downloads/tpc_menus_102.zip
Shadow Robert
23
Years of Service
User Offline
Joined: 22nd Sep 2002
Location: Hertfordshire, England
Posted: 8th Jun 2003 16:12


that will work



that won't... but we change this


and it will again ... its all about understanding how each of the differen variables interact - generally though you should declare values you create as variable types (boolean|byte|word|dword|float|etc...) and also no matter what your doing you should also try to declare it as global or local else it will take it as a standard value operation life ... which is good as it allows you to redeclare these values within functions, but it is also bad as it doesn't globally make sure these values are always declared.

Functions within DBP have been changed to be self contained as opposed to DBv1 where they were globally marked.
This means even though it is possible to have values globally created within the main program, it doesn't guarentee 100% success you can pass them into functions unless you mark them with either Global or Local ... sides it is always good habit to get into declaring everything you use.

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!
Rob K
Retired Moderator
23
Years of Service
User Offline
Joined: 10th Sep 2002
Location: Surrey, United Kingdom
Posted: 8th Jun 2003 16:40
It pisses me off that you cannot get pointers to arrays though - if you could then I could write a DLL to show those values in a debug window. I believe the arrays are just laid out in a fairly standard way in memory too.

Do you want Windows menus in your DBP apps? - Get my plugin: http://snow.prohosting.com/~clone99/downloads/tpc_menus_102.zip
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 8th Jun 2003 17:01
I know! I've only got one last part to figure out, and I'll know it all. Ha Ha Haaaaaaaaa *head thrown back in evil laugh*

Rob, drop me an email, and I'll let you have all the info I have on arrays. It'll be tonight though, coz I'm off out now.
FieldDoc
23
Years of Service
User Offline
Joined: 30th May 2003
Location: London, UK
Posted: 8th Jun 2003 22:36
Thanks guys....the GLOBAL command works perfectly! I was only using arrays coz the recommended book said to....perhaps it was refering to DBC?

Life is like a penis:
When it's soft you can't beat it, when it's hard you get screwed.
Bighead
23
Years of Service
User Offline
Joined: 1st Sep 2002
Location:
Posted: 8th Jun 2003 23:39
@Raven:

I had to change the order of the functions included in your last script:



... otherwise I get the following error message:

#100044: Cannot find structure 'Hello:MyValue' in local declaration at line 7.

(still, your script runs and the else piece of code is selected)

Login to post a reply

Server time is: 2026-07-11 11:42:43
Your offset time is: 2026-07-11 11:42:43