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 / Can a function return more than one variable ?

Author
Message
DemonHill
18
Years of Service
User Offline
Joined: 20th Mar 2008
Location:
Posted: 11th Aug 2010 13:46
I am trying to create a function that returns two variable..

e.g.
Function OutLapCalculation(DriverVar,OnTrackVar,OutLapVar)
If m=qual_1st_out_time(DriverVar) and q1=qual_1st_out_lap(DriverVar)
OnTrackVar=1utLapVar=1
Endif
EndFunction OnTrackVar,OutLapVar


Usage:

`OutLapCalculation(0,Driver1_ontrack,Driver1_Outlap)
HowDo
23
Years of Service
User Offline
Joined: 28th Nov 2002
Location: United Kingdom
Posted: 11th Aug 2010 13:54
only way it could be done, is to make the result a string and then some more code to get at it.

Dark Physics makes any hot drink go cold.
Van B
Moderator
23
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 11th Aug 2010 14:08
I tend to use globals when I need more from a function, like with a collision function I might have the collision point stored in globals, say RET_X and RET_Y, then return a 1 if there is a collision, so if there is a collision, RET_X and Y hold the extra info.

Health, Ammo, and bacon and eggs!
maicl
19
Years of Service
User Offline
Joined: 19th Jun 2007
Location:
Posted: 11th Aug 2010 15:11
Use Global variables instead of locals .
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 11th Aug 2010 15:26
There's little difference between returning multiple values and a type. For each I'd use the same method of a type specifically for the function and a single global variable declared for it:


Sepnon
16
Years of Service
User Offline
Joined: 7th Feb 2010
Location: Brazil
Posted: 12th Aug 2010 04:30
or use a memblock

Login to post a reply

Server time is: 2026-07-25 07:01:54
Your offset time is: 2026-07-25 07:01:54