I can't figure out how to change that in a function inside control.lua. The player.vehicle reference doesn't have the car's property (rotation speed) and I don't know how to get a reference to the car, and not it's parent vehicle.
Any help would be appreciated.
player.vehicle.rotation_speed not working.
- Deadlock989
- Smart Inserter
- Posts: 2529
- Joined: Fri Nov 06, 2015 7:41 pm
Re: player.vehicle.rotation_speed not working.
LuaEntity.rotation_speed doesn't exist. LuaEntityPrototype.rotation_speed is read only and can only be defined in the data stage. You can't change vehicle rotation speeds at runtime.
I don't know what you mean by a "the car and not the car's parent vehicle". Cars are vehicles.
I don't know what you mean by a "the car and not the car's parent vehicle". Cars are vehicles.
Re: player.vehicle.rotation_speed not working.
Cars have all the variables from vehicle, since they inherit from it, but cars have some variables of their own that vehicles don't, like rotation speed. When I get player.vehicle I can modify all vehicle variables, but not car variables.
- Deadlock989
- Smart Inserter
- Posts: 2529
- Joined: Fri Nov 06, 2015 7:41 pm
Re: player.vehicle.rotation_speed not working.
Oh, I see. Some things are read-only and fixed, defined in the data stage as a prototype property (which is why rotation_speed is a property of LuaEntityPrototype and not LuaEntity). You can't change car rotation speed at runtime.
Re: player.vehicle.rotation_speed not working.
You’re mixing up data stage and control stage. In data stage, you create prototypes using the wiki docs. In control stage you do runtime scripting using the api docs at https://lua-api.factorio.com/latest.
Maybe https://lua-api.factorio.com/latest/Data-Lifecycle.html will help clear up your confusion.
Maybe https://lua-api.factorio.com/latest/Data-Lifecycle.html will help clear up your confusion.
My mods
Content: Lunar Landings | Freight Forwarding | Spidertron Patrols | Spidertron Enhancements | Power Overload
QoL: Factory Search | Module Inserter Simplified | Wire Shortcuts X | Ghost Warnings
Content: Lunar Landings | Freight Forwarding | Spidertron Patrols | Spidertron Enhancements | Power Overload
QoL: Factory Search | Module Inserter Simplified | Wire Shortcuts X | Ghost Warnings
Re: player.vehicle.rotation_speed not working.
You must distinguish between the car entity and the car prototype. The entity is what you place on the ground, enter, and drive around with. The prototype defines the default values which all entities of the same type and name will share.xan186 wrote: Fri Dec 23, 2022 11:27 am Cars have all the variables from vehicle, since they inherit from it, but cars have some variables of their own that vehicles don't, like rotation speed. When I get player.vehicle I can modify all vehicle variables, but not car variables.
As Deadlock989 already explained, prototypes are defined during the data stage. You can change the prototypes in whatever way you like from data.lua, data-updates.lua, and data-final-fixes.lua. Once the data stage has finished, the prototypes can't be changed anymore.
The control stage comes after the data stage. Here, you only deal with entities, which are real-game manifestations of a prototype. While you can't change the prototype at this point, you can still read some of its properties:
Code: Select all
local player = game.player
local my_car = player.surface.create_entity{name = "car", position = player.position}
local prototype = my_car.prototype
Code: Select all
if my_car.health < my_car.prototype.max_health then
game.print("Damaged!")
end
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!
Re: player.vehicle.rotation_speed not working.
Ok, so I guess the only way is to manually correct rotation on every tick, and limit it more and more the faster the car is going. Do you think this could be doable??
Re: player.vehicle.rotation_speed not working.
In Autodrive, we have straight paths between two waypoints. If a vehicle is driving from A to B, we determine the current position of the vehicle, calculate the angle between vehicle position and B, and set vehicle.orientation accordingly. Something like this should work for you as well, you just have to factor in vehicle.speed somehow.xan186 wrote: Fri Dec 23, 2022 2:51 pm Ok, so I guess the only way is to manually correct rotation on every tick, and limit it more and more the faster the car is going. Do you think this could be doable??

A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!