Well, I have a game I'm making (as I have said when I asked questions before) and I'm in a bit of a jiffy. To have a procedure work, it must have all other procedures it uses BEFORE it, however, I have a command line in my game, and it uses several procedures- but several procedures use it, aswell! So I'm stuck. How can I make a procedure use a procedure that is beneath it in the coding?
IE,
[code]
Procedure Show;
begin
Writeln('Test');
ShowE;
end;
Procedure ShowE;
begin
Writeln('Test2!');
Show;
end;
begin
Show;
ShowE;
end.
[/code]
That gives me errors. How would I get rid of those errors, in the least complex way? Free Pascal gives me an Identifier not Found error.
Thanks for all help!
Comments
: IE,
: [code]
: Procedure Show;
: begin
: Writeln('Test');
: ShowE;
: end;
:
: Procedure ShowE;
: begin
: Writeln('Test2!');
: Show;
: end;
:
: begin
: Show;
: ShowE;
: end.
: [/code]
: That gives me errors. How would I get rid of those errors, in the least complex way? Free Pascal gives me an Identifier not Found error.
: Thanks for all help!
:
Hi !
You can use the [b]forward[/b] directive.
There is an example in chapter 10.5 of the Free Pascal (2.04) language reference :
http://www.freepascal.org/docs.html
: : IE,
: : [code]
: : Procedure Show;
: : begin
: : Writeln('Test');
: : ShowE;
: : end;
: :
: : Procedure ShowE;
: : begin
: : Writeln('Test2!');
: : Show;
: : end;
: :
: : begin
: : Show;
: : ShowE;
: : end.
: : [/code]
: : That gives me errors. How would I get rid of those errors, in the least complex way? Free Pascal gives me an Identifier not Found error.
: : Thanks for all help!
: :
: Hi !
:
: You can use the [b]forward[/b] directive.
: There is an example in chapter 10.5 of the Free Pascal (2.04) language reference :
: http://www.freepascal.org/docs.html
:
Well... I tried it, and i did it exactly like this:
[code]
Procedure OFiveFiveSt; forward; {Main Store}
begin {1}
Writeln('Welcome to the Imps Extravaganza!');
Writeln('What can I do for you today?');
Writeln('The current stock is:');
itema := 'Black Sword of Demise';
costa := 5000;
itemb := 'Black Mana Armor of Demise';
costb := 5000;
itemc := 'Black Helm of Demise';
costc := 2500;
DispStock;
Writeln('Do you wish to buy something?');
Readln(entry);
CommandLine; {line 254}
end; {1} {line 255}
Procedure c_town; forward;
begin {1}
if entry = 'ADDRESS' then
begin {2}
Writeln('Where would you like to go?');
Readln(entry);
if entry = '055 St.' then
begin
OFiveFiveSt;
Readln;
end;
end; {2}
end; {1}
Procedure CommandLine; forward;
begin
{Movement}
UpperCase;
if entry = 'ADDRESS' then
begin
c_town;
end;
{...}{I cut alot of this procedure off, as it is very long...}
end;
[/code]
The errors from this:
[code]
BETA_v0.08.pas(254,1) Error: Identifier not found "CommandLine"
BETA_v0.08.pas(254,12) Error: Illegal Expression
BETA_v0.08.pas(255,4) Error: Syntax Error, "." expected but ; found
BETA_v0.08.pas(255,4) Fatal: Compilation Aborted
[/code]
Now, without the forward; reference, the errors on line 255 do not occur, and it doesn't require the . instead of ; for my procedure... Which I find odd... If I comment out the forward on 1 procedure and put it on another, it requires a period at the end of that particular procedure instead... Without the forward; reference, the errors are:
[code]
BETA_v0.08.pas(254,1) Error: Identifier not found "CommandLine"
BETA_v0.08.pas(254,12) Error: Illegal expression
BETA_v0.08.pas(3069) Fatal: There were 2 errors compiling module, stopping
BETA_v0.08.pas(3069) Fatal: Compilation aborted
[/code]
Any ideas?
: : : IE,
: : : [code]
: : : Procedure Show;
: : : begin
: : : Writeln('Test');
: : : ShowE;
: : : end;
: : :
: : : Procedure ShowE;
: : : begin
: : : Writeln('Test2!');
: : : Show;
: : : end;
: : :
: : : begin
: : : Show;
: : : ShowE;
: : : end.
: : : [/code]
: : : That gives me errors. How would I get rid of those errors, in the least complex way? Free Pascal gives me an Identifier not Found error.
: : : Thanks for all help!
: : :
: : Hi !
: :
: : You can use the [b]forward[/b] directive.
: : There is an example in chapter 10.5 of the Free Pascal (2.04) language reference :
: : http://www.freepascal.org/docs.html
: :
: Well... I tried it, and i did it exactly like this:
: [code]
: Procedure OFiveFiveSt; forward; {Main Store}
: begin {1}
: Writeln('Welcome to the Imps Extravaganza!');
: Writeln('What can I do for you today?');
: Writeln('The current stock is:');
: itema := 'Black Sword of Demise';
: costa := 5000;
: itemb := 'Black Mana Armor of Demise';
: costb := 5000;
: itemc := 'Black Helm of Demise';
: costc := 2500;
: DispStock;
: Writeln('Do you wish to buy something?');
: Readln(entry);
: CommandLine; {line 254}
: end; {1} {line 255}
:
: Procedure c_town; forward;
: begin {1}
: if entry = 'ADDRESS' then
: begin {2}
: Writeln('Where would you like to go?');
: Readln(entry);
: if entry = '055 St.' then
: begin
: OFiveFiveSt;
: Readln;
: end;
: end; {2}
: end; {1}
:
: Procedure CommandLine; forward;
: begin
: {Movement}
: UpperCase;
: if entry = 'ADDRESS' then
: begin
: c_town;
: end;
: {...}{I cut alot of this procedure off, as it is very long...}
: end;
:
: [/code]
:
: The errors from this:
: [code]
: BETA_v0.08.pas(254,1) Error: Identifier not found "CommandLine"
: BETA_v0.08.pas(254,12) Error: Illegal Expression
: BETA_v0.08.pas(255,4) Error: Syntax Error, "." expected but ; found
: BETA_v0.08.pas(255,4) Fatal: Compilation Aborted
: [/code]
:
: Now, without the forward; reference, the errors on line 255 do not occur, and it doesn't require the . instead of ; for my procedure... Which I find odd... If I comment out the forward on 1 procedure and put it on another, it requires a period at the end of that particular procedure instead... Without the forward; reference, the errors are:
: [code]
: BETA_v0.08.pas(254,1) Error: Identifier not found "CommandLine"
: BETA_v0.08.pas(254,12) Error: Illegal expression
: BETA_v0.08.pas(3069) Fatal: There were 2 errors compiling module, stopping
: BETA_v0.08.pas(3069) Fatal: Compilation aborted
: [/code]
:
: Any ideas?
:
The forward directive needs to be used like this:
[code]
procedure Second; forward;
procedure First;
begin
..
Second;
..
end;
procedure Second;
begin
..
First;
..
end;
[/code]
The forward directive takes the place of the body of the procedure. This way you can define the header of the procedure before defining the body.
: : : : Well, I have a game I'm making (as I have said when I asked questions before) and I'm in a bit of a jiffy. To have a procedure work, it must have all other procedures it uses BEFORE it, however, I have a command line in my game, and it uses several procedures- but several procedures use it, aswell! So I'm stuck. How can I make a procedure use a procedure that is beneath it in the coding?
: : : : IE,
: : : : [code]
: : : : Procedure Show;
: : : : begin
: : : : Writeln('Test');
: : : : ShowE;
: : : : end;
: : : :
: : : : Procedure ShowE;
: : : : begin
: : : : Writeln('Test2!');
: : : : Show;
: : : : end;
: : : :
: : : : begin
: : : : Show;
: : : : ShowE;
: : : : end.
: : : : [/code]
: : : : That gives me errors. How would I get rid of those errors, in the least complex way? Free Pascal gives me an Identifier not Found error.
: : : : Thanks for all help!
: : : :
: : : Hi !
: : :
: : : You can use the [b]forward[/b] directive.
: : : There is an example in chapter 10.5 of the Free Pascal (2.04) language reference :
: : : http://www.freepascal.org/docs.html
: : :
: : Well... I tried it, and i did it exactly like this:
: : [code]
: : Procedure OFiveFiveSt; forward; {Main Store}
: : begin {1}
: : Writeln('Welcome to the Imps Extravaganza!');
: : Writeln('What can I do for you today?');
: : Writeln('The current stock is:');
: : itema := 'Black Sword of Demise';
: : costa := 5000;
: : itemb := 'Black Mana Armor of Demise';
: : costb := 5000;
: : itemc := 'Black Helm of Demise';
: : costc := 2500;
: : DispStock;
: : Writeln('Do you wish to buy something?');
: : Readln(entry);
: : CommandLine; {line 254}
: : end; {1} {line 255}
: :
: : Procedure c_town; forward;
: : begin {1}
: : if entry = 'ADDRESS' then
: : begin {2}
: : Writeln('Where would you like to go?');
: : Readln(entry);
: : if entry = '055 St.' then
: : begin
: : OFiveFiveSt;
: : Readln;
: : end;
: : end; {2}
: : end; {1}
: :
: : Procedure CommandLine; forward;
: : begin
: : {Movement}
: : UpperCase;
: : if entry = 'ADDRESS' then
: : begin
: : c_town;
: : end;
: : {...}{I cut alot of this procedure off, as it is very long...}
: : end;
: :
: : [/code]
: :
: : The errors from this:
: : [code]
: : BETA_v0.08.pas(254,1) Error: Identifier not found "CommandLine"
: : BETA_v0.08.pas(254,12) Error: Illegal Expression
: : BETA_v0.08.pas(255,4) Error: Syntax Error, "." expected but ; found
: : BETA_v0.08.pas(255,4) Fatal: Compilation Aborted
: : [/code]
: :
: : Now, without the forward; reference, the errors on line 255 do not occur, and it doesn't require the . instead of ; for my procedure... Which I find odd... If I comment out the forward on 1 procedure and put it on another, it requires a period at the end of that particular procedure instead... Without the forward; reference, the errors are:
: : [code]
: : BETA_v0.08.pas(254,1) Error: Identifier not found "CommandLine"
: : BETA_v0.08.pas(254,12) Error: Illegal expression
: : BETA_v0.08.pas(3069) Fatal: There were 2 errors compiling module, stopping
: : BETA_v0.08.pas(3069) Fatal: Compilation aborted
: : [/code]
: :
: : Any ideas?
: :
: The forward directive needs to be used like this:
: [code]
: procedure Second; forward;
:
: procedure First;
: begin
: ..
: Second;
: ..
: end;
:
: procedure Second;
: begin
: ..
: First;
: ..
: end;
: [/code]
: The forward directive takes the place of the body of the procedure. This way you can define the header of the procedure before defining the body.
:
So basically, for all of my procedures, right underneath my variables, i put a long list of:
procedure first; forward;
procedure second; forward;
procedure third; forward;
and it will work?
EDIT:
Got it! Thanks, both of ya