Page 2 of 4
Re: [MOD 0.12.x] VehicleSnap 1.0.2
Posted: Sat May 28, 2016 3:42 pm
by lxl
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.
Re: [MOD 0.12.x] VehicleSnap 1.0.2
Posted: Sat May 28, 2016 4:27 pm
by Zaflis
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.
Re: [MOD 0.12.x] VehicleSnap 1.0.2
Posted: Sat May 28, 2016 8:41 pm
by lxl
Wow. 45 min until fixed.
Re: [MOD 0.13.x] VehicleSnap 1.1.0
Posted: Sun Jul 10, 2016 6:28 pm
by Zaflis
Mod is now updated for 0.13. All features seem working same as before. (Installing mods will disable Steam achievements for your save.)
Re: [MOD 0.13.x] VehicleSnap 1.1.0
Posted: Fri Jul 15, 2016 2:03 pm
by Jürgen Erhard
Upload to mod portal, please.
Re: [MOD 0.13.x] VehicleSnap 1.1.0
Posted: Fri Jul 15, 2016 9:54 pm
by Zaflis
Jürgen Erhard wrote:Upload to mod portal, please.
Done. (
https://mods.factorio.com/mods/Zaflis/VehicleSnap )
Re: [MOD 0.13.x] VehicleSnap 1.1.0
Posted: Sun Jul 17, 2016 12:59 pm
by Jürgen Erhard
Just saw you post, I've already noticed it and installed it last night.
Thanks!
Re: [MOD 0.13.x] VehicleSnap 1.1.0
Posted: Sat Sep 03, 2016 8:36 am
by TheTom
Any chance for a .14 update?
Re: [MOD 0.13.x] VehicleSnap 1.1.0
Posted: Sat Sep 03, 2016 9:29 am
by Zaflis
TheTom wrote:Any chance for a .14 update?
Can try in a moment. 0.13 to 0.14 should be just about changing the number to 14 in json file.
Updated and seems to work still.
Re: [MOD 0.13.x] VehicleSnap 1.1.0
Posted: Wed Sep 07, 2016 7:47 am
by TheTom
Zaflis wrote:TheTom wrote:Any chance for a .14 update?
Can try in a moment. 0.13 to 0.14 should be just about changing the number to 14 in json file.
Updated and seems to work still.
Great. Any reason not to upload it to the mod portal? (Not nagging, really asking - the versioning is NOT properly thought out there, sadly).
Re: [MOD 0.13.x] VehicleSnap 1.1.0
Posted: Wed Sep 07, 2016 8:31 am
by Zaflis
TheTom 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).
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 ... /downloads
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
Posted: Wed Nov 23, 2016 6:49 am
by Zaflis
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.
Re: [MOD 0.14] VehicleSnap
Posted: Wed Nov 23, 2016 11:40 am
by Optera
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.
Re: [MOD 0.14] VehicleSnap
Posted: Fri Dec 16, 2016 1:40 pm
by Arumba
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:
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.
But.. I really like this mod. So I want to re-enable it. How can we fix it?
Re: [MOD 0.14] VehicleSnap
Posted: Fri Dec 16, 2016 2:36 pm
by Zaflis
I wouldn't have known that kind of details. If i understand him correctly, you would need to change
Code: Select all
local lastorientation = {}
local player_ticks = {}
local tick = 2
to
Code: Select all
lastorientation = {}
player_ticks = {}
tick = 2
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
Code: Select all
vehiclesnap_lastorientation = {}
vehiclesnap_player_ticks = {}
vehiclesnap_tick = 2
and then rename all the uses for those variable names too.
I could upload this change to see if it helps. (edit: Deleted)
Re: [MOD 0.14] VehicleSnap
Posted: Fri Dec 16, 2016 3:09 pm
by daniel34
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.
What he means is using the
global.x variables (as in
global.lastorientation) to store your data.
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
Posted: Fri Dec 16, 2016 3:41 pm
by Zaflis
I'm getting error on line 11: attempt to perform arithmetic on field 'tick' (a nil value)
They are initialized in the beginning like
Code: Select all
global.lastorientation = {}
global.player_ticks = {}
global.tick = 2
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.
Re: [MOD 0.14] VehicleSnap
Posted: Fri Dec 16, 2016 3:55 pm
by daniel34
Using the following control.lua (adapted from the current mod portal version) it worked for me:
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)
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.
Re: [MOD 0.14] VehicleSnap
Posted: Fri Dec 16, 2016 4:27 pm
by Zaflis
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
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)
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
Re: [MOD 0.14] VehicleSnap
Posted: Fri Dec 16, 2016 5:28 pm
by Zaflis
Current start of the script is now:
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)
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.