Alek000
2010-02-25 04:32:11
How do you know when to use a procedure or when to use a function. I get that the a function returns a variable and a procedure does not, but how can you tell when you need something to return a variable or not.
inb4 search
Runescape Pro
2010-02-25 04:45:54
One way to use a function is to make the function "check" something. Like, if the inventory is full, then its true. Procedures are used to put stuff in order like, if invy full = true then runtobank. and runtobank would be a procedure for walking. Idk if thats hard to understand. i tried to explain as best as i could. ;)
Edit: Not all functions are booleans though.
Alek000
2010-02-25 04:48:55
From: Runescape Pro
One way to use a function is to make the function "check" something. Like, if the inventory is full, then its true. Procedures are used to put stuff in order like, if invy full = true then runtobank. and runtobank would be a procedure for walking. Idk if thats hard to understand. i tried to explain as best as i could. ;)
Edit: Not all functions are booleans though.
Ok so, a function is basically used for stuff like, finding and cutting a tree, and a procedure would be like walking? Is that right?
radiclerobby
2010-02-25 07:51:13
ill put it like this a function is like a question and a procedure is doing it. example
procedure cutyew;
begin
mouse(x,y,3,3,true);
end;
function findyew:boolean;
begin
result:=findcolortolerance(x,y,yew,0,0,500,500,25) and isuptext('ew');
end;
begin
if(findyew)then
cutyew;
end;
of course thats just a example
Gu3st...
2010-02-25 08:09:33
I tend to use functions for everything, and then change the functions that can be used as procedures to procedures when I'm done writing the script. :)
Boreas
2010-02-25 08:28:13
I like to use functions a lot. If it doesn't necessarily have a number or coordinate etc to pass along, just make it a boolean function that returns true if it was completed successfully. Whether you actually do anything based on that result is up to you later. If you don't do anything and you are sure you won't in later revisions, you can just leave it as it won't do any harm, or you can remove the result part and change to procedure as Zyt3x said.