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.

Newcomers DBPro Corner / function help

Author
Message
cheese pwner
15
Years of Service
User Offline
Joined: 26th Oct 2008
Location:
Posted: 28th Sep 2009 23:53
i was wondering how you call a function.

i have made a function like so:



this makes the function but how do you make the function show up
Jimpo
19
Years of Service
User Offline
Joined: 9th Apr 2005
Location:
Posted: 29th Sep 2009 00:23 Edited at: 29th Sep 2009 00:24
First, your function name should have () at the end.
Second, the value after 'endfunction' is the return value. In your case, your function will return the value of the variable labeled 'money'.
Third, to call your function just write the function name in your code.

Example:


Masqutti
14
Years of Service
User Offline
Joined: 8th Jan 2010
Location: insanity
Posted: 19th Jan 2010 09:49
Hi!

Is there a way to use function to return more than 1 variable ? I'm thinking of returning the coordinates in 3D space, so.. Is it possible with just 1 function or do i have to use array or such to return the values ?

something like
function new_pos(objectn as integer)
x1 = rnd(200)
y1 = rnd(200)
z1 = rnd(200)
endfunction x1,y1,z1

(??)

hmmmh.. that didn't compile
LBFN
17
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 19th Jan 2010 15:29 Edited at: 19th Jan 2010 20:12
Quote: "Is there a way to use function to return more than 1 variable ?"

No, you can only return one variable from a function. You would have to either make x1, y1 and z1 global variables or make an array to hold the values.

You could also use a subroutine (procedure) instead of using a function.


Click my sig to download TGC Heroes v0.94.

Neuro Fuzzy
17
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 22nd Jan 2010 04:32 Edited at: 22nd Jan 2010 04:33
yeah, you would have to do something like this:



Masqutti
14
Years of Service
User Offline
Joined: 8th Jan 2010
Location: insanity
Posted: 22nd Jan 2010 09:51
Ok thanks

hmmmh.. that didn't compile
LBFN
17
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 22nd Jan 2010 14:58 Edited at: 22nd Jan 2010 15:00
It could also be done like this:


or if you wanted to use TYPE variables, you could do it this way:



Click my sig to download TGC Heroes v0.94.

Login to post a reply

Server time is: 2024-09-28 14:19:16
Your offset time is: 2024-09-28 14:19:16