Page 1 of 1

_WPL:reverse(); does not work

Posted: Fri May 28, 2010 12:51 pm
by filipsworks

Code: Select all

<!-- #  1 --><waypoint x="31630" z="2716"> __WPL:reverse(); </waypoint>
...
<!-- #350 --><waypoint x="27923" z="6789"> __WPL:reverse(); </waypoint>
When #350 is reached then bot try to go to (as he say) #1 point with coords x=0 y=0 (#1 is 31630;2716). Dunno what's wrong here...

Re: _WPL:reverse(); does not work

Posted: Fri May 28, 2010 6:20 pm
by Administrator
Yeah, looks like this became a problem with one of the recent changes to the waypoint system. I had to re-order the advance, getNextWaypoint, and waypoint action code to correct another bug, but it looks like it only caused this.

Well, it's been "fixed" to a somewhat workable way. Be aware, though, that reversing like that will cause problems and there is nothing that can be done about it. The problem is that you can't guarantee that you will start at any specific waypoint or be going a specific direction. Basically, what I'm saying is, you reverse() on waypoint #1. What happens if you start nearest to waypoint #1? You'd reverse, heading to the last waypoint, which reverses to the first waypoint, which... you get the point.

Instead, you might consider checking if you're going the right direction first.

Code: Select all

if( __WPL.Direction == WPT_BACKWARD ) then
  __WPL:reverse(); -- Start going forward again.
end
There's another function, __WPL:setDirection(dir) (accepts WPT_FORWARD or WPT_BACKWARD), but this might need to be fixed as well (basically, to just do the above code).

Re: _WPL:reverse(); does not work

Posted: Sun May 30, 2010 2:15 am
by filipsworks
Administrator wrote: There's another function, __WPL:setDirection(dir) (accepts WPT_FORWARD or WPT_BACKWARD), but this might need to be fixed as well (basically, to just do the above code).
Using __WPL:setDirection(WPT_BACKWARD); gives the same (no)result:/

Now only solution what I saw is use of that VBS:

Code: Select all

 Const ForReading = 1
 Const ForWriting = 2

 Dim arrLines()
 i = 0

 Set objFSO = CreateObject("Scripting.FileSystemObject")
 Set objFile = objFSO.OpenTextFile("c:\micromacro\scripts\rom\waypoints\pełnaścierzkadopliku.xml", ForReading)

 Do Until objFile.AtEndOfStream
     Redim Preserve arrLines(i)
     arrLines(i) = objFile.ReadLine
     i = i + 1
 Loop

 objFile.Close

 Set objFile = objFSO.OpenTextFile("c:\micromacro\scripts\rom\waypoints\pełnaścierzkadopliku_reversed.xml", ForWriting)

 For i = Ubound(arrLines) to LBound(arrLines) Step -1
     objFile.WriteLine arrLines(i)
 Next

 objFile.Close
correct of xml declaration and general <waypoints> </waypoints> tags and use of loadPaths("path_reversed.xml"); function :/

None of WP-reverse functions from Wiki works:/

Re: _WPL:reverse(); does not work

Posted: Sun May 30, 2010 5:24 am
by Administrator
Try using __WPL:reverse() just for testing. Does that work or not (excluding the problem I mentioned before)?

Re: _WPL:reverse(); does not work

