20
« on: May 24, 2021, 09:18:46 PM »
as always, good points!
FIrst, the find recursive logic. I did that because I did not think of going back to main loop! I was sorta thinking of preserving some time, but really, that is kind of illogical now. Orignally, I had the script moving back to a starting spot to restart the command, and I think that is what drove my decision to avoid going back to start.
Second, after fixing the bracket and ignore item (but not changing it to lists), the script still wound up clicking on the hole. I had to add a close cursor command to it. And if I am within 2 tiles of the hole, it still tend to double click it , which causes a reveal.
;-----------------------------
sub charm
retry_charm:
gosub TM_AdvJournalSync FAIL
gosub TM_AdvJournalSync Charm
set #lobjectid %flute2
wait %lagwaits
event macro 17
wait %lagwaits
gosub TM_AdvJournalscan CHARM Valid recharge
wait %lagwaits
If #result = #true
{
wait 1s
set #targcurs 0
goto retry_charm
}
set #ltargetid %target1
set #ltargetkind 1
wait %lagwaits
event macro 22
wait %lagwaits
gosub TM_AdvJournalscan FAIL Valid don't_seem
If #result = #true
{
wait 10
gosub charm
}
wait 5
gosub worldxyztoscreenxy %xhole %yhole %zhole
click %_cursorx %_cursory
ignoreitem %target2
return
Third, thanks for the catch on the egg loop. The end goal for the script is mostly stationary, with moves only when the targets (hole and snake) are out of 10 tile range. The max is 12 tiles, but I want to make sure I capture close snakes on the other side of the hole too. So, the idea for the Find_eggs is when I have done x amount of holes in a loop, to scan for all possible eggs, then restart. I will remove the return and see what it does.
Fourth, the finddist -1 is because that is what shows when you don't find and item. Again, not knowing tons of logic, I was not aware I could do two terms.
Fifth. I appreciate the array examples! I had not thought of using namespace. i am rather new to playing with that, and don't know it's full power, purpose, and scope. The documentation on helps so much. I find it funny that you named the sub find closest, because I am working on a sub for the same purpose with the same name. That's about all the resemblance though.
I can use parts of what you provided to help me get something that fits the script needs. Since snakes move so fast, so much in that area, i have found it is far faster and more reliable to find a hole, find the closest snake to that hole, then go to char. So, I have been told I will need to do and ABS calc of the snake #finddist and the hole #finddist to come up with the closest one to each other, but still within 12 tiles of ME.
Sixth. From what I can understand of the sample code, your example finds all holes within x distance of me, but I can't tell where it finds the closest. In my experience with #findid, it appears to start furthest out and go clockwise around the character. So, if I read it right, it will give me the first holes around me, but not an ordered list of closest to furthest. Closest to furthest will do several things for the script to speed it up. By the time it cycles through all the holes, all the snakes should be done, and when it re-est I won't have to worry about trying to re-charm a snake that is already charmed.
Things I don't understand from the first script sample, Find_closest.
1) if %0<>2 ; I have no clue to this.
2) set !SearchFor %1
set !finddist %2 + 1 ; initialize distance of closest item found
set !SearchDist %2 ;I think %1 is the type item, and % 2 it the desired distance?
3) I'm completely missing the point of the second code snippet.
This is the code I have been working on for the last couple days. Your seems so much cleaner.
set %Search1 2 ; first search within 4 tiles
set %Search2 3
set %search3 5
;and so on
set %closestHoleID N/A
for %i 1 %holeCount
{
set %holeX %holeX . %i
set %closest ( %holeD - %snakeloc )
}
;still working on this part