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 / Function problem - Have to return a value...

Author
Message
Hayer
20
Years of Service
User Offline
Joined: 4th Nov 2005
Location: Norway
Posted: 18th Aug 2007 11:39
Hi!
This is my round function


This is how i try to call it


But the compiler says that the function MUST return a value if used in an expression...

any help?

paul5147
20
Years of Service
User Offline
Joined: 11th Jan 2006
Location: Hot & Sunny
Posted: 18th Aug 2007 11:58
add the variable you want to return to the "endfuction" command
eg. "endfunction x" will return the value "x"
Mr Kohlenstoff
20
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Germany
Posted: 18th Aug 2007 13:01
I'm not sure what your function is supposed to do.. but when you call it the way you do ("something = Round(test)") then the function also has to return a value of course... otherwise this function call wouldn't have any sense.
I edited your function, how it might work maybe, just try it. I think the local x-variable should also be a float? And then it's returned... but however.



Visit the DBPro - Speed up your game-Thread. http://forum.thegamecreators.com/?m=forum_view&t=88661&b=1
jason p sage
19
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 20th Aug 2007 20:43
NA170425
User Deleted
Posted: 20th Aug 2007 22:23
You guys are making it too hard.



Quote: "Quote: "he probably thought you meant you thought"
NOO!! MY BRAIN IT EXPL"
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 21st Aug 2007 00:01
Maybe - I haven't tested Mr K's function, but I know yours isn't correct. Put a negative number into your function and it won't work correctly (minus 2 becomes minus 1).

You need to do this:


Note, there's an implicit INT() in there - it's not necessary to call the function itself.

Utility plugins collection and
http://www.matrix1.demon.co.uk for older plug-ins and example code
Ric
21
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 21st Aug 2007 00:42
Shouldn't that be local 'V' as integer - I'm assuming it's a typo, unless it's doing something very mysterious.

Zotoaster
21
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 21st Aug 2007 00:52
OR!

I = F - 0.5
and
I = F + 0.5

"It's like floating a boat on a liquid that I don't know, but I'm quite happy to drink it if I'm thirsty enough" - Me being a good programmer but sucking at computers
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 21st Aug 2007 00:56 Edited at: 21st Aug 2007 00:58
Quote: "Shouldn't that be local 'V' as integer "


Why? The default type IS integer - and variables in functions are also local by default. Problems only arise if V is declared as an unsuitable global somewhere else.

Perhaps the question should be: what is the "local I as integer" for? [Edit - I see that's what you meant. Oops! ]
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 21st Aug 2007 01:37
Yeah, it's a typo - I meant to change the V's to I's. There's no real reason for declaring the variable in there either. It's a 'just in case' that I try to follow to avoid trashing my globals, but seeing as I always name my globals appropriately ... It's a good habit anyway.

Utility plugins collection and
http://www.matrix1.demon.co.uk for older plug-ins and example code
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 21st Aug 2007 02:02
Quote: "It's a good habit anyway."


Very true.
sp3ng
20
Years of Service
User Offline
Joined: 15th Jan 2006
Location:
Posted: 25th Aug 2007 03:26
@hayer: also is there a reason why your enter the variable RoundX into the function but do not use it anywhere (only using x, and assigning a value in function to that!)


Add Me
Aralox
19
Years of Service
User Offline
Joined: 16th Jan 2007
Location: Melbourne
Posted: 25th Aug 2007 05:20
Love your sig, code dragon *wink*

sp3ng
20
Years of Service
User Offline
Joined: 15th Jan 2006
Location:
Posted: 25th Aug 2007 13:55
i know, its funny that he kept it from that other thread


Add Me

Login to post a reply

Server time is: 2026-06-12 05:03:38
Your offset time is: 2026-06-12 05:03:38