justarandomgeek / vscode-factoriomod-debug

Factorio Mod Tool Kit
Other
121 stars 26 forks source link

factorio\plugin.lua:80: attempt to call a nil value (field 'on_pre_process_file') every time when I load my control.lua file #127

Closed Icicubes closed 5 months ago

Icicubes commented 5 months ago

Every time when I load my control.lua file it sets of this error in VSC with this plugin. An error occurred in the plugin, please report it to the plugin author. Please check the details in the output or log.

...omgeek.factoriomod-debug\sumneko-3rd\factorio\plugin.lua:80: attempt to call a nil value (field 'on_pre_process_file') stack traceback: ...omgeek.factoriomod-debug\sumneko-3rd\factorio\plugin.lua:80: in function <...omgeek.factoriomod-debug\sumneko-3rd\factorio\plugin.lua:61> [C]: in function 'xpcall' script\plugin.lua:49: in function 'plugin.dispatch' script\files.lua:195: in upvalue 'pluginOnSetText' script\files.lua:266: in function 'files.setText' script\workspace\loading.lua:105: in function <script\workspace\loading.lua:81>

I couldn't figure out how to attach my control.lua file to this bug report so here it is (removed comments at the end):

global.BSCpPcurrentStreakEntities = {} global.BSCpPnextcurrentStreakEntities = {} global.BSCpPTickOfLastEvent = {} global.BSCpPLastBlueprint = {} global.BSCpPnextLastBlueprint = {} global.BSCpPDivisor = {} global.BSCpPnextDivisor = {} global.BSCpPinterruptStreak = {} global.BSCpPresult = {} global.BSCpPfunctioncalls = {}--debug script.on_event(defines.events.on_built_entity, function(event) ---@diagnostic disable-next-line: undefined-field local ThisPlayer = game.players[event.player_index] local TimingWindow = ThisPlayer.mod_settings["Streak-timing-window-in-ticks"].value local displayInvalidStackInfo = ThisPlayer.mod_settings["invalid-stack-info"].value local displayIfended = ThisPlayer.mod_settings["display-streak-if-ended"].value local ThisTick = event.tick ---@diagnostic disable-next-line: undefined-field local es = event.stack if not global.BSCpPcurrentStreakEntities[ThisPlayer.name] then--initialize values for variables global.BSCpPcurrentStreakEntities[ThisPlayer.name]=1 global.BSCpPLastBlueprint[ThisPlayer.name]=-1 global.BSCpPTickOfLastEvent[ThisPlayer.name]=0 global.BSCpPDivisor[ThisPlayer.name]=1 global.BSCpPnextcurrentStreakEntities[ThisPlayer.name]=0 global.BSCpPfunctioncalls[ThisPlayer.name]=0--debug global.BSCpPinterruptStreak[ThisPlayer.name]=false --global.BSCpPcurrentStreak = nil --for migration needed? no I dont think its needed. end if es.is_blueprint then--für jede gemachte ghost Entity in dem Tick wenn es ein BP ist: if not displayIfended and ThisTick == global.BSCpPTickOfLastEvent[ThisPlayer.name] then --(-1). rufe die funktion nur einmal pro Tick auf return end --0. DEBUG wie oft wurde diese funktion aufgerufen? global.BSCpPfunctioncalls[ThisPlayer.name]=global.BSCpPfunctioncalls[ThisPlayer.name]+1--debug game.print("function calls:"..(global.BSCpPfunctioncalls[ThisPlayer.name]))--debug --1. Identifiziere den aktuellen Blueprint. local CurrentBlueprint = es.item_number --2. Finde dadurch heraus, ob es noch derselbe Blueprint wa[h]r oder nicht [falsch]. if global.BSCpPLastBlueprint[ThisPlayer.name]==-1 then global.BSCpPLastBlueprint[ThisPlayer.name]=CurrentBlueprint end local changedBlueprint = global.BSCpPLastBlueprint[ThisPlayer.name] ~= CurrentBlueprint --2.b) findet gerade eine Streak statt? wahr oder falsch local StreakActive = ((ThisTick-(global.BSCpPTickOfLastEvent[ThisPlayer.name]))<TimingWindow) if not StreakActive then global.BSCpPDivisor[ThisPlayer.name] = es.get_blueprint_entity_count() end --4.b) --3. Obwohl sich der Blueprint geändert hat muss global divisor gleich bleiben bis zum nächsten onTick wo nach der interuption diese globale variable übernommen wird. if changedBlueprint and StreakActive and displayIfended then global.BSCpPnextDivisor[ThisPlayer.name] = es.get_blueprint_entity_count() game.print((global.BSCpPnextDivisor[ThisPlayer.name]).." changed nextdivisior")--debug end --4. Wenn es noch derselbe Blueprint ist, erhöhe die aktuellen streak entities um 1 --4.b) fix the off by 1 error that occurs during changing blueprint? deactivate bp check? --if global.BSCpPcurrentStreakEntities[ThisPlayer.name]==0 then global.BSCpPcurrentStreakEntities[ThisPlayer.name]=1 end if not changedBlueprint then global.BSCpPcurrentStreakEntities[ThisPlayer.name] = global.BSCpPcurrentStreakEntities[ThisPlayer.name]+1 else global.BSCpPnextcurrentStreakEntities[ThisPlayer.name] = global.BSCpPnextcurrentStreakEntities[ThisPlayer.name]+1 end --5. erhalte die berechnete Streak für die current streak Entities / entity anzahl im Blueprint local result = math.floor((global.BSCpPcurrentStreakEntities[ThisPlayer.name]) / (global.BSCpPDivisor[ThisPlayer.name])) if ((global.BSCpPcurrentStreakEntities[ThisPlayer.name])>1) and not displayIfended and not changedBlueprint and StreakActive then ThisPlayer.print((global.BSCpPcurrentStreakEntities[ThisPlayer.name])) ThisPlayer.create_local_flying_text{text=(global.BSCpPcurrentStreakEntities[ThisPlayer.name]), create_at_cursor=true} end if displayIfended then global.BSCpPresult[ThisPlayer.name] = result end

        --(6. wenn nicht timeout oder changedBlueprint und nicht displayIfended setze streak entities 1)
        if not displayIfended and ((ThisTick-global.BSCpPTickOfLastEvent[ThisPlayer.name])>TimingWindow or changedBlueprint) then global.BSCpPcurrentStreakEntities[ThisPlayer.name]=1 end
        --7. wenn Blueprint sich verändert hat und displayIfended und ergebnis>1
        if displayIfended and changedBlueprint and (result>1) and not ((ThisTick-global.BSCpPTickOfLastEvent[ThisPlayer.name])>TimingWindow) then --testing result>1 nicht notwendig wird sowieso gefiltert?nein. and global.BSCpPcurrentStreakEntities[ThisPlayer.name]>2
            --8. Streak wurde unterbrochen? bei displayIfended
            global.BSCpPinterruptStreak[ThisPlayer.name] = true
            --9. verhindere das das ergebnis 2 mal gedruckt wird. setze last Tick >
            global.BSCpPTickOfLastEvent[ThisPlayer.name] = -TimingWindow
            --global.BSCpPTickOfLastEvent[ThisPlayer.name]=(ThisTick-(TimingWindow-1))
            --ThisPlayer.print((ThisTick-(TimingWindow-1)).."correct tick")--debug
            --ThisPlayer.print((global.BSCpPTickOfLastEvent[ThisPlayer.name]).."correct tick?")--debug
            ThisPlayer.print("You changed the Blueprint got triggered.")--debug
            ThisPlayer.print((global.BSCpPDivisor[ThisPlayer.name]))--debug
            ThisPlayer.print("⟶from "..(global.BSCpPLastBlueprint[ThisPlayer.name]).." to "..(CurrentBlueprint))--debug
            --ThisPlayer.print(displayIfended)--debug
            --ThisPlayer.print((event.tick).."Tick of change in LastEvent")--debug
            --ThisPlayer.print((global.BSCpPTickOfLastEvent[ThisPlayer.name]).."current Last Event Tick should be:"..(event.tick-global.BSCpPTickOfLastEvent[ThisPlayer.name]))--debug
        else
            --10. Wenn dieser event tick ungleich Tick of last event ist und es nicht abgebrochen wurde(ich setze tickoflastevent -timing window wenn abgebrochen wurde)
            --wird FÜR jede entity entity aufgerufen also in selben function call noch aktualisiert
            if (global.BSCpPTickOfLastEvent[ThisPlayer.name]~=ThisTick) and not ((global.BSCpPTickOfLastEvent[ThisPlayer.name])==-TimingWindow) then
                global.BSCpPTickOfLastEvent[ThisPlayer.name]=ThisTick
                ThisPlayer.print("renewed global tick of last event")--debug
            end
        end
        --
        --11. Wenn sich der Blueprint verändert hat, set the new current Blueprint to the Last Blueprint.
        --INFO nur wenn es die letzte Entity aus dem Blueprint ist... kann aber auch nicht die letzte entity sein. das heißt am anfang des nächsten onTicks
        --ansonsten wird fälschlicherweise für die restlichen platzierten Geister der noch aktuelle streak entities wert erhöht!
        if changedBlueprint or not StreakActive then global.BSCpPnextLastBlueprint[ThisPlayer.name]=CurrentBlueprint end
    else --wenn kein BP ist und ungültig ist und gezeigt werden soll, drucke Info Nachricht:
        if not es.valid_for_read and displayInvalidStackInfo then
            ThisPlayer.print("LuaItemStack was not valid for read. Try to put it in your inventory. Books are not supported as well as editor instant building. Only copy and paste (=)and Blueprints in your inventory when fully placed:( And its not save load stable but thats too edge case. idc. You can turn off this message in the mod options.")
        end
