Results 1 to 10 of 10

Thread: Alternating a boolean result

  1. #1
    Join Date
    May 2012
    Posts
    499
    Mentioned
    23 Post(s)
    Quoted
    228 Post(s)

    Default Alternating a boolean result

    Hey,

    Does anyone have some suggestions to alternate a boolean result?
    Currently I use something this:
    Simba Code:
    minimap.clickCompass(random(2));
    But I would like to alternate a true and false (camera north and south).
    I suppose I could store it globally? But unsure how to do it without using 10+ lines.

    Ended up using this:
    Simba Code:
    minimap.clickCompass(Compass);
        if Compass then
          Compass := false
        else
        compass := true;

  2. #2
    Join Date
    Dec 2011
    Location
    East Coast, USA
    Posts
    4,231
    Mentioned
    112 Post(s)
    Quoted
    1869 Post(s)

    Default

    Well minimap.clickCompass() specifically is a procedure, so doesn't give you that capability.

    But any routine that is a function which returns a boolean (such as minimap.isFlagPresent()) you could assign to the result of the function.

    Simba Code:
    compass := minimap.isFlagPresent();
    or even
    Simba Code:
    if (minimap.isFlagPresent()) then
    . It can be used exactly like any old boolean, since it returns one.

    If you want to get really cool, I suppose you could modify .clickCompass() to return a boolean, but I'm not sure if that would be useful considering the nature of the routine.


    ***


    More to the point of your question, you could use a case statement if you really wanted to randomize the angle, here's how I do it:

    Declare these
    Simba Code:
    const
      MM_DIRECTION_NORTHEAST = 45;
      MM_DIRECTION_SOUTHEAST = 135;
      MM_DIRECTION_SOUTHWEST = 225;
      MM_DIRECTION_NORTHWEST = 315;
    and then call this
    Simba Code:
    function TRSMinimap.randomAngle(return:boolean = false):boolean; //Turns to a random angle. Returns to original if "return" is true.
    var
      a, b:extended;
    begin
      writeDebug('Altering angle direction');
      a := self.getAngleDegrees();
      writeDebug('Angle is currently ' + toStr(a));

      case random(8) of
       0: self.setAngle(MM_DIRECTION_NORTH);
       1: self.setAngle(MM_DIRECTION_SOUTH);
       2: self.setAngle(MM_DIRECTION_EAST);
       3: self.setAngle(MM_DIRECTION_WEST);
       4: self.setAngle(MM_DIRECTION_NORTHEAST);
       5: self.setAngle(MM_DIRECTION_SOUTHEAST);
       6: self.setAngle(MM_DIRECTION_NORTHWEST);
       7: self.setAngle(MM_DIRECTION_SOUTHWEST);
      end;

      b := self.getAngleDegrees();
      writeDebug('Angle was altered to ' + toStr(b));

      if (return) then
       begin
         writeDebug('Returning angle to ' + toStr(a));
         self.setAngle(a);
       end;
    end;

    ***

    But if you wanted to be really cool, you could dump .setAngle() and use .isAngle() which I find to be a tad more efficient.
    Simba Code:
    function TRSMinimap.isAngle(deg:extended; turnTo:boolean = false):boolean; //Returns true if the current compass angle is within a few degrees of "deg"
    var                                                                        //Will also turn to "deg" if turnTo is true.
      a:extended;
    begin
      a := self.getAngleDegrees();

      result := inRange(round(a), (deg - 5), (deg + 5));
      writeDebug('isAngle(): angle is currently ' + toStr(a) + ', threshold was ' + toStr(deg) + ', returning ' + lowercase(toStr(result)) + '');

      if (not (result)) then
       if (turnTo) then
        begin
          writeDebug('isAngle(): altering angle to ' + toStr(deg));
          self.setAngle(deg);
        end;
    end;
    Last edited by KeepBotting; 05-16-2015 at 01:07 PM. Reason: This is the last edit, I promise
    GitLab projects | Simba 1.4 | Find me on IRC or Discord | ScapeRune scripts | Come play bot ScapeRune!

    <BenLand100> we're just in the transitional phase where society reclassifies guns as Bad™ before everyone gets laser pistols

  3. #3
    Join Date
    Jun 2007
    Location
    The land of the long white cloud.
    Posts
    3,702
    Mentioned
    261 Post(s)
    Quoted
    2006 Post(s)

    Default

    To alternate, you could do something like

    Simba Code:
    var
      north: boolean;

    procedure moveCompass();
    begin
      minimap.clickCompass(north := not north);
    end;

  4. #4
    Join Date
    May 2012
    Posts
    499
    Mentioned
    23 Post(s)
    Quoted
    228 Post(s)

    Default

    Not even close to what I asked but thanks anyway.
    Clickcompass() has the option to right click it and select south.
    This way I can just alternate between north and south, and that is exactly what I needed.

  5. #5
    Join Date
    Dec 2011
    Location
    East Coast, USA
    Posts
    4,231
    Mentioned
    112 Post(s)
    Quoted
    1869 Post(s)

    Default

    Quote Originally Posted by lovebotter View Post
    Not even close to what I asked but thanks anyway.
    Clickcompass() has the option to right click it and select south.
    This way I can just alternate between north and south, and that is exactly what I needed.
    To whom is the first line directed? I edited my original post, added a bit more information. Is it still irrelevant?

    Glad you found out about .clickCompass()'s optional boolean lol, I must not have understood the question properly or I'd have suggested it
    GitLab projects | Simba 1.4 | Find me on IRC or Discord | ScapeRune scripts | Come play bot ScapeRune!

    <BenLand100> we're just in the transitional phase where society reclassifies guns as Bad™ before everyone gets laser pistols

  6. #6
    Join Date
    May 2012
    Posts
    499
    Mentioned
    23 Post(s)
    Quoted
    228 Post(s)

    Default

    Quote Originally Posted by The Mayor View Post
    To alternate, you could do something like

    Simba Code:
    var
      north: boolean;

    procedure moveCompass();
    begin
      minimap.clickCompass(north := not north);
    end;

    Thanks! Quite a bit shorter then mine!
    So it starts true or false on default? Or would I have to mention that?

  7. #7
    Join Date
    May 2012
    Posts
    499
    Mentioned
    23 Post(s)
    Quoted
    228 Post(s)

    Default

    Quote Originally Posted by KeepBotting View Post
    To whom is the first line directed? I edited my original post, added a bit more information. Is it still irrelevant?

    Glad you found out about .clickCompass()'s optional boolean lol, I must not have understood the question properly or I'd have suggested it
    Well the mayor's reply is exactly what I was looking for. Just didn't come up with the way to write it that short.

    Yours is helpfull, but not needed for me

  8. #8
    Join Date
    Dec 2011
    Location
    East Coast, USA
    Posts
    4,231
    Mentioned
    112 Post(s)
    Quoted
    1869 Post(s)

    Default

    Quote Originally Posted by lovebotter View Post
    Well the mayor's reply is exactly what I was looking for. Just didn't come up with the way to write it that short.

    Yours is helpfull, but not needed for me
    Ah, I see. Sorry I couldn't be of more help it's really early..
    GitLab projects | Simba 1.4 | Find me on IRC or Discord | ScapeRune scripts | Come play bot ScapeRune!

    <BenLand100> we're just in the transitional phase where society reclassifies guns as Bad™ before everyone gets laser pistols

  9. #9
    Join Date
    Jun 2007
    Location
    The land of the long white cloud.
    Posts
    3,702
    Mentioned
    261 Post(s)
    Quoted
    2006 Post(s)

    Default

    Quote Originally Posted by lovebotter View Post
    Thanks! Quite a bit shorter then mine!
    So it starts true or false on default? Or would I have to mention that?
    Well the boolean is uninitialized and defaults to false, so to start with north, you could go:

    Simba Code:
    var
      north: boolean := true;

  10. #10
    Join Date
    May 2012
    Posts
    499
    Mentioned
    23 Post(s)
    Quoted
    228 Post(s)

    Default

    Quote Originally Posted by The Mayor View Post
    Well the boolean is uninitialized and defaults to false, so to start with north, you could go:

    Simba Code:
    var
      north: boolean := true;
    Was just wondering if I actually had to set it true/false first before using it
    Thanks!

    @keepbotting,
    I usually use camera.setangle(random(360)),
    But that usually makes camera spin rather retarded, like it tries to find the exact degree.

    But for my current script (combat) just having it alternate north/south works perfectly.

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
  •