UOS: How to compare to a list element?

Share your guides, how-tos, FAQs, and so forth. This is not for support -- post questions in General Discussion.
Post Reply
Vampire337
Posts: 13
Location: Cincinnati, Ohio

UOS: How to compare to a list element?

Post by Vampire337 » September 15th, 2020, 5:11 pm

I'm attempting to store location coordinates in a list (works fine) so that I can write an if statement to determine where I want my character to move (and eventually, move there and maybe do actions).

I started by creating the list and putting some values in it:

Code: Select all

if not listexists 'XYCoords'
  createlist 'XYCoords'
endif
clearlist 'XYCoords'
pushlist 'XYCoords' '1200'
pushlist 'XYCoords' '2400'

Code: Select all

if XYCoords[0] = 1200 and XYCoords[1] = 2400
  //Do something
  clearlist 'XYCoords'
  pushlist 'XYCoords' '1000'
  pushlist 'XYCoords' '2400'
elseif XYCoords[0] = 1000 and XYCoords[1] = 2400
  //Do something else
endif
So far I get told that "Comand XYCoords[0] doesn't exist." So it's reading this as a command and not a compare statement. I have tried apostrophes around the numbers, double equals, swapping the numbers and the list reference, creative maneuvers with the list command, etc. Anyone have some insight on either how I make the syntax match what it's looking to see, or is there a better way to store numeric values for processing later in the script?

Dredd
Posts: 12

Re: UOS: How to compare to a list element?

Post by Dredd » September 15th, 2020, 7:12 pm

So, I’m not sure if this will help, but I use this:

Code: Select all

 if @x ‘alias’ > ‘self’ and @y ‘alias’ > ‘self’
 walk ‘southeast’
 //repeat for all directions
Alias would be a target, mob or vendor or whatever. You could replace the alias with an actual tile location as well.

I then create a stuck timer, something like:

Code: Select all

 If timer ‘stuck’ > whatever time
 //do something like:
 //move in a direction to get closer
 //cancel target
 //etc

Vampire337
Posts: 13
Location: Cincinnati, Ohio

Re: UOS: How to compare to a list element?

Post by Vampire337 » September 15th, 2020, 8:16 pm

Thanks for the reply.

Using a 2-element list to store location works fine as long as I'm comparing x or y to the list elements. The problem seems to be that I want to use the list to moderate the script, and it seems UOSteam doesn't allow for the list reference to be on the left of the comparison operator.

I am able to walk to the desired position using the following:

Code: Select all

while x != XYCoords[0] or y != XYCoords[1]
  if x < XYCoords[0]
    run 'east'
  endif
  if x > XYCoords[0]
    run 'west'
  endif
  if y < XYCoords[1]
    run 'south'
  endif
  if y > XYCoords[1]
    run 'north'
  endif
  pause 100
endwhile
That code actually lives in a separate macro, and I call this macro from the main macro, so I can make one line playmacro call instead of repeating the same 15 lines over and over. What I'm looking to do here is use the "desired" location to tell my if/else logic what to evaluate. The flowchart logic is something like this:

Code: Select all

If desired location is 1
  recall to location 1
  unload resources
  set desired location to 2
elseif desired position is 2
  run to location 2
  playmacro 'gathering resources'
  set desired location to 3
elseif desired location is 3
  run to...
endif
I don't want to rely on the current x/y because there may be actions to be taken before moving. But unless I can find a way to put the list reference on the left of that equals, I may hafta restructure it.

Vampire337
Posts: 13
Location: Cincinnati, Ohio

Re: UOS: How to compare to a list element?

Post by Vampire337 » September 17th, 2020, 1:56 pm

Just to close the loop on this, I did end up giving in and using my x and y coords. It seems that UOS lacks any method for storing "variables" because it doesn't allow you to compare the list element or alias to something else. I was able to structure my script such that the desired actions at each x/y coord could be executed and then the character walks to the next location.

Tbh I'm probably pushing the limits by using separate macros as function calls. But I am still a little curious if one could write to a book and use that for storage variables.

Xionu
Posts: 90

Re: UOS: How to compare to a list element?

Post by Xionu » September 17th, 2020, 3:58 pm

Not sure if this helps you any, but here is a quick script I wrote that changes the XYCoords based on your player's X/Y. Test in in Luna if you'd like. Loop on or off, on will run in circles, off will run to the next spot only.

Code: Select all

//Start ontop of or directly north or south of the Luna moongate
@createlist 'XYCoords'
@clearlist 'XYCoords'
//Set Coords to SE Corner
if x 'self' == 1015
  if y < 538 and y >= 499
    sysmsg 'Spot 1'
    @pushlist 'XYCoords' '1015'
    @pushlist 'XYCoords' '538'
  endif
endif
//Set Coords to SW Corner
if @x <= 1015 and @x > 961
  if @y == 538
    sysmsg 'Spot 2'
    @pushlist 'XYCoords' '961'
    @pushlist 'XYCoords' '538'
  endif