end

end,--every on built entity ghost gets counted together if they were from the same Blueprint ---@diagnostic disable-next-line: missing-fields {{filter="ghost"}}) script.on_event(defines.events.ontick, function(event) for , p in pairs(game.players) do local ThisPlayer = p local displayIfended = ThisPlayer.mod_settings["display-streak-if-ended"].value local TimingWindow = ThisPlayer.mod_settings["Streak-timing-window-in-ticks"].value if global.BSCpPcurrentStreakEntities[ThisPlayer.name] and global.BSCpPDivisor[ThisPlayer.name] then if ((global.BSCpPcurrentStreakEntities[ThisPlayer.name]) % (global.BSCpPDivisor[ThisPlayer.name]))~=0 then ThisPlayer.print("off by "..((global.BSCpPcurrentStreakEntities[ThisPlayer.name]) % (global.BSCpPDivisor[ThisPlayer.name]))) global.BSCpPcurrentStreakEntities[ThisPlayer.name]=global.BSCpPcurrentStreakEntities[ThisPlayer.name]+((global.BSCpPcurrentStreakEntities[ThisPlayer.name])%(global.BSCpPDivisor[ThisPlayer.name])) end end--debug if global.BSCpPnextLastBlueprint[ThisPlayer.name] then --es muss am anfang onTick aufgerufen werden global.BSCpPLastBlueprint[ThisPlayer.name] = global.BSCpPnextLastBlueprint[ThisPlayer.name] global.BSCpPnextLastBlueprint[ThisPlayer.name]=nil end if global.BSCpPcurrentStreakEntities[ThisPlayer.name] and global.BSCpPDivisor[ThisPlayer.name] then --gibts beide? local grossgenug = (math.floor(global.BSCpPcurrentStreakEntities[ThisPlayer.name] / global.BSCpPDivisor[ThisPlayer.name]))>1--=Ist hoch genug? if global.BSCpPTickOfLastEvent[ThisPlayer.name] and displayIfended then --ThisPlayer.print((global.BSCpPTickOfLastEvent[ThisPlayer.name]).." wrong tick? yes it was") --ThisPlayer.print((event.tick-global.BSCpPTickOfLastEvent[ThisPlayer.name]).." Tick calculated = 240(=Timing Window) to fire.") local Zeitabgelaufen = ((event.tick - global.BSCpPTickOfLastEvent[ThisPlayer.name])==TimingWindow) local unterbrochen = global.BSCpPinterruptStreak[ThisPlayer.name] --game.print(Zeitabgelaufen)--debug --game.print(unterbrochen)--debug if Zeitabgelaufen or unterbrochen then -- muss "and grossgenug" sein? oder ist es sogar falsch gewesen --ThisPlayer.print("That were "..(math.floor(global.BSCpPcurrentStreakEntities[ThisPlayer.name] / global.BSCpPDivisor[ThisPlayer.name])).." fully placed Blueprints in a row.") if unterbrochen then global.BSCpPinterruptStreak[ThisPlayer.name] = false if grossgenug then ThisPlayer.print("That were "..(global.BSCpPresult[ThisPlayer.name]).." fully placed Blueprints in a row.") end game.print("interrupted [item=blueprint]")--debug global.BSCpPresult[ThisPlayer.name] = 0 --cleaner if global.BSCpPTickOfLastEvent[ThisPlayer.name]==-TimingWindow then global.BSCpPTickOfLastEvent[ThisPlayer.name]=event.tick-1 end --0 or -1? probably -1 ??? global.BSCpPDivisor[ThisPlayer.name] = global.BSCpPnextDivisor[ThisPlayer.name] global.BSCpPnextDivisor[ThisPlayer.name] = 0 --cleaner global.BSCpPcurrentStreakEntities[ThisPlayer.name] = global.BSCpPnextcurrentStreakEntities[ThisPlayer.name] global.BSCpPnextcurrentStreakEntities[ThisPlayer.name] = 0 ThisPlayer.print((global.BSCpPcurrentStreakEntities[ThisPlayer.name]).." nextStreakEntities as currentStreakEntities")--debug ThisPlayer.print((global.BSCpPDivisor[ThisPlayer.name]).." nextDivisor as divisor")--debug elseif Zeitabgelaufen then if grossgenug then ThisPlayer.print("That were "..(math.floor(global.BSCpPcurrentStreakEntities[ThisPlayer.name] / global.BSCpPDivisor[ThisPlayer.name])).." fully placed Blueprints in a row.") end ThisPlayer.print("Timeout got triggered.")--debug ThisPlayer.print((global.BSCpPresult[ThisPlayer.name])) global.BSCpPcurrentStreakEntities[ThisPlayer.name]=1 end end end end end end)--checks every tick for every player in the game: if displayIfended [on]: outputs Streak count as console message after the timeout or interruption.

