Results 1 to 6 of 6

Thread: How to extract a number value from chat

  1. #1
    Join Date
    May 2012
    Posts
    37
    Mentioned
    0 Post(s)
    Quoted
    6 Post(s)

    Default How to extract a number value from chat

    Hello

    I am trying to create an function that will switch world according to the chat like for portables FC. For example, if well can't be found after 5 mins it will read the chat and find the world by "well84ca".

    This is what I began :

    Code:
    procedure findWorld();
    begin
      var
        text: String;
        world: String;
      repeat
        wait(1000);
      until(chatbox.findTextOnLines(['fo','Forge','forge','well','Well'],[0]) and chatbox.findTextOnLines(['ca','CA'],[0]));
      text := chatbox.findTextOnLine();
    end;
    The problem now is I don't know how to extract the world because with chatbox.findTextOnLine it takes the whole line with players name that can contains number. How can I append the text ? Use TString ?

    Thanks !

  2. #2
    Join Date
    Jan 2012
    Posts
    1,596
    Mentioned
    78 Post(s)
    Quoted
    826 Post(s)

    Default

    Simba Code:
    world := StrToIntDef(ExtractFromStr(between(':', text[length(text)],text), numbers), -1);
    Should get the numbers from the chat message, or return -1.

  3. #3
    Join Date
    May 2012
    Posts
    37
    Mentioned
    0 Post(s)
    Quoted
    6 Post(s)

    Default

    Quote Originally Posted by Turpinator View Post
    Simba Code:
    world := StrToIntDef(ExtractFromStr(between(':', text[length(text)],text), numbers), -1);
    Should get the numbers from the chat message, or return -1.
    Thhanks that worked ! Can you explain me what is text[length(text)] ? ^_^

  4. #4
    Join Date
    Jan 2012
    Posts
    1,596
    Mentioned
    78 Post(s)
    Quoted
    826 Post(s)

    Default

    lets say text is 'this is some text'
    and if you want to access individual characters, you can just do text[3] (that would get you 'i'). If you wanted the 'o', it would be text[10]. etc etc.
    and length(text) is... the length.
    so put it all together, and you get... the last character in the string.

    You could also have used the right() func, but off the top of my head, i wasnt sure the params.
    (right() will get you the right portion of the string, from the specified index) So that would have been simpler, but... yeaaah


    Ooo. i just realized this wont work if the string has repeating letters.
    Simba Code:
    world := StrToIntDef(ExtractFromStr(copy(text, length(text)+1-pos(':', text), pos(':', text)) , numbers), -1);
    Seems as if simba doesnt have right() off the bat. Very well. I did it with the copy() func.

  5. #5
    Join Date
    May 2012
    Posts
    37
    Mentioned
    0 Post(s)
    Quoted
    6 Post(s)

    Default

    Quote Originally Posted by Turpinator View Post
    lets say text is 'this is some text'
    and if you want to access individual characters, you can just do text[3] (that would get you 'i'). If you wanted the 'o', it would be text[10]. etc etc.
    and length(text) is... the length.
    so put it all together, and you get... the last character in the string.

    You could also have used the right() func, but off the top of my head, i wasnt sure the params.
    (right() will get you the right portion of the string, from the specified index) So that would have been simpler, but... yeaaah


    Ooo. i just realized this wont work if the string has repeating letters.
    Simba Code:
    world := StrToIntDef(ExtractFromStr(copy(text, length(text)+1-pos(':', text), pos(':', text)) , numbers), -1);
    Seems as if simba doesnt have right() off the bat. Very well. I did it with the copy() func.
    The issue with this last code is it concatenate the number in IG name too.

  6. #6
    Join Date
    Jan 2012
    Posts
    1,596
    Mentioned
    78 Post(s)
    Quoted
    826 Post(s)

    Default

    Simba Code:
    program new;
    var
      text : string = 'turp9: coal43dc';
      world : integer;

    begin
      world := StrToIntDef(ExtractFromStr(copy(text, length(text)+1-pos(':', text), pos(':', text)) , numbers), -1);
      writeln(world);
    end
    Progress Report:
    Compiled successfully in 266 ms.
    43
    Successfully executed.

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
  •