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.

Author
Message
Shock
AGK Developer
21
Years of Service
User Offline
Joined: 24th Oct 2002
Location: United Kingdom
Posted: 3rd Nov 2002 15:03
Is there a way to pass out more than one variable from a function? I need to get two return values (one for how many people killed, and another for which object it was that was killed. Or is there a way to turn a local variable into a global variable?

Thanx peeps
www.shockforge.com ShockForge Software
www.havochost.com Unlim bandwdith, unlim space, you.havochost.com, you.s8i.com, visit site for more details.
...::::ShockForge::::...
xtom
21
Years of Service
User Offline
Joined: 26th Aug 2002
Location: Ireland
Posted: 3rd Nov 2002 16:03
Arrays are global. You could create an array with just one space. Don't think you can return more than 1 value.
Shadow Robert
21
Years of Service
User Offline
Joined: 22nd Sep 2002
Location: Hertfordshire, England
Posted: 3rd Nov 2002 16:38
well one way is through an array as suggested...

make it outside of the function preferably at the top of the code then even data entered within the function is still global
so like
function myfunc()
`<< rest of function >>
gGAMESTATS(0) = vTotalDead
gGAMESTATS(1) = vLastDead
endfunction

another is by using a bool switch...
like

function myfunc(bOption)
`<< rest of function >>
if bOption = 1
vExport = vTotalDead
else
vExport = vLastDead
endif
endfunction vExport

or if you expect set values, bitshift the values

function myfunc()
`<< rest of function >>
vExport = vTotalDead << 16 + vLastDead << 8
endfunction vExport

or you could setup strings with known buffer values...

function myfunc()
`<< rest of function >>
sExport$ = str$(vTotalDead) + "_" + str$(vLastDead)
endfunction sExport$

i mean you'll have to remember what you do, and if you make numbers to large or strings too long it'll slow everything - quickest and best option is like an array, especially for great amounts of data ... but for simple things then the others are viable

Anata aru kowagaru no watashi!
Shadow Robert
21
Years of Service
User Offline
Joined: 22nd Sep 2002
Location: Hertfordshire, England
Posted: 3rd Nov 2002 16:45
oh if you bitshift remember DB doesnt have that as standard so use ->


and remember for that to compile a bit value
you'd go

vTotalValue = bitLeft(vValue1,24) + bitLeft(vValue2,16) + bitLeft(vValue3,8)

but to decode its
vValue3 = bitLeft(vTotalValue,8)
vValue2 = bitLeft(vTotalValue,16)
vValue1 = bitLeft(vTotalValue,24)



also for the string you'll want to search for but not include the "_" symbol or whatever you use

Anata aru kowagaru no watashi!
Shock
AGK Developer
21
Years of Service
User Offline
Joined: 24th Oct 2002
Location: United Kingdom
Posted: 3rd Nov 2002 16:57
thanx, i think i'll use an array as thats easiest and quickest

www.shockforge.com ShockForge Software
www.havochost.com Unlim bandwdith, unlim space, you.havochost.com, you.s8i.com, visit site for more details.
...::::ShockForge::::...
TheCyborg
21
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Denmark
Posted: 4th Nov 2002 11:44
Why dont you use 2 functions in the same loop?

TheCyborg Development.
http://TheCyborg.Amok.dk
The Ultimate Source To DarkBASIC Programming.
Shock
AGK Developer
21
Years of Service
User Offline
Joined: 24th Oct 2002
Location: United Kingdom
Posted: 4th Nov 2002 21:52
coz that would mean using my poor fingers to type more than what they need to

www.shockforge.com ShockForge Software
www.havochost.com Unlim bandwdith, unlim space, you.havochost.com, you.s8i.com, visit site for more details.
...::::ShockForge::::...

Login to post a reply

Server time is: 2024-03-28 10:01:43
Your offset time is: 2024-03-28 10:01:43