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 / functions: need more than one return value

Author
Message
Zotoaster
20
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 5th Jul 2005 10:30
im trying to make an AI plugin and i need to return more that one value, how would i do this, would i make lots of functions, each one returning separate values, and each function leading to the next one or what?

Your signature has been erased by a mod because it's larger than 600x120...
hyrichter
21
Years of Service
User Offline
Joined: 15th Feb 2004
Location: Arizona
Posted: 5th Jul 2005 12:40
DBC functions can only return one value. So, you'd be best to use different functions to return different values. More info on why you need more than one return value would be helpful.

Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 5th Jul 2005 13:41 Edited at: 5th Jul 2005 13:51
As long as you dimensionalize outside the function you can change anything and have as many separate values come out of functions as you want. Only non-dimed integers and strings don't keep the change in the functions ( b1 and a$ ).

Underworld 1020
21
Years of Service
User Offline
Joined: 2nd Mar 2004
Location: NY, USA
Posted: 11th Jul 2005 10:29
Or you could use file commands to store data while your inside the function and read the data back in at anytime you want using file commands. Simply because the data is stored into a file on your computer just like anything else, I use file commands in every program I make. If you need help with them or something then just look here:

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

TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 23rd Jul 2005 10:50
In the past, I've cheated by returning all the required info from the function in a string, though it depends on what data you want to return.

Numeric data can be converted to ASCII characters and strung together in a string and returned from the function.

Boolean (yes/no) data can be strings of "0"'s and "1"'s.

I agree with Grog though, that the easiest way is to use Arrays which you can access both inside and outside of functions.

TDK_Man
blanky
20
Years of Service
User Offline
Joined: 3rd Aug 2004
Location: ./
Posted: 23rd Jul 2005 21:32
Arrays, arrays.

Dim MyGlobalVariable(0)
MyGlobalVariable(0)=WHATEVAH

Underworld 1020, aside from the fact you're probably going to send your hard drive into an early grave, files are SLOW. Much slower than RAM, in any case.

Meh. TDK's string-thing works too. ^_^

Syntax Error - Learn to type, you fool!
Zotoaster
20
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 23rd Jul 2005 21:48
can you still use the arrays if you include a function instead of having it as part of your source code?

Your signature has been erased by a mod because it's larger than 600x120...
oDCo
20
Years of Service
User Offline
Joined: 11th May 2005
Location:
Posted: 24th Jul 2005 01:46
Yep, as long as you declare the Array in you main source code.
BearCDPOLD
21
Years of Service
User Offline
Joined: 16th Oct 2003
Location: AZ,USA
Posted: 24th Jul 2005 09:01 Edited at: 24th Jul 2005 09:01
Maybe not quite memory efficient (your program will run the same logic through multiple times to get all values), but it works.

function GetAnInsult$(pick)
if pick=1 then insult$="your mom"
if pick=2 then insult$="your dad"
if pick=3 then insult$="your face"
if pick=4 then insult$="phatty"
endfunction insult$

I dunno about you guys, but I'm really sick of these workarounds-I'm gonna nab DarkSDK or something before my brain explodes.


I'm going to eat you!

Login to post a reply

Server time is: 2025-05-22 13:54:47
Your offset time is: 2025-05-22 13:54:47