eott / preciouspreciouscaffeine

[Done] A mod for the game Factorio, adding coffee products and technology to the game
2 stars 3 forks source link

[crash] Player need to be alive for caffeine level ticks to work? #3

Closed StefanPrintezis closed 7 years ago

StefanPrintezis commented 7 years ago

Think I missed a player.alive of valid check. Server crashed when someone placed a waterfill below them which would cause them to die. Server kept crashing on updatecaffeinelevel when the player joined.

dmon82 commented 7 years ago

Looks like it, game drops to main menu when the player dies in singleplayer mode too.

Error while running event on_tick (ID 0) No character. stack traceback: PreciousPreciousCaffeine/control.lua:55: in function 'updateCaffeineLevel' PreciousPreciousCaffeine/control.lua:45: in function <PreciousPreciousCaffeine/control.lua:28>

dmon82 commented 7 years ago

Reading the API, the call at line 55 to character_crafting_speed_modifier, it says when called on a LuaPlayer it requires an instance of LuaEntity in the character variable, but I guess it's NIL at the time of calling.

Would it be enough to check for that in the onTick function loop at 44?

for i, player in pairs(game.players) do if (player.character ~= nil) then updateCaffeineLevel(player) end end

(apparently I also fail at markup)

I haven't really worked with Lua before, and have only glanced over Factorio modding. This stops it crashing in singleplayer when I die, and I assume concurrency is not an issue. But I'm hesitant to put it up as a pull request, because I'm unexperienced with the modding API.

eott commented 7 years ago

Thanks for the feedback. Yeah, it should be sufficient to add a simple check if the player character exists. I wanted to fix this and the multiplayer issues as well and put it into a patch, but unfortunately don't have anyone to test multiplayer with, so I never got around to do that. So maybe I'll do a patch just for this bug instead.

dmon82 commented 7 years ago

I can definitely spare some time to get on a multiplayer game with you, no guarantee if I can get more people to hop on at any one time but I can try. I looked through things but looking into how to make mods multiplayer-proof seemed rather time extensive. It was really funny when I searched for "water" to get like water wells or pumpjacks to generate water, and then found this coffee mod, loving it :) :+1:

Feel free to add me on Steam (jackd23, my avatar right now is a blue "AI" picture from Rocket League... a little goof a friend of mine came up with), or a Discord link maybe, I don't use much other than that, and IRC. I'm in GMT+1 but my day schedule is "flexible".

eott commented 7 years ago

Should be fixed now.