Results 1 to 9 of 9

Thread: Case statement help needed.

  1. #1
    Join Date
    Mar 2007
    Location
    Mars, I thought all men were from Mars.
    Posts
    513
    Mentioned
    7 Post(s)
    Quoted
    124 Post(s)

    Default Case statement help needed.

    I'm a little confused on how I would write a case statement for the procedure below. Instead of using an if statement over and over. Thanks for the help.

    Simba Code:
    procedure Check_for_text;
    begin

      if(FindChatBoxText(Players[0].Nick, 8, clBlue))or
      if(FindChatBoxText('hello', 8, clBlue))or
      if(FindChatBoxText('Hello', 8, clBlue))or
      if(FindChatBoxText('WC lvl', 8, clBlue))or
      if(FindChatBoxText('bot', 8, clBlue))then
        begin
        Writeln('Texted Found')
        end;

    end;

  2. #2
    Join Date
    Feb 2011
    Location
    Earth
    Posts
    1,784
    Mentioned
    1 Post(s)
    Quoted
    0 Post(s)

    Default

    Well I think there is a function that looks for multiple strings in the chatbox that would accomplish the same thing.

    Currently: Working on Defending&Attacking in my Castle-Wars Script
    Project Rebuild: 90M/170M

  3. #3
    Join Date
    Feb 2006
    Posts
    3,044
    Mentioned
    4 Post(s)
    Quoted
    21 Post(s)

    Default

    You should use TStringArray;
    then Loop it through.

    I will post example in a while, can't atm.

    ~Home

  4. #4
    Join Date
    Dec 2011
    Posts
    33
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    i'm not sure but just get rid of all the ifs except the first one? i think there unnecessary and will cause syntax error
    Simba Code:
    procedure Check_for_text;
    begin

      if(FindChatBoxText(Players[0].Nick, 8, clBlue))or
      (FindChatBoxText('hello', 8, clBlue))or
      (FindChatBoxText('Hello', 8, clBlue))or
      (FindChatBoxText('WC lvl', 8, clBlue))or
      (FindChatBoxText('bot', 8, clBlue))then
        begin
        Writeln('Texted Found')
        end;

    end;
    Last edited by shnk; 01-01-2012 at 08:34 PM.

  5. #5
    Join Date
    Feb 2007
    Location
    Het ademt zwaar en moedeloos vannacht.
    Posts
    7,211
    Mentioned
    26 Post(s)
    Quoted
    72 Post(s)

    Default

    Simple loop:
    Simba Code:
    procedure Check_for_text;
    var i : integer;
    searchme : TStringArray;
    begin
      searchme := [players[0].nick, 'hello', 'Hello', 'WC lvl', 'bot'];
      for i := 0 to high(searchme) do
      if(FindChatBoxText(searchme[i], 8, clBlue)then
        begin
        Writeln('Texted Found')
        end;

    end;
    Also, may I suggest using Players[currentplayer].nick? Just makes for cleaner code and makes it way easier in case you decide to implement multiplayer.
    I made a new script, check it out!.

  6. #6
    Join Date
    Mar 2007
    Location
    Mars, I thought all men were from Mars.
    Posts
    513
    Mentioned
    7 Post(s)
    Quoted
    124 Post(s)

    Default

    Quote Originally Posted by Home View Post
    You should use TStringArray;
    then Loop it through.

    I will post example in a while, can't atm.

    ~Home
    Well the idea is to not call the slow if statement so many times, right? I read using the if statement so many times like this is bad scripting.

    Quote Originally Posted by shnk View Post
    i'm not sure but just get rid of all the ifs except the first one? i think there unnecessary and will cause syntax error
    Simba Code:
    procedure Check_for_text;
    begin

      if(FindChatBoxText(Players[0].Nick, 8, clBlue))or
      (FindChatBoxText('hello', 8, clBlue))or
      (FindChatBoxText('Hello', 8, clBlue))or
      (FindChatBoxText('WC lvl', 8, clBlue))or
      (FindChatBoxText('bot', 8, clBlue))then
        begin
        Writeln('Texted Found')
        end;

    end;
    My bad, that was the code I ment to post. Was just in a hurry to post. But like I said above I don't think I should use so many if statements in a row.

    Quote Originally Posted by PatDuffy View Post
    Well I think there is a function that looks for multiple strings in the chatbox that would accomplish the same thing.
    What function is this?

    I tried this but I didn't do something right.

    Simba Code:
    program new;
    {$i srl/srl.scar}
    var
      text :TStringArray;
    begin
    SetupSRL();
    text :=  ['Hello', 'hello', 'bot', 'sup', 'wcing', 'fire']
    if(FindChatBoxText(text, 8, clBlue))then
       begin
        Writeln('Texted Found')
       end;
    end.

  7. #7
    Join Date
    Feb 2009
    Location
    inside Hello World! Application
    Posts
    232
    Mentioned
    0 Post(s)
    Quoted
    8 Post(s)

    Post

    Quote Originally Posted by bud_wis_er_420 View Post

    Simba Code:
    program new;
    {$i srl/srl.scar}
    var
      text :TStringArray;
    begin
    SetupSRL();
    text :=  ['Hello', 'hello', 'bot', 'sup', 'wcing', 'fire']
    if(FindChatBoxText(text, 8, clBlue))then
       begin
        Writeln('Texted Found')
       end;
    end.
    The text variable is a TStringArray so it contains more than one string and in this code with;
    Simba Code:
    If(FindChatBoxText(text,8,clblue)

    You should probably have it as;
    Simba Code:
    For I:= 0 to high(text) do
      If(FindChatBoxText(text[I],8,clblue)) then
        Begin
         WriteLn('Found Text: ' + text[I]); // Reports on found text
      end else
        WriteLn('Text was not Found!'); // either goes here or after the other "end;"
    End;

    Just to explain what's going on abit
    So this will go through all the strings in your array from the first string 'hello' through all the rest until the last string called 'fire'. It will Report what string it'd found by using the WriteLn(); function.


    Simba Code:
    for I:=0 to high(text)
    /\
    This goes through all string in the given array from 0 (which is always the starting string,integer,Boolean etc. In a array! The high(text) finds the last integer,string,Boolean etc. That's what it does but what it means is that it gets the highest number hence the word high... This is a type of loop as it will cycle through whatever is in it as many times starting from "0" in this example to the number "5" as it counts up from "0" so that'd be the numbers;
    Code:
    0
    1
    2
    3
    4
    5
    There are 6 (integers which represent each value in the array). So to sum up it will go through each string looking for a similar one! Very helpful and time saving aswell as good for anti-ban and much more.

    Ps. Sorry if the code I'd made doesn't work I haven't tested it and checked it :/ it mostly from memory a I'm not on Laptop any ques just post below or PM

    ~Bro433
    Last edited by Swatarianess; 01-01-2012 at 09:33 PM.
    I'm not a lesser Being imma Lesser demon


    http://i.imgur.com/faGr0.png << First Script With Paint. Good First proggy? exp 21k/hr is ok pretty buggy

  8. #8
    Join Date
    Mar 2007
    Location
    Mars, I thought all men were from Mars.
    Posts
    513
    Mentioned
    7 Post(s)
    Quoted
    124 Post(s)

    Default

    Awesome, thx very much. I understand now.

  9. #9
    Join Date
    Dec 2011
    Location
    Lubbock, Tx
    Posts
    115
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Instead of starting another thread, I am going to ask my question here. I am trying to use a case statement to basically use the method that the botter chose.

    Like I have the Constant Method= whatever

    I want to use that Constant to determine which method it uses out of this case statement:

    Simba Code:
    Case Method
            1: Begin
                repeat;
                  MineOre;
                if (InvFull) Then
                  Begin
                    DropAll;
                  end;
                ProgressReport;
                Stats_Commit;
                Until (false);
              end;
            2: Begin
                 repeat
                   MineOre;
                    If InvCount= PlusOne Then
                      DropOre;
                      ProgressReport;
                      Stats_Commit;
                    if(Invfull) Then
                    DropAll;
                    AntiBan;
                  Until (false);
               end;
            3:  Begin
                   Repeat
                      Repeat
                        MineOre;
                      Until (InvFull);
                        WalkToBank;
                   Until (false);
                End;
      end

    I have only seen cases with the use of Random() of I want it to be set. Is this even possible?
    My Scripts:
    [HardRockin] Iron Miner (Best mining exp/hr on this site, that I have found)

Thread Information

Users Browsing this Thread

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

Posting Permissions

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