Results 1 to 8 of 8

Thread: random choose problem

  1. #1
    Join Date
    Feb 2012
    Posts
    224
    Mentioned
    1 Post(s)
    Quoted
    8 Post(s)

    Default random choose problem

    i use this in my firemaking script to make it randomly step north or south when get msg (cant light fire here). so here is how it looks like


    Simba Code:
    if FindBlackChatMessage('here') then
    begin
     case random(1) of
      1: begin
           WriteLn('Stepping North.');
            Mouse(258, 150, 3, 3, True);
            While IsMoving do
            wait(10);
           end;

    2:  begin
           WriteLn('Stepping South.');
            Mouse(259, 213, 3, 3, True);
            While IsMoving do
            wait(10);
          end;        
      end;
    end;

    the problem is it never steps south(always north) or doesnt move at all

    enyone knows why?

  2. #2
    Join Date
    Oct 2008
    Location
    C:\Simba\Includes\
    Posts
    7,566
    Mentioned
    19 Post(s)
    Quoted
    180 Post(s)

    Default

    Change the 1/2 of the case to 0/1, because Random(1) returns either 0 or 1.
    Away for awhile, life is keeping me busy. | Want to get my attention in a thread? @Kyle Undefined; me.
    { MSI Phoenix || SRL Stats Sigs || Paste || Scripts || Quotes || Graphics }

    When posting a bug, please post debug! Help us, help you!

    I would love to change the world, but they won't give me the source code. || To be the best, you've got to beat the rest. || Logic never changes, just the syntax.
    If you PM me with a stupid question or one listed in FAQ, or about a script that is not mine, I will NOT respond.


    SRL is a Library of routines made by the SRL community written for the Program Simba. We produce Scripts for the game Runescape.


  3. #3
    Join Date
    Oct 2011
    Location
    UK
    Posts
    1,322
    Mentioned
    2 Post(s)
    Quoted
    1 Post(s)

    Default

    Quote Originally Posted by Kyle Undefined View Post
    Change the 1/2 of the case to 0/1, because Random(1) returns either 0 or 1.
    Doesn't Random(1) always return 0. He would want Random(2)

    Also get rid of those static waits!!!
    Last edited by putonajonny; 04-25-2012 at 07:35 PM.

  4. #4
    Join Date
    Oct 2008
    Location
    C:\Simba\Includes\
    Posts
    7,566
    Mentioned
    19 Post(s)
    Quoted
    180 Post(s)

    Default

    It starts at 0, and the number you pass in "1" is the highest it will go. Random(2) will return 0/1/2
    Away for awhile, life is keeping me busy. | Want to get my attention in a thread? @Kyle Undefined; me.
    { MSI Phoenix || SRL Stats Sigs || Paste || Scripts || Quotes || Graphics }

    When posting a bug, please post debug! Help us, help you!

    I would love to change the world, but they won't give me the source code. || To be the best, you've got to beat the rest. || Logic never changes, just the syntax.
    If you PM me with a stupid question or one listed in FAQ, or about a script that is not mine, I will NOT respond.


    SRL is a Library of routines made by the SRL community written for the Program Simba. We produce Scripts for the game Runescape.


  5. #5
    Join Date
    Feb 2012
    Posts
    224
    Mentioned
    1 Post(s)
    Quoted
    8 Post(s)

    Default

    oh lol ur right how could i forget this (duh)

  6. #6
    Join Date
    Feb 2012
    Posts
    224
    Mentioned
    1 Post(s)
    Quoted
    8 Post(s)

    Default


  7. #7
    Join Date
    Feb 2012
    Location
    Somewhere, over the rainbow...
    Posts
    2,272
    Mentioned
    3 Post(s)
    Quoted
    45 Post(s)

    Default

    Quote Originally Posted by Kyle Undefined View Post
    Random(2) will return 0/1/2
    Not true. The numbers in the bracket is the number it goes to, starting from 0. So it will return 0 and 1 only.

    Proof:
    Simba Code:
    procedure Test;
    begin
      case Random(2) of

      0: Writeln('Got 0');
      1: Writeln('Got 1');
      2: Writeln('Got 2');

      end;
    end;

    begin
      ClearDebug;
      SetUpSRL;
      repeat
        inc(Tests)
        Wait(500);
        Test;
      until Tests = 20;
    end.


    And here is the result:
    Code:
    Got 1
    Got 0
    Got 0
    Got 0
    Got 1
    Got 0
    Got 0
    Got 1
    Got 1
    Got 1
    Got 0
    Got 1
    Got 0
    Got 0
    Got 1
    Got 0
    Got 1
    Got 0
    Got 0
    Got 1

  8. #8
    Join Date
    Oct 2008
    Location
    C:\Simba\Includes\
    Posts
    7,566
    Mentioned
    19 Post(s)
    Quoted
    180 Post(s)

    Default

    Ah yes, you are right. I forgot that Random in PS is totally different than what I'm use to So I was wrong, it starts a 0 and will go up to the number passed in - 1.
    Away for awhile, life is keeping me busy. | Want to get my attention in a thread? @Kyle Undefined; me.
    { MSI Phoenix || SRL Stats Sigs || Paste || Scripts || Quotes || Graphics }

    When posting a bug, please post debug! Help us, help you!

    I would love to change the world, but they won't give me the source code. || To be the best, you've got to beat the rest. || Logic never changes, just the syntax.
    If you PM me with a stupid question or one listed in FAQ, or about a script that is not mine, I will NOT respond.


    SRL is a Library of routines made by the SRL community written for the Program Simba. We produce Scripts for the game Runescape.


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
  •