PDA

View Full Version : Mainloop sequence question



Renzanity
03-09-2015, 02:41 PM
Hi everyone, I need help about how I can fix the sequence of my script. I can't seem to make it do what I intend it to do. It does kill the cows, but it continuously goes on killing and not loot anything.

To put it simply, I want it to:

1st Run to the location where the Cows are
2nd Kill 1 cow
3rd Wait for the loot to surface and then loot it
4th Continue to kill Cows and looting until the bag is full
5th Run to the bank to deposit



repeat
if (tabBackpack.isEmpty) then
pToCowPen();

repeat
killCows();
pReport();
lootHides();
pReport();
until (tabBackpack.isFull);

if (tabBackpack.isFull) then
pToBank();
dHides();

until (false);



Or I think maybe it's my looting procedure that's wrong so I'm displaying it here as well.


//To loot cowhides
procedure lootHides();
var
x, y: integer;
begin
mainscreen.findObject(x, y, 8422864, 26,colorSetting(2, 0.05, 0.87), mainscreen.playerPoint, 10, 70, 70, ['aw', 'owhide', 'ones'], MOUSE_RIGHT);
wait(randomRange(800, 1000));
chooseOption.select(['ake Cowhide']);
wait(randomRange(1000, 1500));
inc(hC);
end;



If you want to see my whole script to look into it more, let me know on a post below.

Thanks in advance! :norris:

fady
03-09-2015, 03:06 PM
Hi everyone, I need help about how I can fix the sequence of my script. I can't seem to make it do what I intend it to do. It does kill the cows, but it continuously goes on killing and not loot anything.

To put it simply, I want it to:

1st Run to the location where the Cows are
2nd Kill 1 cow
3rd Wait for the loot to surface and then loot it
4th Continue to kill Cows and looting until the bag is full
5th Run to the bank to deposit



repeat
if (tabBackpack.isEmpty) then
pToCowPen();

repeat
killCows();
pReport();
lootHides();
pReport();
until (tabBackpack.isFull);

if (tabBackpack.isFull) then
pToBank();
dHides();

until (false);



Or I think maybe it's my looting procedure that's wrong so I'm displaying it here as well.


//To loot cowhides
procedure lootHides();
var
x, y: integer;
begin
mainscreen.findObject(x, y, 8422864, 26,colorSetting(2, 0.05, 0.87), mainscreen.playerPoint, 10, 70, 70, ['aw', 'owhide', 'ones'], MOUSE_RIGHT);
wait(randomRange(800, 1000));
chooseOption.select(['ake Cowhide']);
wait(randomRange(1000, 1500));
inc(hC);
end;



If you want to see my whole script to look into it more, let me know on a post below.

Thanks in advance! :norris:



does the progress report change after killing the cow? if not, can I see the killCow procedure? if yes, can I see the pReport procedure?

also I suggest adding the following, so both procedures are linked to the IF statement
if (tabBackpack.isFull) then
begin //begin here
pToBank();
dHides();
end; //end here

Renzanity
03-09-2015, 03:17 PM
does the progress report change after killing the cow? if not, can I see the killCow procedure? if yes, can I see the pReport procedure?

also I suggest adding the following, so both procedures are linked to the IF statement
if (tabBackpack.isFull) then
begin //begin here
pToBank();
dHides();
end; //end here

The progress report do change everytime I kill a cow. Here's the procedure.


//Progress Report
procedure pReport();
var
CowsKilled, HidesLoot, CPH, HPH: integer;
begin
CowsKilled := cK;
HidesLoot := hC;
CPH := round((CowsKilled * 60) / (getTimeRunning() / 60000));
HPH := round((HidesLoot * 60) / (getTimeRunning() / 60000));

clearDebug();
writeLn('========================================= ==========================');
writeLn('==================Renzanity Taverley Cowhide Looter================');
writeLn('========================================= ==========================');
writeLn('Time Ran: ' + timeRunning);
writeLn('Cows Killed: ' + intToStr(CowsKilled) + ' cows');
writeLn('Cowhides Looted: ' + intToStr(HidesLoot) + ' pcs');
writeLn('Cows/hr: ' + intToStr(CPH));
writeLn('Hides/hr: ' + intToStr(HPH));
writeLn('========================================= ==========================');
writeLn('==========================HAPPY BOTTING============================');
writeLn('========================================= ==========================');
end;


And I changed that section where the killCows(); and lootHides(); are. It's now

repeat
killCows();
lootHides();
pReport();
until (tabBackpack.isFull);

And thanks for that tip! :norris:

3Garrett3
03-09-2015, 03:20 PM
Hi everyone, I need help about how I can fix the sequence of my script. I can't seem to make it do what I intend it to do. It does kill the cows, but it continuously goes on killing and not loot anything.

To put it simply, I want it to:

1st Run to the location where the Cows are
2nd Kill 1 cow
3rd Wait for the loot to surface and then loot it
4th Continue to kill Cows and looting until the bag is full
5th Run to the bank to deposit



repeat
if (tabBackpack.isEmpty) then
pToCowPen();

repeat
killCows();
pReport();
lootHides();
pReport();
until (tabBackpack.isFull);

if (tabBackpack.isFull) then
pToBank();
dHides();

until (false);



Or I think maybe it's my looting procedure that's wrong so I'm displaying it here as well.


//To loot cowhides
procedure lootHides();
var
x, y: integer;
begin
mainscreen.findObject(x, y, 8422864, 26,colorSetting(2, 0.05, 0.87), mainscreen.playerPoint, 10, 70, 70, ['aw', 'owhide', 'ones'], MOUSE_RIGHT);
wait(randomRange(800, 1000));
chooseOption.select(['ake Cowhide']);
wait(randomRange(1000, 1500));
inc(hC);
end;



If you want to see my whole script to look into it more, let me know on a post below.

Thanks in advance! :norris:

Here's a couple pointers:

Mainloop - You have an if statement after the repeat. I'm assuming both functions after are supposed to be performed because they're both indented the same. You need those in a begin/end statement or it will only complete the first action if the "if/then" is true.

So:


repeat
if (tabBackpack.isEmpty) then
pToCowPen();
repeat
killCows();
pReport();
lootHides();
pReport();
until (tabBackpack.isFull);

if (tabBackpack.isFull) then
begin
pToBank();
dHides();
end;
until (false);


However, using the logic in your script, it will not get to the "if/then" part unless the backpack is full. So the additional if statement is not really required unless you want a second check. Could just be:


repeat
if (tabBackpack.isEmpty) then
pToCowPen();
repeat
killCows();
pReport();
lootHides();
pReport();
until (tabBackpack.isFull);

pToBank();
dHides();

until (false);


Also, all of your indents are 2x the amount they need to be. One tab (or 2 spaces) is all that you need. Everything looks like 2 tabs (4 spaces). I'm not going to fix that to show you though ;).

As for your original question, "why does it skip looting" I can think of two main reasons.

1) It doesn't wait long enough for the loot. Cow death animations take forever and it's more efficient when manually killing them to get 2 kills then go back for the loot. That's tough with color though so you're going to need to wait for the death animation before checking for loot, otherwise it will just skip over it.

2) The colors aren't working and it can't find them. I'd suggest staying away from mainScreen.findObject anyway and moving to TPA finding as soon as you can. There is a section in The Mayor's guide which describes how to use it and you should find that pretty easy to use. It will give you way better object finding IMO.

I'd also suggest (if you want to stay with findObject) doing the following:


procedure lootHides();
var
x, y: integer;
begin
if mainscreen.findObject(x, y, 8422864, 26,colorSetting(2, 0.05, 0.87), mainscreen.playerPoint, 10, 70, 70, ['aw', 'owhide', 'ones'], MOUSE_RIGHT) then
begin
wait(randomRange(800, 1000));
chooseOption.select(['ake Cowhide']);
wait(randomRange(1000, 1500));
inc(hC);
end;
end;


That way it isn't searching for a chooseOption without actually right-clicking on the loot.

If you want more information on what's going on in your script, I suggest putting a bunch of writeLn calls everywhere. For example:


procedure lootHides();
var
x, y: integer;
begin
writeln('Starting lootHides');
if mainscreen.findObject(x, y, 8422864, 26,colorSetting(2, 0.05, 0.87), mainscreen.playerPoint, 10, 70, 70, ['aw', 'owhide', 'ones'], MOUSE_RIGHT) then
begin
writeln('Found object, choosing option');
wait(randomRange(800, 1000));
chooseOption.select(['ake Cowhide']);
wait(randomRange(1000, 1500));
inc(hC);
end else writeln('Did not find object');
end;


Then you'll know what's going on in the script and you should be able to figure out where it's going wrong.

Renzanity
03-09-2015, 03:39 PM
Here's a couple pointers:

Mainloop - You have an if statement after the repeat. I'm assuming both functions after are supposed to be performed because they're both indented the same. You need those in a begin/end statement or it will only complete the first action if the "if/then" is true.

So:


repeat
if (tabBackpack.isEmpty) then
pToCowPen();
repeat
killCows();
pReport();
lootHides();
pReport();
until (tabBackpack.isFull);

if (tabBackpack.isFull) then
begin
pToBank();
dHides();
end;
until (false);


