Page 1 of 1

LuaEntity.stop_spider() has no effect

Posted: Wed Sep 21, 2022 6:04 pm
by Pi-C
Expected behavior: If a spider-vehicle is in motion, it will immediately stop once it has received the stop_spider() command.

Real behavior: For this code

Code: Select all

AD.show("vehicle.autopilot_destination", vehicle.autopilot_destination)
AD.show("vehicle.autopilot_destinations", vehicle.autopilot_destinations)

AD.writeDebug("Trying to stop spider!")
vehicle.stop_spider()

AD.show("vehicle.autopilot_destination", vehicle.autopilot_destination)
AD.show("vehicle.autopilot_destinations", vehicle.autopilot_destinations)
I get the following output:

Code: Select all

20189.718 Script @__autodrive__/libs/debugging.lua:167: vehicle.autopilot_destination: {
  x = -11.5,
  y = -17.5
}
20189.718 Script @__autodrive__/libs/debugging.lua:167: vehicle.autopilot_destinations: {
  {
    x = -11.5,
    y = -17.5
  },
  {
    x = -11.5,
    y = -18.5
  },
  {
    x = -12.42578125,
    y = -19.06640625
  }
}
20189.718 Script @__autodrive__/libs/debugging.lua:167: Trying to stop spider!
20189.718 Script @__autodrive__/libs/debugging.lua:167: vehicle.autopilot_destination: {
  x = -11.5,
  y = -17.5
}
20189.718 Script @__autodrive__/libs/debugging.lua:167: vehicle.autopilot_destinations: {
  {
    x = -11.5,
    y = -17.5
  },
  {
    x = -11.5,
    y = -18.5
  },
  {
    x = -12.42578125,
    y = -19.06640625
  }
}
Neither vehicle.autopilot_destination nor vehicle.autopilot_destinations have been affected by vehicle.stop_spider(), and the vehicle happily continued on its path.

The only way to make sure the vehicle stops seems to be this:

Code: Select all

for w, waypoint in pairs(vehicle.autopilot_destinations) do
	vehicle.autopilot_destination = nil
end
This isn't very intuitive. Shouldn't stop_spider() automatically clear autopilot_destination/autopilot_destinations?

Re: LuaEntity.stop_spider() has no effect

Posted: Wed Sep 21, 2022 7:41 pm
by Klonan
Pi-C wrote:
Wed Sep 21, 2022 6:04 pm
Expected behavior: If a spider-vehicle is in motion, it will immediately stop once it has received the stop_spider() command.

This isn't very intuitive. Shouldn't stop_spider() automatically clear autopilot_destination/autopilot_destinations?
The function is only calling the internal resetSpeed() on the spider, the usecase being after reaching the waypoints to stop all extra momentum/movement

Since autopilot destinations are easily cleared with script, and clearing was never mentioned in the mod requests or the changelog, I will class this as not a bug

Re: LuaEntity.stop_spider() has no effect

Posted: Wed Sep 21, 2022 8:40 pm
by Pi-C
Thanks for your reply!
Klonan wrote:
Wed Sep 21, 2022 7:41 pm
The function is only calling the internal resetSpeed() on the spider, the usecase being after reaching the waypoints to stop all extra momentum/movement
Too bad that isn't documented! :-)
Since autopilot destinations are easily cleared with script, and clearing was never mentioned in the mod requests or the changelog, I will class this as not a bug
They are easily cleared per script once you know how to do that, which isn't obvious:

Code: Select all

autopilot_destination :: MapPosition? [Read/Write] 
Destination of this spidertron's autopilot, if any.

autopilot_destinations :: array[MapPosition] [Read] 
The queued destination positions of spidertron's autopilot.

stop_spider() 
Stops the given SpiderVehicle.
I've added this to the documentation improvement requests.