SRL Archive - OSR Help

Functions and Procedures


Ducksarecool

2012-05-07 13:57:55

hey, i understand a Function returns something if i am right it will return a Integer, Boolean or string(think theres one more but cant remember it) and a Function is just a list of commands. But im just not getting to grip what a function would return as in a tutorial i have seen it could return how many trips of something it has done but where does it return this to? im just not understanding it fully.

Word

2012-05-07 15:04:29

A procedure just executes or DOES something, while a function actually returns a value.

By return, we mean it returns a variable which can usually be used on later in the function:

function IntToStr(i: LongInt): String;

In that example, the function would return a string (which you could call anything, not "String") which we would use later, maybe like so:

Writeln('Number of logs:' + String);

Hope I helped.

Ducksarecool

2012-05-07 15:28:30

From: Word
A procedure just executes or DOES something, while a function actually returns a value.

By return, we mean it returns a variable which can usually be used on later in the function:

function IntToStr(i: LongInt): String;

In that example, the function would return a string (which you could call anything, not "String") which we would use later, maybe like so:

Writeln('Number of logs:' + String);

Hope I helped.


ok thanks, so anything with variables is a function? or a function is when the script finds say a color then returns the coordinates of that color?

Word

2012-05-07 15:35:43

From: Ducksarecool
ok thanks, so anything with variables is a function? or a function is when the script finds say a color then returns the coordinates of that color?


No, for the first question. You can declare variables at the beginning of the script, yet it's not a function.

A function returns a variable type, while a procedure merely executes - follows certain steps - without returning anything.

They are very similar, but one just returns a value, while the other doesn't. Like you said in the second part, yes, that would be a function. A procedure in this case could be to click the colour (where nothing would therefore be returned; just an action would be performed).

Ducksarecool

2012-05-07 15:38:26

From: Word
No, for the first question. You can declare variables at the beginning of the script, yet it's not a function.

A function returns a variable type, while a procedure merely executes - follows certain steps - without returning anything.

They are very similar, but one just returns a value, while the other doesn't. Like you said in the second part, yes, that would be a function.


ok got it thanks man :)

Word

2012-05-07 15:41:51

From: Ducksarecool
ok got it thanks man :)


No problem. They are quite similar, so maybe I confused you a little (it is pretty hard to explain).

Check out: http://villavu.com/forum/showthread.php?p=1006864#post1006864 for an explanation with examples, will be much easier to understand.

Also, no problem. :)