However, using the logic in your script, it will not get to the "if/then" part unless the backpack is full. So the additional if statement is not really required unless you want a second check. Could just be:


repeat
if (tabBackpack.isEmpty) then
pToCowPen();
repeat
killCows();
pReport();
lootHides();
pReport();
until (tabBackpack.isFull);

pToBank();
dHides();

until (false);


Also, all of your indents are 2x the amount they need to be. One tab (or 2 spaces) is all that you need. Everything looks like 2 tabs (4 spaces). I'm not going to fix that to show you though ;).

As for your original question, "why does it skip looting" I can think of two main reasons.

1) It doesn't wait long enough for the loot. Cow death animations take forever and it's more efficient when manually killing them to get 2 kills then go back for the loot. That's tough with color though so you're going to need to wait for the death animation before checking for loot, otherwise it will just skip over it.

2) The colors aren't working and it can't find them. I'd suggest staying away from mainScreen.findObject anyway and moving to TPA finding as soon as you can. There is a section in The Mayor's guide which describes how to use it and you should find that pretty easy to use. It will give you way better object finding IMO.

I'd also suggest (if you want to stay with findObject) doing the following:


procedure lootHides();
var
x, y: integer;
begin
if mainscreen.findObject(x, y, 8422864, 26,colorSetting(2, 0.05, 0.87), mainscreen.playerPoint, 10, 70, 70, ['aw', 'owhide', 'ones'], MOUSE_RIGHT) then
begin
wait(randomRange(800, 1000));
chooseOption.select(['ake Cowhide']);
wait(randomRange(1000, 1500));
inc(hC);
end;
end;


That way it isn't searching for a chooseOption without actually right-clicking on the loot.

If you want more information on what's going on in your script, I suggest putting a bunch of writeLn calls everywhere. For example:


procedure lootHides();
var
x, y: integer;
begin
writeln('Starting lootHides');
if mainscreen.findObject(x, y, 8422864, 26,colorSetting(2, 0.05, 0.87), mainscreen.playerPoint, 10, 70, 70, ['aw', 'owhide', 'ones'], MOUSE_RIGHT) then
begin
writeln('Found object, choosing option');
wait(randomRange(800, 1000));
chooseOption.select(['ake Cowhide']);
wait(randomRange(1000, 1500));
inc(hC);
end else writeln('Did not find object');
end;


Then you'll know what's going on in the script and you should be able to figure out where it's going wrong.

Thanks for the effort on replying on my post, sir! :norris:

I think the findObj function can't find the color. I'll be trying to use TPA now, I just assumed that findObj would work because I used it on my Jug Filler script just a few days ago. :)

And yes, the indents are pretty horrific. Haha. I'll be sure to follow the right indentations now. And will be updating my other script's indentations as well. :D

Renzanity
03-09-2015, 03:54 PM
I recalibrated my findObj function and it's now looting the hides.
Upon checking on The Mayor's AiO tutorial, I saw this again and was reminded that I could change this via trial-and-error.

if mainscreen.findObject(x, y, 8422864, 26,colorSetting(2, 0.05, 0.87), mainscreen.playerPoint, 10, 10, 5, ['aw', 'owhide', 'ones'], MOUSE_RIGHT) then

My object has a width of about 10 pixels
My object has a height of about 10 pixels
I want it to find at least 5 matching pixels

Now I'll just have to fix the wait() on my procedures to make it accurately wait for the dying cow animation to finish.

Thanks!

I'll be back here whenever I tackle some problems I can't figure out myself. :D

3Garrett3
03-09-2015, 03:58 PM
I recalibrated my findObj function and it's now looting the hides.
Upon checking on The Mayor's AiO tutorial, I saw this again and was reminded that I could change this via trial-and-error.

if mainscreen.findObject(x, y, 8422864, 26,colorSetting(2, 0.05, 0.87), mainscreen.playerPoint, 10, 10, 5, ['aw', 'owhide', 'ones'], MOUSE_RIGHT) then

My object has a width of about 10 pixels
My object has a height of about 10 pixels
I want it to find at least 5 matching pixels

Wooo, so it's working now? Glad to hear it! Post here again if anything breaks or whatnot. Also lots of helpful people idle on IRC so feel free to pop on there with questions if you have any more.

Renzanity
03-09-2015, 04:00 PM
Wooo, so it's working now? Glad to hear it! Post here again if anything breaks or whatnot. Also lots of helpful people idle on IRC so feel free to pop on there with questions if you have any more.

I'll be sure to do that soon. I didn't know scripting would be fun like this. :P

And yes it is, a little more recalibration on the waits and it'll work perfectly soon, thank you, sir. :D