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 / Distance formula and functions

Author
Message
Your mother
20
Years of Service
User Offline
Joined: 21st May 2005
Location:
Posted: 23rd May 2005 05:49
i am trying to learn how to properly use functions, so i wrote this program,


and this is the dist.dba function Distance,


it all works fine except that when i tell it to print Distance#, it always prints a 0. can someone please help me?
Link102
20
Years of Service
User Offline
Joined: 1st Dec 2004
Location: On your head, weeeeee!
Posted: 23rd May 2005 07:15 Edited at: 23rd May 2005 07:15
Try putting the function at the end of your main code, to check if it works then.

When useing functions, you can't use variable that are in the main code, exept for dims, I think object position has the same sort of problem.

please reply
NanoBrain
20
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Portland, OR
Posted: 23rd May 2005 07:29
Your mother,

The problem is that you are not returning the value Distance# from the function. To do this, call the function by adding it to a variable.

Distance# = Distance(2,1)

You have created the function, itself, correctly. As in, endfunction Distance#.


+NanoBrain+
Your mother
20
Years of Service
User Offline
Joined: 21st May 2005
Location:
Posted: 23rd May 2005 08:14
oh, i thought it would do that automatically, thank you so much, for all your help!

Login to post a reply

Server time is: 2025-05-23 02:05:17
Your offset time is: 2025-05-23 02:05:17