View Full Version : Why does this not work?
IlovePascal
13-02-2007, 12:34 AM
Hey, just a little question:
why does this not work?
if x<>xto then x += velocity*( (xto-x)/AbsR(xto-x));
with
Function AbsR(x:real):real;
begin
if x<0 then Result := -x;
end;
Cheers :wink:
PS: btw, is tht how u return a value for a function?
Robert Kosek
13-02-2007, 01:17 AM
There is no += operator in pascal, that's why. ;)
IlovePascal
13-02-2007, 01:23 AM
There is no += operator in pascal, that's why.
no,no, I always use that. Well, maybe in strict pascal there isn't, but the compiler accepts it...
AthenaOfDelphi
13-02-2007, 03:08 AM
Because the return value of the AbsR function could be undefined.
You are setting 'Result' if x is less than zero, but what about if x is greater than or equal to 0?
Edit:- Just reworded this as the parser took out the less than and greater than symbols
cragwolf
13-02-2007, 04:14 AM
So what if x is not less than zero, what do you think your function will return then?
IlovePascal
13-02-2007, 05:56 AM
:oops: duh!
well I'm really sorry about this! It's funny how sometimes we just don't see the obvious!
Maybe for the fact I haven't slept more than 10h in the last 60h or so...
Well good night, n this thread can be deleted!!! lol
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.