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.

Author
Message
Philip 1337
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: United Kingdom
Posted: 9th Dec 2002 18:27
How do I use functions
The Darthster
21
Years of Service
User Offline
Joined: 25th Sep 2002
Location: United Kingdom
Posted: 9th Dec 2002 18:47
Functions are really useful. You can feed values into them and either get them to return values, or affect variables or objects.

They are constructed like this:
Function {function name(parameters, more parameters)}
maths expressions, or just any general code relating to the parameters
EndFunction {return value}

Start with a really simple function that returns a value. This will add two numbers together.



This will take x and y, add them and put the result in z. z is returned from the function. To use this in a program, do this:



Now this is hardly the most useful function, but you can make your own functions for really complicated maths expressions you may have to do over and over, and functions that use several parameters.

You don't need to return a value, you can make functions which will affect objects or sprites in the game. For example:



This moves an object based on it's current position, and so it doesn't need to return a value.

These aren't the most useful examples, but I hope they help you understand a bit.
Kangaroo2
21
Years of Service
User Offline
Joined: 26th Sep 2002
Location: United Kingdom
Posted: 10th Dec 2002 16:31
Whilst I agree function are useful, in most cases the same effect can be used with gosub/return loops, which some people (I included) prefer, and which reportedly work slightly faster in DBPro. Its a matter of taste though and TheDarthster just explained them very well

* If the apocalypse comes, email me *

Login to post a reply

Server time is: 2024-05-07 15:15:20
Your offset time is: 2024-05-07 15:15:20