I've struggled with some strange behavior while trying to upgrade one of my mods for Factorio 1.1. The mod allows to "lock" an entity by setting the properties active, minable, and operable to false. I've tried to load an old save from 0.18 where two entities were locked and on was unlocked.
To change the lock status, I use this code:
Code: Select all
local v_data = v_id and global.GCKI_vehicles[v_id]
local v = v_data and v_data.entity
if v and v.valid then
-- Unlock vehicle on account of locker
if v_data.locker and v_data.locker == player then
log("Unlocking")
v.active = true
v.operable = true
-- If setting from Unminable Vehicles is enabled, no vehicle may be mined
v.minable = true
remove_vehicle_locker(v_id, player)
-- Don't unlock a vehicle that has been locked by somebody else!
elseif v_data.locker and v_data.locker ~= player then
-- Lock vehicle on account of player
else
log("Locking")
v.active = false
v.operable = false
v.minable = false
add_vehicle_locker(v_id, player)
end
I've suspected that perhaps something would be wrong with the saved game, so I started a new game in 0.18 where I reproduced the issue. The attachment contains the WIP version of my mod and the saved game from 0.18. (If Alt-mode is on, locked vehicles will be marked with an icon and can't be entered. Use the keys from the quickbar with the tank to unlock it. You now will be able to open its inventory and enter it, but you can't drive. Enter "/gvv" on the chat console if you want to get the GUI of "Global variable viewer".)