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 / Function Variables

Author
Message
monkey for sale
17
Years of Service
User Offline
Joined: 8th Jun 2007
Location: Inside you head
Posted: 14th Apr 2008 04:44
Im am working on some code and a little problem arose, after getting annoyed and my teacher not being able to solve the problem i finally found in the manual that functions create their very own variables and cannot affect global ones. So if I want a function to return 7 variables to an array, is it impossible?

Why are you reading this?
LBFN
18
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 14th Apr 2008 05:56
No, it won't return seven variables from a function. However, you can simply change the value of the arrays inside a function. This effectively works around the fact that you cannot use global variables with DBC. An example:


Hope this helps,

LBFN
monkey for sale
17
Years of Service
User Offline
Joined: 8th Jun 2007
Location: Inside you head
Posted: 14th Apr 2008 06:13
I thought that you couldnt even edit array values, since that is how it works with normal variables, thanks

Why are you reading this?
monkey for sale
17
Years of Service
User Offline
Joined: 8th Jun 2007
Location: Inside you head
Posted: 14th Apr 2008 06:24
hmm, for some reason i get the error, Array Accessed out of bounds

i declare the array as
dim objects(100,7)=0



Why are you reading this?
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 14th Apr 2008 06:49
Quote: "dim objects(100,7)=0"


You can't assign values to an array during declaration.

dim objects(100,7)
objects(100,7)=0


...though in DBC, numeric arrays automatically contain zero when they are declared, so implicitly stating it is not necessary.

Tutorial 1 covers arrays and number 6 covers functions here:

http://forum.thegamecreators.com/?m=forum_view&t=99497&b=10

Quote: "for some reason i get the error, Array Accessed out of bounds"


Check the counting values of objectN used in the For..Next loop. If you don't have a For..Next loop then check whatever value objectN is at this point in your program.

TDK_Man

monkey for sale
17
Years of Service
User Offline
Joined: 8th Jun 2007
Location: Inside you head
Posted: 15th Apr 2008 05:24
it isnt a for next loop, its part of the function,objectN is the object number.

But i have it working now. Thanks

Why are you reading this?

Login to post a reply

Server time is: 2025-06-07 13:04:52
Your offset time is: 2025-06-07 13:04:52