Author Topic: Regarding event pathfind and while loop... question.  (Read 3862 times)

0 Members and 1 Guest are viewing this topic.

Offline GrandewdTopic starter

  • Full Member
  • ***
  • Posts: 239
  • Activity:
    0%
  • Reputation Power: 3
  • Grandewd has no influence.
  • Respect: +24
  • Referrals: 0
    • View Profile
Regarding event pathfind and while loop... question.
« on: September 27, 2014, 02:34:36 PM »
0

 :-[
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?  ???

Offline The Ghost

  • Elite
  • *
  • *
  • Posts: 1917
  • Activity:
    0%
  • Reputation Power: 25
  • The Ghost is on the verge of being accepted.The Ghost is on the verge of being accepted.The Ghost is on the verge of being accepted.The Ghost is on the verge of being accepted.The Ghost is on the verge of being accepted.
  • Respect: +245
  • Referrals: 0
    • View Profile
Re: Regarding event pathfind and while loop... question.
« Reply #1 on: September 27, 2014, 03:03:25 PM »
0
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

Offline manwinc

  • Elite
  • *
  • *
  • Posts: 2556
  • Activity:
    0%
  • Reputation Power: 32
  • manwinc is a rising star!manwinc is a rising star!manwinc is a rising star!manwinc is a rising star!manwinc is a rising star!manwinc is a rising star!
  • Gender: Male
  • "The Devs Hard at Work"
  • Respect: +123
  • Referrals: 1
    • View Profile
Re: Regarding event pathfind and while loop... question.
« Reply #2 on: September 28, 2014, 02:19:11 AM »
0
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.
Monkeys and Typewriters!

" Oh I know, We'll make a Boss Encounter that requires 3 keys per player to enter, Then we'll make it not a closed instance so you never know if you are going to pop into a fresh room or a boss that has 1% Health left with 20 dudes smashing its face in, wasting your time and effort"

Offline gimlet

  • Very Super Secret
  • Global Moderator
  • *
  • *
  • Posts: 6207
  • Activity:
    3.2%
  • Reputation Power: 71
  • gimlet is awe-inspiring!gimlet is awe-inspiring!gimlet is awe-inspiring!gimlet is awe-inspiring!gimlet is awe-inspiring!gimlet is awe-inspiring!gimlet is awe-inspiring!gimlet is awe-inspiring!gimlet is awe-inspiring!gimlet is awe-inspiring!gimlet is awe-inspiring!gimlet is awe-inspiring!
  • Gender: Male
  • Respect: +274
  • Referrals: 3
    • View Profile
Re: Regarding event pathfind and while loop... question.
« Reply #3 on: September 28, 2014, 07:36:57 AM »
0
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!

Offline GrandewdTopic starter

  • Full Member
  • ***
  • Posts: 239
  • Activity:
    0%
  • Reputation Power: 3
  • Grandewd has no influence.
  • Respect: +24
  • Referrals: 0
    • View Profile
Re: Regarding event pathfind and while loop... question.
« Reply #4 on: September 28, 2014, 10:42:30 PM »
0
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...

Offline manwinc

  • Elite
  • *
  • *
  • Posts: 2556
  • Activity:
    0%
  • Reputation Power: 32
  • manwinc is a rising star!manwinc is a rising star!manwinc is a rising star!manwinc is a rising star!manwinc is a rising star!manwinc is a rising star!
  • Gender: Male
  • "The Devs Hard at Work"
  • Respect: +123
  • Referrals: 1
    • View Profile
Re: Regarding event pathfind and while loop... question.
« Reply #5 on: September 29, 2014, 03:20:49 AM »
0


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
{

}
Monkeys and Typewriters!

" Oh I know, We'll make a Boss Encounter that requires 3 keys per player to enter, Then we'll make it not a closed instance so you never know if you are going to pop into a fresh room or a boss that has 1% Health left with 20 dudes smashing its face in, wasting your time and effort"

Offline GrandewdTopic starter

  • Full Member
  • ***
  • Posts: 239
  • Activity:
    0%
  • Reputation Power: 3
  • Grandewd has no influence.
  • Respect: +24
  • Referrals: 0
    • View Profile
Re: Regarding event pathfind and while loop... question.
« Reply #6 on: September 29, 2014, 11:39:14 AM »
0
I believe I see the logic now, Manwinc...  Thanks much for taking the time to explain...  :)

Offline The Ghost

  • Elite
  • *
  • *
  • Posts: 1917
  • Activity:
    0%
  • Reputation Power: 25
  • The Ghost is on the verge of being accepted.The Ghost is on the verge of being accepted.The Ghost is on the verge of being accepted.The Ghost is on the verge of being accepted.The Ghost is on the verge of being accepted.
  • Respect: +245
  • Referrals: 0
    • View Profile
Re: Regarding event pathfind and while loop... question.
« Reply #7 on: October 30, 2014, 09:15:12 PM »
0
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

Offline Cstalker

  • Google Slut
  • ScriptUO Beta Tester
  • ***
  • *
  • Posts: 179
  • Activity:
    0%
  • Reputation Power: 0
  • Cstalker has no influence.
  • Gender: Male
  • Respect: +9
  • Referrals: 0
    • View Profile
Re: Regarding event pathfind and while loop... question.
« Reply #8 on: October 31, 2014, 10:23:01 AM »
0
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

Tags: