Results 1 to 9 of 9

Thread: If...Then syntax for cases?

  1. #1
    Join Date
    Dec 2006
    Location
    Third rock from the sun.
    Posts
    2,510
    Mentioned
    4 Post(s)
    Quoted
    1 Post(s)

    Default If...Then syntax for cases?

    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:

    SCAR Code:
    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,

    Mike.

  2. #2
    Join Date
    Dec 2006
    Location
    SC
    Posts
    692
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    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.

    SCAR Code:
    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.

  3. #3
    Join Date
    Dec 2006
    Location
    Third rock from the sun.
    Posts
    2,510
    Mentioned
    4 Post(s)
    Quoted
    1 Post(s)

    Default

    Ah, that would make sense

    Is it possible for me to make a function to basically convert the Writeln procedure to return a boolean?

  4. #4
    Join Date
    Dec 2006
    Location
    SC
    Posts
    692
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Yup. Very simple. Want me to make you one?

  5. #5
    Join Date
    Dec 2006
    Location
    Third rock from the sun.
    Posts
    2,510
    Mentioned
    4 Post(s)
    Quoted
    1 Post(s)

    Default

    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

  6. #6
    Join Date
    Dec 2006
    Location
    SC
    Posts
    692
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Alright, if you need help, pm me msn andrey0ll@yahoo.com or I'll just refresh this every five minutes or so.

  7. #7
    Join Date
    Dec 2006
    Location
    Third rock from the sun.
    Posts
    2,510
    Mentioned
    4 Post(s)
    Quoted
    1 Post(s)

    Default

    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.

    SCAR Code:
    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

  8. #8
    Join Date
    Dec 2006
    Location
    SC
    Posts
    692
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    SCAR Code:
    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.

  9. #9
    Join Date
    Dec 2006
    Location
    Third rock from the sun.
    Posts
    2,510
    Mentioned
    4 Post(s)
    Quoted
    1 Post(s)

    Default

    Hey, that's cool

    Thanks man

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Cases, What are they?
    By Ashur2Good in forum Outdated Tutorials
    Replies: 12
    Last Post: 10-27-2008, 07:55 AM
  2. Cases - how do I use them?
    By R0b0t1 in forum OSR Help
    Replies: 6
    Last Post: 08-30-2007, 02:37 PM
  3. Cases
    By EL_TYCHO in forum OSR Help
    Replies: 2
    Last Post: 06-26-2007, 11:30 AM
  4. Cases
    By inSaner in forum OSR Help
    Replies: 7
    Last Post: 05-06-2007, 04:50 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •