player.vehicle.rotation_speed not working.

Place to get help with not working mods / modding interface.
Post Reply
MrDayne
Burner Inserter
Burner Inserter
Posts: 9
Joined: Fri Dec 23, 2022 9:56 am
Contact:

player.vehicle.rotation_speed not working.

Post by MrDayne »

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.

User avatar
Deadlock989
Smart Inserter
Smart Inserter
Posts: 2528
Joined: Fri Nov 06, 2015 7:41 pm

Re: player.vehicle.rotation_speed not working.

Post by Deadlock989 »

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.
Image

MrDayne
Burner Inserter
Burner Inserter
Posts: 9
Joined: Fri Dec 23, 2022 9:56 am
Contact:

Re: player.vehicle.rotation_speed not working.

Post by MrDayne »

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.

User avatar
Deadlock989
Smart Inserter
Smart Inserter
Posts: 2528
Joined: Fri Nov 06, 2015 7:41 pm

Re: player.vehicle.rotation_speed not working.

Post by Deadlock989 »

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.
Image

Xorimuth
Filter Inserter
Filter Inserter
Posts: 627
Joined: Sat Mar 02, 2019 9:39 pm
Contact:

Re: player.vehicle.rotation_speed not working.

Post by Xorimuth »

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.
My mods
Content: Freight Forwarding | Spidertron Patrols | Spidertron Enhancements | Power Overload
QoL: Factory Search | Remote Configuration | Module Inserter Simplified | Wire Shortcuts X | Ghost Warnings

Pi-C
Smart Inserter
Smart Inserter
Posts: 1656
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: player.vehicle.rotation_speed not working.

Post by Pi-C »

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.
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.

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
The variable prototype will then contain a LuaEntityPrototype from which you can read the default values. For example, if you'd want to find out whether your car is damaged, you could run this on every tick:

Code: Select all

if my_car.health < my_car.prototype.max_health then
    game.print("Damaged!")
end
(This is just a stupid example! In a real mod, you'd listen to the on_entity_damaged event.)
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

MrDayne
Burner Inserter
Burner Inserter
Posts: 9
Joined: Fri Dec 23, 2022 9:56 am
Contact:

Re: player.vehicle.rotation_speed not working.

Post by MrDayne »

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

Pi-C
Smart Inserter
Smart Inserter
Posts: 1656
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: player.vehicle.rotation_speed not working.

Post by Pi-C »

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??
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. :-)
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

Post Reply

Return to “Modding help”