Function Call
Blitz3D Forums/Blitz3D Beginners Area/Function Call
| ||
I feel like a complete noob for asking this but this function doesn't seem to be getting called. I tried modifying one of the demos, the car driving over the terrain, and I attempted to make functions to clean up the code. The problem is I can't verify that the functions are even being called. The debugger steps right over them. Please have a look. zX#=WheelsGetRollVectorX# Function WheelsGetRollVectorX#() vX#=(EntityX( wheels[2],True )+EntityX( wheels[4],True ))/2 vX#=vX#-(EntityX( wheels[1],True )+EntityX( wheels[3],True ))/2 Return vX# End Function For the life of me I don't know why it keeps returning zero. Wheels is a global array of 4 sphere entities. Please help. |
| ||
Hi, the problem is Blitz thinks you want WheelsGetRollVector# to be a variable because you omitted the () Is that # legal in a function name? I know EntityX# etc. uses it, anyway I would change it to zX#=WheelsGetRollVectorX() Function WheelsGetRollVectorX() vX#=(EntityX( wheels[2],True )+EntityX( wheels[4],True ))/2 vX#=vX#-(EntityX( wheels[1],True )+EntityX( wheels[3],True ))/2 Return vX# End Function it one of Blitz's few annoying things -.- |
| ||
That was it! Your are right about that being annoying! I wish BlitZ made you declare your variables first before you could use them. It makes these kinds of bugs a thing of the past. Thanks! |
| ||
Actually, I think Blitz is declaring 'WheelsGetRollVectorX#' as a function, since I believe you'd get an error message if you had both a function and a variable with the same name. The problem is that Blitz allows you to use function names without the parenthesis when calling a function, but it only allows a result to be returned if the parenthesis are present in the calling function name. So you need to add the parenthesis to the calling function name, as Shambler said. As far as the '#' being legal in a function name, it needs to be there if you want the function to return a floating point result, just as '$' would need to be there to return a string, or a custom type extension would need to be there to return a type pointer of the specified custom type. By default integers are returned, so there's no need to specify a '%' for them. |
| ||
@Axeman thanks for that info I was not aware of requiring # $ etc. at all. I've never written a function that returns anything except true/false =) |