Nuclear Cars

by MrDayne

Nuclear cars with gears, nitro and an advanced steering control for high speed turning.

Content
1 year, 10 months ago
1.1
213
Transportation

b Crash when player starts/joins game

1 year, 9 months ago

I get a crash when starting a new or resuming an existing game:

Error while running event Nuclear_Car::on_player_joined_game (ID 45)
__Nuclear_Car__/control.lua:141: attempt to index field 'entity' (a nil value)


function enter_vehicle(event)
  ...
  if event.entity.type == "car" then
    mycar = event.entity
    orientation = mycar.orientation
    ready = true
  else
    ready = false
  end
end
script.on_event(defines.events.on_player_driving_changed_state, enter_vehicle)
script.on_event(defines.events.on_player_joined_game, enter_vehicle)

The error in line 141:

if event.entity.type == "car" then

occurs when the function is run on account of on_player_joined_game, which will never have event.entity (on_player_driving_changed_state may or may not have it). So the fix is to check whether event.entity exists before trying to do something with it:

if event.entity and event.entity.type == "car" then

New response