[MOD 0.17] VehicleSnap
Re: [MOD 0.12.x] VehicleSnap 1.0.2
Hello,
When I enter the train i get the following msg.
Error while running the event handler: __VehicleSnap__/control.lua:13: Callable only on car entity type.
(reproduced w/o mods on a new map)
But I truly do love your mod. Now i only crash into my base in corners and not on straight tracks.
When I enter the train i get the following msg.
Error while running the event handler: __VehicleSnap__/control.lua:13: Callable only on car entity type.
(reproduced w/o mods on a new map)
But I truly do love your mod. Now i only crash into my base in corners and not on straight tracks.
Re: [MOD 0.12.x] VehicleSnap 1.0.2
Wow, and it so happened i didn't use trains in my most recent world I have a fix (1.0.3) coming up shortly, i have to test the fixed version. Because of this i can't have unique speed tests per car type anymore (unless i sacrifice tiny bit of performance for more string comparisons), so car's value will lower to that of tanks; 0.1 down from 0.14.
update: I still couldn't get the car stuck to wall in tests while it starts snapping a little earlier.
And 1.0.3 is released.
update: I still couldn't get the car stuck to wall in tests while it starts snapping a little earlier.
And 1.0.3 is released.
Re: [MOD 0.12.x] VehicleSnap 1.0.2
Wow. 45 min until fixed.
Re: [MOD 0.13.x] VehicleSnap 1.1.0
Mod is now updated for 0.13. All features seem working same as before. (Installing mods will disable Steam achievements for your save.)
-
- Filter Inserter
- Posts: 299
- Joined: Sun Jun 12, 2016 11:29 pm
- Contact:
Re: [MOD 0.13.x] VehicleSnap 1.1.0
Upload to mod portal, please.
Re: [MOD 0.13.x] VehicleSnap 1.1.0
Done. ( https://mods.factorio.com/mods/Zaflis/VehicleSnap )Jürgen Erhard wrote:Upload to mod portal, please.
-
- Filter Inserter
- Posts: 299
- Joined: Sun Jun 12, 2016 11:29 pm
- Contact:
Re: [MOD 0.13.x] VehicleSnap 1.1.0
Just saw you post, I've already noticed it and installed it last night. Thanks!
Re: [MOD 0.13.x] VehicleSnap 1.1.0
Any chance for a .14 update?
Re: [MOD 0.13.x] VehicleSnap 1.1.0
Can try in a moment. 0.13 to 0.14 should be just about changing the number to 14 in json file.TheTom wrote:Any chance for a .14 update?
Updated and seems to work still.
Re: [MOD 0.13.x] VehicleSnap 1.1.0
Great. Any reason not to upload it to the mod portal? (Not nagging, really asking - the versioning is NOT properly thought out there, sadly).Zaflis wrote:Can try in a moment. 0.13 to 0.14 should be just about changing the number to 14 in json file.TheTom wrote:Any chance for a .14 update?
Updated and seems to work still.
Re: [MOD 0.13.x] VehicleSnap 1.1.0
Sorry, i've not paid attention and even still 0.14 is an experimental version It's updated https://mods.factorio.com/mods/Zaflis/V ... /downloadsTheTom wrote:Zaflis wrote:Great. Any reason not to upload it to the mod portal? (Not nagging, really asking - the versioning is NOT properly thought out there, sadly).
I should have propably added this forum link (homepage) in the json too, just didn't want to update the mod for that little change.
Re: [MOD 0.14.x] VehicleSnap 1.14.0
New version is out again, hope it still works for you as it did on my tests. I've seen this mod use around 0.02ms of tick time per frame, which was about same as most mods, but some mods managed to get off with less too. So i figured, what processing do i really need to do when nobody is even in a car? LUA is weird, the commands that were used were nothing significant. A for loop from 1 to 1 for example shouldn't be expected to do much, but it does... something does.
So after fixing things, the mod's idle time has gone down to 0.003ms and 0.025 while driving. I simply made the mod wait for 40 ticks if no cars were found during the check. That should be plenty of time to account for player entering a vehicle and gaining speed to start snapping again.
Another fix is for variables, they are now unique per player. I would imagine it may have caused odd behavior in multiplayer when there were at least 2 people driving at the same time.
So after fixing things, the mod's idle time has gone down to 0.003ms and 0.025 while driving. I simply made the mod wait for 40 ticks if no cars were found during the check. That should be plenty of time to account for player entering a vehicle and gaining speed to start snapping again.
Another fix is for variables, they are now unique per player. I would imagine it may have caused odd behavior in multiplayer when there were at least 2 people driving at the same time.
Re: [MOD 0.14] VehicleSnap
You could also register your tick function only when a player enters a car. and unregister once he leaves.
My mods use this method to have no drain unless an entity is built.
My mods use this method to have no drain unless an entity is built.
My Mods: mods.factorio.com
Re: [MOD 0.14] VehicleSnap
Any chance we can get this mod updated to be MP friendly? We were using it last night in a ~60 player game and finally identified that this mod was the issue causing our desyncs. I looked at the discussion tab on the modportal and found this from Rseding91:
But.. I really like this mod. So I want to re-enable it. How can we fix it?You need to store your mods data variables in the global table so they're saved/loaded with the game.
Right now because they're stored as local variables they get reset every time a new player joins the game or every time the game is saved, exited, and loaded.
This results in desyncs in MP and breaks the replay in single player.
Re: [MOD 0.14] VehicleSnap
I wouldn't have known that kind of details. If i understand him correctly, you would need to change
to
But if they are named like that as global variables, what is the scope for those variable names? Will other scripts see them? If the scope interferes with other mods or main Factorio itself, they could be
and then rename all the uses for those variable names too.
I could upload this change to see if it helps. (edit: Deleted)
Code: Select all
local lastorientation = {}
local player_ticks = {}
local tick = 2
Code: Select all
lastorientation = {}
player_ticks = {}
tick = 2
Code: Select all
vehiclesnap_lastorientation = {}
vehiclesnap_player_ticks = {}
vehiclesnap_tick = 2
I could upload this change to see if it helps. (edit: Deleted)
Last edited by Zaflis on Fri Dec 16, 2016 3:46 pm, edited 1 time in total.
Re: [MOD 0.14] VehicleSnap
What he means is using the global.x variables (as in global.lastorientation) to store your data.Rseding91 wrote:You need to store your mods data variables in the global table so they're saved/loaded with the game.
Right now because they're stored as local variables they get reset every time a new player joins the game or every time the game is saved, exited, and loaded.
See here: https://wiki.factorio.com/Lua/Data_Lifecycle#global
You never need to prefix your variables (like your vehiclesnap_) because each mod runs in a separate instance and can't collide with other mods. (except in data.lua, but you usually won't have that issue there if you properly introduce your variables and the probability of someone else using the same variables is very low)
Re: [MOD 0.14] VehicleSnap
I'm getting error on line 11: attempt to perform arithmetic on field 'tick' (a nil value)
They are initialized in the beginning like
About those one, i would propably need to check if those are null before assigning default value? But that's related to save sync, and the error above doesn't make sense to me yet.
Code: Select all
global.tick = global.tick - 1
Code: Select all
global.lastorientation = {}
global.player_ticks = {}
global.tick = 2
Re: [MOD 0.14] VehicleSnap
Using the following control.lua (adapted from the current mod portal version) it worked for me:
I tested it only in singleplayer, no guarantees for multiplayer. I'm not sure if Rseding91's advice actually avoids the desync (EDIT: it probably does, as globals are stored with the savegame before a new player downloads it).
local vehiclesnap_amount doesn't need a global as it's always constant.
Code: Select all
local vehiclesnap_amount = 16.0
-- snap amount is the amount of different angles car can drive on,
-- (360 / vehiclesnap_amount) is the difference between 2 axis
-- car will slowly turn towards such angle axis
global.lastorientation = {}
global.player_ticks = {}
global.tick = 2
script.on_event(defines.events.on_tick, function(event)
global.tick = global.tick - 1
if global.tick == 0 then
-- If noone is in vehicles, take longer delay to do this whole check
global.tick = 40
for index, player in pairs(game.players) do
if player.vehicle and player.vehicle.valid then
local v = player.vehicle.type
if v == "car" or v == "tank" then
global.tick = 2
if player.vehicle.speed > 0.1 then
local o = player.vehicle.orientation
if global.lastorientation[index] == nil then global.lastorientation[index] = 0 end
if global.player_ticks[index] == nil then global.player_ticks[index] = 0 end
if math.abs(o - global.lastorientation[index]) < 0.001 then
if global.player_ticks[index] > 1 then
local o2 = math.floor(o * vehiclesnap_amount + 0.5) / vehiclesnap_amount
o = (o * 4.0 + o2) * 0.2
player.vehicle.orientation = o
else
global.player_ticks[index] = global.player_ticks[index] + 1
end
else
global.player_ticks[index] = 0
end
global.lastorientation[index] = o;
end
end
end
end
end
end)
local vehiclesnap_amount doesn't need a global as it's always constant.
Re: [MOD 0.14] VehicleSnap
That seems to only work when you make a new map. But when loading a map with older version of the mod it errors back to main menu.
I was trying to add this aswell (based on https://wiki.factorio.com/Lua/Data_Lifecycle#global the on_load should be correct for this) to make new mod's compatibility for old saves
But it's giving error aswell that doesn't get logged, but i guess workaround would be to save the map with mod disabled.
edit: That was wrong, should've been
I was trying to add this aswell (based on https://wiki.factorio.com/Lua/Data_Lifecycle#global the on_load should be correct for this) to make new mod's compatibility for old saves
Code: Select all
script.on_event(script.on_load, function(event)
if global.lastorientation == nil then global.lastorientation = {} end
if global.player_ticks == nil then global.player_ticks = {} end
if global.tick == nil then global.tick = 2 end
end)
edit: That was wrong, should've been
Code: Select all
script.on_load(function()
Last edited by Zaflis on Fri Dec 16, 2016 5:31 pm, edited 1 time in total.
Re: [MOD 0.14] VehicleSnap
Current start of the script is now:
Unless you convince me to put first 3 lines inside on_init, i'd consider it solved It worked in all test cases i could think of, but obviously i cannot test multiplayer sync.
Also the mod is using the game.players directly. Say your player index is 4 and you're driving a car. If player index 3 leaves the game, you will now be index 3, no? If that happens you might see your snap variable reset.
Code: Select all
global.lastorientation = {}
global.player_ticks = {}
global.tick = 2
script.on_configuration_changed(function(data)
if data.mod_changes == nil then return end
if global.lastorientation == nil then global.lastorientation = {} end
if global.player_ticks == nil then global.player_ticks = {} end
if global.tick == nil then global.tick = 2 end
end)
Also the mod is using the game.players directly. Say your player index is 4 and you're driving a car. If player index 3 leaves the game, you will now be index 3, no? If that happens you might see your snap variable reset.
- Attachments
-
- VehicleSnap_1.14.21.zip
- (1.26 KiB) Downloaded 215 times