Sorry that I didn't mention the extra brace. I knew that, but deleted it from the version I was working with. I found it using the ScriptUO editor and it's Tools/Syntax_Error_Check menu option.
Great catch on the toggle nature of
ignoreitem.
Ignoreitem:You could also have 3
ignoreitem lists:
1) unreachable things
2) holes already targeted
3) snakes already charmed
Anything unreachable (so likely only holes that spawn in bad locations) use no list:
ignoreitem #findidSnakes could be found that are out of your line of sight, I would just add those to the 'snake' list, because these are mobile and could come back into range later, so when you have no more snakes found, you would want these to be come valid found objects.
Anything that is a hole that you targeted:
ignoreitem %target2 hole
Anything that is a snake charmed:
ignoreitem %target1 snake
Then you replace the hole ignoreitem reset with:
ignoreitem reset hole
And replace the snake ignoreitem reset with:
ignoreitem reset snake
You would never do a
ignoreitem reset without the list parameter in the script.
#FINDDIST:In plothole you have a test after
finditem:
if #finddist > 3 ||
#finddist = -1
I understand '
#finddist > 3', but what does '
#finddist = -1' mean?
Was this supposed to be if the hole was no found ('
#findkind = -1') in the 2nd half of the test?
Variable Naming Convention:Name variables clearly to make it obvious what is preserved:
%target1 should be
%targetsnake%target2 should be
%targethole
Some logical flow questions:sub findhole
The end of this issues a recursive
gosub findhole
sub findsnake
1) The end of this issues a
gosub findhole - why?
2) If there is a need to reset to begin searching again, wouldn't you want to run through the logic of 'mainloop'?
sub eggs_in_one_basket
There is a
finditem and a
for loop, but the first time through the loop it returns. Why have the
for loop?
There is findhole and findsnake subs with nested
finditem statements. Suppose you want to find the closest thing, consider this structure:
sub FindClosest
if %0 <> 2
return #false
namespace push
namespace local FindClosest_
namespace clear
set !SearchFor %1
set !finddist %2 + 1 ; initialize distance of closest item found
set !SearchDist %2
finditem !SearchFor G_ , !SearchDist
if #findcnt > 0
{
for #findindex 1 #findcnt
{
if #finddist < !finddist
{
set !findid #findid
set !findx #findx
set !findy #findy
set !findz #findz
set !finddist #finddist
}
}
}
if !finddist = !SearchDist
{
set #result #false ; nothing was found
}
else
{
set #result !findid
}
namespace pop
return #result
Now you use it:
gosub FindClosest %type %distance
if ! #result
{
; nothing was found in range or wrong number of parameters passed
}
if #result
{
; found a valid thing to use
; you could go back into the namespace if you need more than just the #findid:
namespace copy find* from local FindClosest_
; now !findid !findx, !findy, !findz and !finddist are copied into your regular namespace
}
That eliminates having a lot of finditems in each of those find* subs and returns the closest one. Much cleaner.
Here is the example on how findsnake tag_snake would change to use that:
sub findsnake
gosub FindClosest %snakes 10
if ! #result
{
; nothing was found in range or wrong number of parameters passed
ignoreitem reset
move 710 714
gosub findhole ; I still don't understand this statement in the original, but leaving the logic untouched
}
else
{
; found a valid thing to use
set !findid #RESULT ; we only need the ID from the snake, so no need to grab the other variables
; to follow the example in searching for the hole, you would do the namespace copy logic...
}
return
;---------------
sub tag_snake
set %target1 !findid
ignoreitem !findid
return