Xtensity
2010-02-04 07:26:33
I've always had this problem when making scripts. I have a lot of fail safes in my functions but a lot of them wont work for the fact that many of the fail safes call from a function which is below it in the script. If I moved that lower function up above the current function then it wouldn't find the function I moved it above.
How do I get around this? It seems it happens when compiling, when compiling, it runs through the script, if it gets to a called function within another functions that hasn't been declared yet, but would have been declared right after the current function, it will say function not found.
Scar scripts are the only kind of scripts where I have experienced this issue, and it's a huge pain to have to copy an entire function into another function just because it can't find the function when compiling.
Any tips?
You are looking for forward.
function Fwded : string; forward;
procedure Call;
begin
writeln('watwatin' + Fwded + 'butt');
end;
function Fwded : string;
begin
result := 'da';
end;
begin
Call;
end.
Xtensity
2010-02-04 13:13:51
From: Sex
You are looking for forward.
function Fwded : string; forward;
procedure Call;
begin
writeln('watwatin' + Fwded + 'butt');
end;
function Fwded : string;
begin
result := 'da';
end;
begin
Call;
end.
Eh, can you explain how I would use that, or how it works?
Dynamite
2010-02-04 13:15:57
Basically, just do:
Function FunctionName; Forward;
Like at the top of the script.
That will allow you to call it.
Xtensity
2010-02-04 14:16:32
From: The Man
Basically, just do:
Function FunctionName; Forward;
Like at the top of the script.
That will allow you to call it.
What if I need the function to return a boolean? Just a hypothetical question.
All my functions are simple execution functions that dont need to return anything… So if I put forward there all functions should be able to call all other functions regardless of the order? How can I make it have forward and return a boolean? I'm not at home atm so I can't test this. I'll be home in a bit though
Dynamite
2010-02-04 14:18:09
function FunctionName : boolean; forward;
Bionicle
2010-02-04 14:19:05
I don't usually use forwarded functions but:
Function FunctionName: Boolean; Forward;
I'm pretty sure that's right.
E: :ninja:'d
marpis
2010-02-04 14:36:54
If the function has parameters, the parameter names must be identical too.
function DoThis(Uber: boolean): boolean; forward;
...
function DoThis(Super: boolean): boolean; // <-- WRONG
begin
end;
function DoThis(Uber: boolean): boolean; // <-- RIGHT!
begin
end;
Xtensity
2010-02-04 14:58:55
From: marpis
If the function has parameters, the parameter names must be identical too.
function DoThis(Uber: boolean): boolean; forward;
...
function DoThis(Super: boolean): boolean; // <-- WRONG
begin
end;
function DoThis(Uber: boolean): boolean; // <-- RIGHT!
begin
end;
er those 2 wrong and right ones look exactly the same, where's the difference?
Dynamite
2010-02-04 14:59:40
The "Super" and "Uber" in the parenthesis
Xtensity
2010-02-04 15:04:16
From: The Man
The "Super" and "Uber" in the parenthesis
program New;
var
X,Y,Z:Integer;
function Add:Boolean; forward;
function Add:Boolean;
begin
Subtract;
end;
function Subtract:Boolean; forward;
function Subtract:Boolean;
begin
end;
begin
end.
I did this…still can't find the function subtract when called from the Add function. I Know it doesn't do anything here, but it cant call it..
Xtensity
2010-02-04 15:07:00
From: The Man
Read what this says ^
Put the forward at the top of the script
;)
Alright I got that, but do I have to do this for each function?
Dynamite
2010-02-04 15:08:18
program New;
var
X,Y,Z:Integer;
function Subtract :Boolean; forward;
function Add:Boolean;
begin
Subtract;
end;
function Subtract:Boolean;
begin
end;
begin
end.
Xtensity
2010-02-04 15:11:55
Alright I figured it out, thanks for helping guys :).
senrath
2010-02-04 15:56:08
Also, unless both functions call each other (or it leads to an unreadable mess), it's better not to use Forward.
Put the forward above where you want to call it. You only need it if the function you are calling is not already interpreted by SCAR.
I try to stay away from forwards though..you can find an alternative usually.