Posted: Tue Jun 01, 2010 2:39 am
by Wundervice
i actually came looking for an answer to this. I can verify that the standard methods of reversing DO NOT work. Im not even sure the workaround does (but i haven't confirmed).

Re: _WPL:reverse(); does not work

Posted: Wed Jun 02, 2010 3:30 am
by jurafxp
i am using this:

Code: Select all

<!-- #  1 --><waypoint x="123" z="123">__WPL:reverse();__WPL:setWaypointIndex(2); </waypoint>
...
<!-- # 69 --><waypoint x="456" z="456">__WPL:reverse();__WPL:setWaypointIndex(68); </waypoint>

Re: _WPL:reverse(); does not work

Posted: Thu Jun 03, 2010 1:12 am
by filipsworks
jurafxp wrote:i am using this:

Code: Select all

<!-- #  1 --><waypoint x="123" z="123">__WPL:reverse();__WPL:setWaypointIndex(2); </waypoint>
...
<!-- # 69 --><waypoint x="456" z="456">__WPL:reverse();__WPL:setWaypointIndex(68); </waypoint>
Good I see? __WPL:reverse(); have to be called 2 times (#69 call __WPL:reverse(); > then go to 68 (next will be 69) > __WPL:reverse(); ?)

What exacly is "__WPL:setWaypointIndex(68);"?

Re: _WPL:reverse(); does not work

Posted: Thu Jun 03, 2010 2:23 am
by rock5
I had a look at _WPL:Reverse() and found what the problem was. It had checks when changing to backwards but no checks when changing to forward. I just applied the same checks for both directions and now it works perfectly.

To manually fix it while waiting for dev implements this fix, change the following.

In waypointlist.lua find the reverse function;

Code: Select all

-- Reverse your current direction
function CWaypointList:reverse()
	if( self.Direction == WPT_FORWARD ) then
		self.Direction = WPT_BACKWARD;
		self.CurrentWaypoint = self.CurrentWaypoint - 1;
		if( self.CurrentWaypoint <= 0 ) then
			self.CurrentWaypoint = #self.Waypoints - 1;
		end
	else
		self.Direction = WPT_FORWARD;
	end;
end
Change to match the following. Note you are only adding the 4 lines above the last 2 "end"s.

Code: Select all

-- Reverse your current direction
function CWaypointList:reverse()
	if( self.Direction == WPT_FORWARD ) then
		self.Direction = WPT_BACKWARD;
		self.CurrentWaypoint = self.CurrentWaypoint - 1;
		if( self.CurrentWaypoint <= 0 ) then
			self.CurrentWaypoint = #self.Waypoints - 1;
		end
	else
		self.Direction = WPT_FORWARD;
		self.CurrentWaypoint = self.CurrentWaypoint + 1;
		if( self.CurrentWaypoint >= #self.Waypoints ) then
			self.CurrentWaypoint = 2;
		end
	end;
end

Re: _WPL:reverse(); does not work

Posted: Thu Jun 03, 2010 4:33 am
by Administrator
Thanks. I'll include it with the next commit.

I still think setDirection() might be broken and need to be changed to this:

Code: Select all

function CWaypointList:setDirection(wpt)
  if( wpt ~= WPT_FORWARD and wpt ~= WPT_BACKWARD ) then
    return; -- do nothing, invalid input
  end

  if( wpt ~= self.Direction ) then
    self:reverse();
  end
end
Is someone able to help me test this?

Re: _WPL:reverse(); does not work

Posted: Thu Jun 03, 2010 5:48 am
by rock5
Administrator wrote:Is someone able to help me test this?
I can confirm that setdirection wasn't working.

With my fix to reverse and your fix to setdirection they are both working correctly.

Although I could never see the point of reverse. Setdirection should be all you need.

Re: _WPL:reverse(); does not work

Posted: Sun Jun 06, 2010 7:57 am
by rock5
I noticed you still haven't committed these changes. In the mean time I've been thinking. We have them back-to-front.

setdirection uses reverse but I think it should be reverse that uses setdirection. Makes more sense to me. So I changed them around and tested them, the code is below. They both work correctly. If you agree with me, feel free to add to next commit. Otherwise use the fixes above.

Code: Select all

-- Sets the "direction" (forward/backward) to travel
function CWaypointList:setDirection(wpt)
	-- Ignore invalid types
	if( wpt ~= WPT_FORWARD and wpt ~= WPT_BACKWARD ) then
		return;
	end;

	if( wpt ~= self.Direction ) then
		self.Direction = wpt
		if( wpt == WPT_BACKWARD ) then
			self.CurrentWaypoint = self.CurrentWaypoint - 1;
			if( self.CurrentWaypoint <= 0 ) then
				self.CurrentWaypoint = #self.Waypoints - 1;
			end
		else
			self.CurrentWaypoint = self.CurrentWaypoint + 1;
			if( self.CurrentWaypoint >= #self.Waypoints ) then
				self.CurrentWaypoint = 2;
			end
		end;
	end
end

-- Reverse your current direction
function CWaypointList:reverse()
	if( self.Direction == WPT_FORWARD ) then
		self:setDirection(WPT_BACKWARD);
	else
		self:setDirection(WPT_FORWARD);
	end;
end

Re: _WPL:reverse(); does not work

Posted: Tue Jun 08, 2010 12:35 am
by filipsworks
rock5 wrote:I noticed you still haven't committed these changes. In the mean time I've been thinking. We have them back-to-front.

setdirection uses reverse but I think it should be reverse that uses setdirection. Makes more sense to me. So I changed them around and tested them, the code is below. They both work correctly. If you agree with me, feel free to add to next commit. Otherwise use the fixes above.
Confirmed - Works