SRL Archive - FAQ

Help with loops.


Zeta Matt

2013-09-07 12:02:29


begin //this micro script has no meaning, is just an example...
SetupSRL
While FindColorTolerance(x, y, color, xs, ys, xc, yc, tolerance) do DetectMiniMapForClanMates;
end.

When I call this, it will first FindColorTolerance and then, if it did find the color, it will DetectMiniMapForClanMates… if the color wasn't found, it won't DetectMiniMapForClanMates.
.
But, what I need is: it will both FindColorTolerance and DetectMiniMapForClanMates; if the color was found, it will just continue doing both…if the color wasn't found, then it will stop DetectMiniMapForClanMates right when this procedure ends, and then will continue to the rest of the script… How could I do this?

Itankbots

2013-09-07 14:35:34

From: archermaths

begin //this micro script has no meaning, is just an example...
SetupSRL
While FindColorTolerance(x, y, color, xs, ys, xc, yc, tolerance) do DetectMiniMapForClanMates;
end.

When I call this, it will first FindColorTolerance and then, if it did find the color, it will DetectMiniMapForClanMates… if the color wasn't found, it won't DetectMiniMapForClanMates.
.
But, what I need is: it will both FindColorTolerance and DetectMiniMapForClanMates; if the color was found, it will just continue doing both…if the color wasn't found, then it will stop DetectMiniMapForClanMates right when this procedure ends, and then will continue to the rest of the script… How could I do this?


begin
SetupSRL;
While FindColorTolerance(x, y, color, xs, ys, xc, yc, tolerance) Do
Repeat
DetectMiniMapForClanMates;
Until Not FindColorTolerance(x, y, color, xs, ys, xc, yc, tolerance);
end.

Is this what you mean? It will repeat DetectMiniMapForClanMates Until it fails to find your colour.

Zeta Matt

2013-09-07 14:49:55

I'm afraid not =( It will FindColor and, if it wasn't found, it will end the script. If it found the color, then it will do: DetectMiniMap -> FindColor -> DetectMiniMap -> FindColor… I need something that does both at the same time… I think this micro script will explain better what I want:


begin //This is just to explain what I want, the syntax is incorrect
SetupSRL;
While
begin
Repeat ChopAndBankLogs until t=1000(*forever*)
end;
do
begin
Repeat DetectMiniMapForClanMates until MateWasDetected;
end; //The meaning: it will chop and bank the logs normally, like a woodcutting script would do.
//While doing this Chopping and Banking, it would keep, everytime, detecting MiniMap for orange dots.
//If it detected an orange dot, DetectMiniMapForClanMates would return true, and the loop "While...do" would be stopped.
end.

Trying to explain, again, it's like I created a woodcutting program and a DetectMiniMapForClanMates program. I would put both to the same client and run both at the same time. That's what I want to do, but in the same script.

I know I could put it to DetectMiniMap in many places in the middle of ChopAndBankLogs program… But since DetectingMiniMap is something I want to run from the start to the end of the script, it would be better if I could just put it like that.

Itankbots

2013-09-07 19:19:49

Ohh…you're trying to Multithread. I.E. Do two Things simultaneously.

im 90% Sure thats currently not possible with Simba :( Which is one of the drawbacks. I think SRL6 and Lape Might have the ability, but im not 100% sure, can't remember, Kinda sick atm so my memory is bad Lol Sorry.

So basically what you need to do is Set a timer, for how often you want to check for ClanMates on the minimap, So lets say thats every 10 seconds.

Then you just need to make it Repeat ChopAndBank Logs Untill Timer>10seconds. Then Check for clan mates. Then Back to Chopping logs.

I believe thats what you're trying to do yeah? If you still dont understand how to do that, i can write an example in a second. Just on Ipad and too hard to code on this :P

Brandon

2013-09-07 19:49:55

You can just use the "And/Or/Xor" keywords in a statement..


//Ex:
while (ChoppingLogs Or Banking) do //can also replace or with xor because you can't be banking and chopping at the same time ;)
begin
If DetectMates Then
Exit; //Or TerminateScript; Or Break;
Wait(10);
end;

//Ex2:
while((ChoppingLogs Or Banking) And (Not DetectMates)) Do
Begin
writeln('Chopping logs.. No mates around..');
Wait(10);
End;

Zeta Matt

2013-09-07 21:23:41

Any time you use "or", "and" or "xor", it executes the procedures in the order given. In your example:
//Ex2:
while((ChoppingLogs Or Banking) And (Not DetectMates)) Do
Begin
writeln('Chopping logs.. No mates around..');
Wait(10);
End;
It would check if you are chopping logs, then it would check if you are banking and then it would check if mates were detected… I want it to do 2 things at the same time, not one and then another.

Sjoe

2013-09-07 21:27:34

From: archermaths
Any time you use "or", "and" or "xor", it executes the procedures in the order given. In your example:
//Ex2:
while((ChoppingLogs Or Banking) And (Not DetectMates)) Do
Begin
writeln('Chopping logs.. No mates around..');
Wait(10);
End;
It would check if you are chopping logs, then it would check if you are banking and then it would check if mates were detected… I want it to do 2 things at the same time, not one and then another.


It does check both though. Hence the 'and'
It would not chop logs if it is detecting mates.

Zeta Matt

2013-09-07 21:28:05

From: Itankbots
Ohh…you're trying to Multithread. I.E. Do two Things simultaneously.

im 90% Sure thats currently not possible with Simba :( Which is one of the drawbacks. I think SRL6 and Lape Might have the ability, but im not 100% sure, can't remember, Kinda sick atm so my memory is bad Lol Sorry.

So basically what you need to do is Set a timer, for how often you want to check for ClanMates on the minimap, So lets say thats every 10 seconds.

Then you just need to make it Repeat ChopAndBank Logs Untill Timer>10seconds. Then Check for clan mates. Then Back to Chopping logs.

I believe thats what you're trying to do yeah? If you still dont understand how to do that, i can write an example in a second. Just on Ipad and too hard to code on this :P


I kinda liked that suggestion, but ChopAndBank is a long function; If i put Repeat ChopAndBank until Timer>10 seconds, it would only know if it has passed 10 seconds when the function ended… when it had passed much more than 10 seconds lol…
So, on summary, seems that my only option is to put many "DetectMiniMap" procedures along the function "ChopAndBank" which was what I didn't want to do :D haha, thanks anyways guys!

Sjoe

2013-09-07 21:43:47

From: archermaths
I kinda liked that suggestion, but ChopAndBank is a long function; If i put Repeat ChopAndBank until Timer>10 seconds, it would only know if it has passed 10 seconds when the function ended… when it had passed much more than 10 seconds lol…
So, on summary, seems that my only option is to put many "DetectMiniMap" procedures along the function "ChopAndBank" which was what I didn't want to do :D haha, thanks anyways guys!


yeah that's gotta be your alternative to 'multithreading', calling the function as much as possible :)