endif
//Set Coords to NW Corner
if @x == 961
  if @y <= 538 and @y > 499
    sysmsg 'Spot 3'
    @pushlist 'XYCoords' '961'
    @pushlist 'XYCoords' '499'
  endif
endif
//Set Coords to NE Corner
if @x >= 961 and @x < 1015
  if @y == 499
    sysmsg 'Spot 4'
    @pushlist 'XYCoords' '1015'
    @pushlist 'XYCoords' '499'
  endif
endif
//Running
while @x != XYCoords[0] or @y != XYCoords[1]
  while @x < XYCoords[0]
    run 'east'
    pause 75
  endwhile
  while @x > XYCoords[0]
    run 'west'
    pause 75
  endwhile
  while @y < XYCoords[1]
    run 'south'
    pause 75
  endwhile
  while @y > XYCoords[1]
    run 'north'
    pause 75
  endwhile
  pause 100
endwhile

As far as storing variables by using books, I don't see anything in the documentation to do this.. You may try using

Code: Select all

sysmsg 'text'
@injournal 'text' 'system'
@clearjournal
Vampire337 likes this.
Top

Vampire337
Posts: 13
Location: Cincinnati, Ohio

Re: UOS: How to compare to a list element?

Post by Vampire337 » September 17th, 2020, 4:14 pm

Xionu wrote:
September 17th, 2020, 3:58 pm
Not sure if this helps you any, but here is a quick script I wrote that changes the XYCoords based on your player's X/Y. Test in in Luna if you'd like. Loop on or off, on will run in circles, off will run to the next spot only.
That's a neat little proof-of-concept script, and it closely resembles the setup I've built. I have a 'function' that does the second part (run, step by step, toward the XYCoords list) and I use clearlist, pushlist, pushlist prior to calling it from my main script. Biggest add is that I included non-cardinal directions. Need to write some "good" unstuck logic in it now. The taming training macros out there are decent, but eventually they give up.
Xionu wrote:
September 17th, 2020, 3:58 pm
As far as storing variables by using books, I don't see anything in the documentation to do this..
I also saw nothing in the "all-inclusive" documentation describing writing to books, but I also see a recent post in this forum where there exists the capability of copying books, so perhaps reading and disseminating the data from the book might be useful for storing script values.

Such 4th wall breaking tho! Imagine writing nonsense into a book that stored information for a script that was driving you in real life... :shock: 8-)

Xionu
Posts: 90

Re: UOS: How to compare to a list element?

Post by Xionu » September 18th, 2020, 6:46 pm

Vampire337 wrote:
September 17th, 2020, 4:14 pm
Xionu wrote:
September 17th, 2020, 3:58 pm
Not sure if this helps you any, but here is a quick script I wrote that changes the XYCoords based on your player's X/Y. Test in in Luna if you'd like. Loop on or off, on will run in circles, off will run to the next spot only.
That's a neat little proof-of-concept script, and it closely resembles the setup I've built. I have a 'function' that does the second part (run, step by step, toward the XYCoords list) and I use clearlist, pushlist, pushlist prior to calling it from my main script. Biggest add is that I included non-cardinal directions. Need to write some "good" unstuck logic in it now. The taming training macros out there are decent, but eventually they give up.
Xionu wrote:
September 17th, 2020, 3:58 pm
As far as storing variables by using books, I don't see anything in the documentation to do this..
I also saw nothing in the "all-inclusive" documentation describing writing to books, but I also see a recent post in this forum where there exists the capability of copying books, so perhaps reading and disseminating the data from the book might be useful for storing script values.

Such 4th wall breaking tho! Imagine writing nonsense into a book that stored information for a script that was driving you in real life... :shock: 8-)
I believe the book copy macro you're referring to uses inscription in order to copy the books (not the actual text inside the book).
Something that you may find useful is using a runebook with named runes. These runes can act as variables, while still static, they are variables none the less.

You can drop the rune from the book and use something like:

Code: Select all

@findtype 0x1f14 'any' 'backpack'
if property 'RuneName' 'found'
  sysmsg 'Do something'
endif
Or you can keep the rune in the runebook and use something like:

Code: Select all

promptalias 'runebook'
useobject 'runebook'
waitforgump 0x554b87f3 1500
if @ingump 0x554b87f3 'RuneName'
  sysmsg 'Do something'
endif
You can go as far as dropping and renaming them with a macro if you'd like, this sort of makes them non-static, but in the macro they will only be static.

Code: Select all

promptalias 'Rune'
createlist 'RuneName'
pushlist 'RuneName' 1
pushlist 'RuneName' 2
for 0 to RuneName
  useobject 'Rune'
  promptmsg RuneName[]
  pause 600
endfor

Vampire337
Posts: 13
Location: Cincinnati, Ohio

Re: UOS: How to compare to a list element?

Post by Vampire337 » September 18th, 2020, 8:04 pm

You are correct; when I went back and looked it was using inscription to offload the text copy to the server. I like the rune-as-variables concept, as it should prove more user-friendly than naming animals.

Thanks for the tips!

Post Reply