justarandomgeek commented 5 months ago

sounds like the plugin was not fully installed for some reason - perhaps re-run the version selector to reinstall it?

Icicubes commented 5 months ago

I didn't tried that yet but now I have and that didn't work. still the same.

JanSharp commented 5 months ago

That is an extra peculiar error, because the only way for that to happen is if the plugin.lua file is from a different (newer) version then the factorio-plugin/util.lua file... and I can't think of a way for that to happen through any "normal" means. Best I got is to make sure to double check your settings, in particular if you have the Lua.runtime.plugin configured (theoretically it should not be set at all). Aside from that there should be a path defined inside ofLua.workspace.userThirdParty which points to a "generated" location which also contains the plugin, and the Lua.workspace.checkThirdParty setting which should be set to ApplyInMemory. If the settings don't look like this at all then you can try removing any lua language server specific settings and effectively have a clean slate before running the version picker.

Icicubes commented 5 months ago

I have deleted in my Factorio mod folder the two files launch.json and settings.json in the .vscode folder and that fixed it. { // Use IntelliSense to learn about possible attributes. // Hover to view descriptions of existing attributes. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "type": "factoriomod", "request": "launch", "name": "Factorio Mod Debug" }, { "type": "factoriomod", "request": "launch", "name": "Factorio Mod Debug (Settings & Data)", "hookSettings": true, "hookData": true }, { "type": "factoriomod", "request": "launch", "name": "Factorio Mod Debug (Profile)", "hookMode": "profile" } ] } {
"factorio.versions": [ { "name": "Steam", "factorioPath": "C:\Program Files (x86)\Steam\steamapps\common\Factorio\bin\x64\factorio.exe" } ], "Lua.workspace.library": [ "c:\Program Files (x86)\Steam\steamapps\common\Factorio\data" ], "Lua.workspace.userThirdParty": [ "c:\Users\\AppData\Roaming\Code\User\workspaceStorage\bcfd053678db442f37922c276e0b29c5\justarandomgeek.factoriomod-debug\sumneko-3rd", "c:\Users\*\AppData\Roaming\Code\User\workspaceStorage\86ff54b8208419818c1e54dec2bf38dc\justarandomgeek.factoriomod-debug\sumneko-3rd", "c:\Users\\AppData\Roaming\Code\User\workspaceStorage\957dea38a59421b9f8fd581c3a21a97c\justarandomgeek.factoriomod-debug\sumneko-3rd" ], "Lua.diagnostics.globals": [ "script", "game", "log", "serpent", "defines", "settings" ], "Lua.workspace.checkThirdParty": "ApplyInMemory" }

justarandomgeek commented 5 months ago

just to note - this was almost certainly caused by the multiple userThirdParty links pointing to different workspaces (good chance they're out of sync on versions too). next fmtk will automatically unlink these when this happens.