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 Discussion / Question about FUNCTION and Arrays

Author
Message
oDCo
20
Years of Service
User Offline
Joined: 11th May 2005
Location:
Posted: 26th Jun 2005 00:12 Edited at: 26th Jun 2005 00:53
Hi all,

I'm a little confused by how FUNCTION works. From reading the DB manual, I understand that any variables inside the function are local variables and don't effect the global variables. It also says that the same applies to arrays . . . but I have a FUNCTION that populates an array that is outside of the function.



Does this not contradict what the manual says?

David
NanoBrain
20
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Portland, OR
Posted: 26th Jun 2005 01:24
oDCo,

You must not be reading the manual correctly, or it is a misprint. However, arrays are global, and can be effected from within any area of your code. Now, local variables within a function will not change any non-array variable which is anywhere else inside of the program. Any normal variable cannont be affected by the variables inside of a function, unless you asign the return value of the function, to the variable. Even if the variables have the same name.

For example:




+NanoBrain+
empty
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: 3 boats down from the candy
Posted: 26th Jun 2005 04:07
Quote: "Does this not contradict what the manual says?"

Actually your example doesn't contradict the manual as arrays are global when declared outside functions. However there are no global variables in DarkBasic.
If you DIM an array inside a function it is local to the function. If declared outside of a function it is always global.




Play Nice! Play Basic! Version 1.073
oDCo
20
Years of Service
User Offline
Joined: 11th May 2005
Location:
Posted: 27th Jun 2005 03:19
Ahhhh, that makes sense . . . along with what the manual says.

Cheers guys

David

Login to post a reply

Server time is: 2025-05-22 19:13:48
Your offset time is: 2025-05-22 19:13:48