View Full Version : If...Then syntax for cases?
Jason2gs
03-23-2007, 02:37 AM
I'm trying out how to work out using cases with for..to..do setups, but I'm not sure what the syntax is for using cases with if...then statements. I'll post the script:
program New;
var
x : Integer;
begin
for x:=1 to 10 do
begin
Wait(1000);
case Random(2) of
0: Writeln('Hello!');
1: Writeln('Hi!');
end;
if(Writeln('Hello!'))then
break;
end;
end.
I want it to Break; if it Writelns "Hello!". This doesn't work, it gives me a mismatch error.
I tried assigning the two Writelns to variables, but that didn't work either.
Please help, :D
Mike.
WhoCares357
03-23-2007, 02:41 AM
WriteLn does not return a boolean. It will never be acceptable in an if then statement. I suggest making a string that equals something in a random case. Then say WriteLn(Whatever). If Whatever = Hello then //rest of script.
program New;
var
x : Integer;
Saying: String;
begin
for x:=1 to 10 do
begin
Wait(1000);
case Random(2) of
0: Saying:= 'Hello!';
1: Saying:= 'Hi!';
end;
Writeln(Saying)
if(Saying = 'Hello!')then
break;
end;
end.
Jason2gs
03-23-2007, 02:50 AM
Ah, that would make sense ;)
Is it possible for me to make a function to basically convert the Writeln procedure to return a boolean?
WhoCares357
03-23-2007, 02:52 AM
Yup. Very simple. Want me to make you one?
Jason2gs
03-23-2007, 02:55 AM
Hmm... I'll try it out, and post here if when I'm done/need any help with it. K?
I've never really made a function before, and I'd like to try it out ;)
WhoCares357
03-23-2007, 02:56 AM
Alright, if you need help, pm me msn andrey0ll@yahoo.com or I'll just refresh this every five minutes or so.
Jason2gs
03-23-2007, 03:08 AM
Ok, I've got it kinda down, but doesn't do what exactly what it's supposed to do. It always returns True. I'm not sure how to make it randomnize.
program New;
function JWriteln:Boolean;
begin
Writeln('Hello!');
Result:= True;
end;
begin
if(JWriteln = True)then
Writeln('It was true!');
if(JWriteln = False)then
Writeln('It was false!');
end.
Gonna start the Goblin Sche. up and go to bed. Tis 20 after 11 already :(
Bye, thanks for your help :p
WhoCares357
03-23-2007, 03:28 AM
program New;
function JWriteln(Say, Compare: String):Boolean;
begin
Writeln(Say);
if Say = Compare then
begin
Result:= True;
end else
begin
Result:= False;
end;
end;
begin
if(JWriteln('Hello', 'Hello!') = True)then
Writeln('It was true!');
if(JWriteln('Hello', 'Hello!') = False)then
Writeln('It was false!');
end.
That's a smudgy version of what you wanted. I'm tired too; can't think straight right now. Hope that helps a little, to build off of maybe.
Jason2gs
03-23-2007, 03:47 PM
Hey, that's cool :p
Thanks man :)
Powered by vBulletin® Version 4.2.1 Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.