SRL Archive - General Botting Help

Alternating a boolean result


Thomas

2015-05-16 08:37:17

Hey,

Does anyone have some suggestions to alternate a boolean result?
Currently I use something this:
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:
       minimap.clickCompass(Compass);
if Compass then
Compass := false
else
compass := true;

KeepBotting

2015-05-16 08:59:12

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.

compass := minimap.isFlagPresent();
or even
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
const
MM_DIRECTION_NORTHEAST = 45;
MM_DIRECTION_SOUTHEAST = 135;
MM_DIRECTION_SOUTHWEST = 225;
MM_DIRECTION_NORTHWEST = 315;
and then call this
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.
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;

The Mayor

2015-05-16 09:17:51

To alternate, you could do something like


var
north: boolean;

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

Thomas

2015-05-16 09:17:56

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.

KeepBotting

2015-05-16 09:19:36

From: lovebotter
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

Thomas

2015-05-16 09:20:16

From: The Mayor
To alternate, you could do something like


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?

Thomas

2015-05-16 09:21:22

From: KeepBotting
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 :)

KeepBotting

2015-05-16 09:22:08

From: lovebotter
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 :p it's really early..

The Mayor

2015-05-16 09:22:58

From: lovebotter
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:


var
north: boolean := true;

Thomas

2015-05-16 09:26:12

From: The Mayor
Well the boolean is uninitialized and defaults to false, so to start with north, you could go:


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.