View Full Version : What's wrong with this procedure?
KeepBotting
07-03-2012, 06:52 PM
Here's my procedure.
procedure SailCheck;
begin
if FindBlackChatMessage('coins and board the ship') then
WriteLn('successfully sailed');
if not FindBlackChatMessage ('coins and board the ship') then
WriteLn('something went wrong');
SailBoat; { repeats the previous procedure }
end;
However, when I run it, it seems to return both true and false for the FindBlackChatMessage. In any case, it runs both messages.
Wat do?
Runaway
07-03-2012, 06:55 PM
Well, you've got a space between the second FindBlackChatMessage and ('coins and board the ship'). Also, you mine as well use an else statement!
procedure SailCheck;
begin
if FindBlackChatMessage('coins and board the ship') then
WriteLn('successfully sailed')
else
begin
WriteLn('something went wrong');
SailBoat;
end;
end;
KeepBotting
07-03-2012, 06:56 PM
Well, you've got a space between the second FindBlackChatMessage and ('coins and board the ship'). Also, you mine as well use an else statement!
procedure SailCheck;
begin
if FindBlackChatMessage('coins and board the ship') then
WriteLn('successfully sailed')
else
begin
WriteLn('something went wrong');
SailBoat;
end;
Ooh, thanks! :D I had tried to use an else statement before, but I neglected to use another begin and end with it.
Runaway
07-03-2012, 07:00 PM
No problem :)
You need a begin/end if you're using more than one procedure/statement after the if..then or the else. And if you use more than one procedure/statement between the if..then and the else, you use begin..end else instead of begin..end; Example (other than what I posted above):
procedure SailCheck;
begin
if FindBlackChatMessage('coins and board the ship') then
begin
WriteLn('successfully sailed');
WaitSailing;
end else
WriteLn('something went wrong');
end;
PS: I forgot the second end; in the first post!
KeepBotting
07-03-2012, 07:09 PM
No problem :)
You need a begin/end if you're using more than one procedure/statement after the if..then or the else. And if you use more than one procedure/statement between the if..then and the else, you use begin..end else instead of begin..end; Example (other than what I posted above):
procedure SailCheck;
begin
if FindBlackChatMessage('coins and board the ship') then
begin
WriteLn('successfully sailed');
WaitSailing;
end else
WriteLn('something went wrong');
end;
PS: I forgot the second end; in the first post!Interesting. Because when I use something like if FindObj(blah, blah, blah, blah) then and there is no begin/end or an else, but it still works.
Recursive
07-03-2012, 07:16 PM
Depends on what you are returning, sometimes it might return both results but you may have not been checking for both so you think it returned just one.
Runaway
07-03-2012, 07:18 PM
Interesting. Because when I use something like if FindObj(blah, blah, blah, blah) then and there is no begin/end or an else, but it still works.
This is because an if..then will apply to the line after it. For example:
if This then
That;
Writeln('Hopefully we did that!');
^ it will write "Hopefully we did that!" no matter what; but it will only do That; if This is true.
KeepBotting
07-03-2012, 07:57 PM
This is because an if..then will apply to the line after it. For example:
if This then
That;
Writeln('Hopefully we did that!');
^ it will write "Hopefully we did that!" no matter what; but it will only do That; if This is true.That's interesting...when I first started programming, I used the BASIC language (DOS ftw!?!?!?) and it didn't follow that rule.
Runaway
07-03-2012, 08:09 PM
That's interesting...when I first started programming, I used the BASIC language (DOS ftw!?!?!?) and it didn't follow that rule.
Well I'm not sure about other languages, but pascal follows the typical "semi-colon" rules. a simple if..then statement is followed by a single semi-colon, so it counts as a single line; no matter the spacing between it. What I posted above is the same as:
if This then That;
Writeln('Hopefully we did that!');
So if you want to involve multiple procedures/statements within that if..then, you must use a begin/end since:
if This then That; Writeln('Doing that!');
counts as two lines. Using the begin/end is what allows you to link multiple procedures to the single if..then:
if This then begin That; Writeln('Doing that!'); end;
:)
Tniffoc
07-03-2012, 08:15 PM
The easiest way to think about it is to think of begins and ends as a way to box things together. An if statement will only do the thing on the next line EVER. The begins and ends will just package a bunch of lines together so that the if statement sees it as one line. Thats how I think about it anyways, but maybe I'm just screwed up.
Powered by vBulletin® Version 4.2.1 Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.