ScriptUO

Official ScriptUO EasyUO Scripts => Script Debug => Topic started by: Grandewd on September 27, 2014, 02:34:36 PM

Title: Regarding event pathfind and while loop... question.
Post by: Grandewd on September 27, 2014, 02:34:36 PM

 :-[
Here's the simple code I'm using:
Code: [Select]
event pathfind 2149 1415 -23
while #charposx <> 2149 && #charposy <> 1415
   {
    wait 5
    event pathfind 2149 1415 -23
   }

I know Cheffe said in the doc's:
Quote
Please note that your script will keep on executing while the character is moving.
but in my example the script jumps out of the while loop before it reaches the coords. 
This is in one of my houses, and nothing is keeping it from reaching the destination tile. 

How/why is it leaving the while loop before the condition is met?  ???
Title: Re: Regarding event pathfind and while loop... question.
Post by: The Ghost on September 27, 2014, 03:03:25 PM
Try this maybe it will work better.and add step as u need then.
step_m1:
move 2149 1415 0 5s
     if ! ( #charposx = 2149 && #charposy = 1415 )
    {
     goto step_m1
    }
 else
 {
 goto step_m2
 }
step_m2
Title: Re: Regarding event pathfind and while loop... question.
Post by: manwinc on September 28, 2014, 02:19:11 AM
Its because of the Logic


while #charposx <> 2149 && #charposy <> 1415 ; <- Logic

So once either your #Charposx = 2149 or your #Charposy = 1415 it will break from the while because you are telling it to only move while BOTH of them aren't what you want. Change the && to an ||


While #Charposx <> 2149 || #Charposy <> 1415

That will force it to continue to perform the code until it satisifies both Conditions.
Title: Re: Regarding event pathfind and while loop... question.
Post by: gimlet on September 28, 2014, 07:36:57 AM
Its because of the Logic


while #charposx <> 2149 && #charposy <> 1415 ; <- Logic

So once either your #Charposx = 2149 or your #Charposy = 1415 it will break from the while because you are telling it to only move while BOTH of them aren't what you want. Change the && to an ||


While #Charposx <> 2149 || #Charposy <> 1415

That will force it to continue to perform the code until it satisifies both Conditions.


Spot on!
Title: Re: Regarding event pathfind and while loop... question.
Post by: Grandewd on September 28, 2014, 10:42:30 PM
Its because of the Logic:  while #charposx <> 2149 && #charposy <> 1415 ; <- Logic
So once either your #Charposx = 2149 or your #Charposy = 1415 it will break from the while because you are telling it to only move while BOTH of them aren't what you want. ....
Which is why pathfind is part of the loop, so it WILL keep trying until BOTH conditions are met.

That will force it to continue to perform the code until it satisifies both Conditions.
Exactly!   I mean isn't that what the AND (&&) is saying.... Isn't that the condition - that BOTH have to be true ? What else would AND be for?

Forgive me for being obtuse, but I'm trying to see why my logic is off...
Title: Re: Regarding event pathfind and while loop... question.
Post by: manwinc on September 29, 2014, 03:20:49 AM


Okay, lets look at it if you are standing on a certain spot.

Lets say you are standing on x = 2149 and y = 1414

Because your #Charposx = 2149 the first statement (#charposx <> 2149) is False. && Requires that both statements have to be true in order for it to run the code.

while #charposx <> 2149 && #charposy <> 1415 ; <- Logic
{

}
Title: Re: Regarding event pathfind and while loop... question.
Post by: Grandewd on September 29, 2014, 11:39:14 AM
I believe I see the logic now, Manwinc...  Thanks much for taking the time to explain...  :)
Title: Re: Regarding event pathfind and while loop... question.
Post by: The Ghost on October 30, 2014, 09:15:12 PM
To keep question under same topic I will post in here
 The idea is to use this to move a few title it I get damage or have a enemies near by.  The problem I'm having is that the doesn't get out of the loop.  Not sure what I miss or did wrong here.

Code: [Select]
set %PosX #charposx - 2
set %PosY #charposy + 6
gosub healthcheck
halt
sub healthcheck
  namespace push
    namespace local HC
set %endX #charposx
set %endY #charposy
 repeat
 wait 10
   event pathfind %PosX %PosY
   until %endX = %PosX && %endY = %PosY
namespace pop
return
Title: Re: Regarding event pathfind and while loop... question.
Post by: Cstalker on October 31, 2014, 10:23:01 AM
try this

Code: [Select]
Repeat
gosub healthcheck
Until Cstalker = Awesome
halt
sub healthcheck
  namespace push
  namespace local HC
  set %PosX #charposx - 2
  set %PosY #charposy + 6
 repeat
       wait 10
       event pathfind %PosX %PosY
 until #charposX = %PosX && #charposY = %PosY
 namespace pop
return