Blueprint Flip and Turn

by NovaM

Mirrors/Flips a blueprint in hand. WARNING: if you are using factorio 1.0 or factorio >= 0.18.37 then you must use the workaround below: - Grab the blueprint from the new blueprint interface - Drop it in the inventory to make a copy. (there is a row of buttons across the top one of has the letter C on it that is the copy button fot the print that is highlighted) - Grab that copy - The flip buttons work on this copy. This issue is not fixable for now, due to Factorio API limitation.

Content
3 years ago
0.16 - 1.1
46.7K
Blueprints

b [FIXED in 18.5.3] Error while running event blueprint_flip_and_turn::on_init()

3 years ago
(updated 3 years ago)

Hello,
A bug occurred when I wanted to update a mod on a server. The server crashed during startup.
Here is the error recovered in the logs:


32.336 Error ServerMultiplayerManager.cpp:90: MultiplayerManager failed: "The mod Blueprint Flip and Turn (18.4.0) caused a non-recoverable error.
Please report this error to the mod author.

Error while running event blueprint_flip_and_turn::on_init()
__blueprint_flip_and_turn__/control.lua:355: attempt to index field '?' (a nil value)
stack traceback:
    __blueprint_flip_and_turn__/control.lua:355: in function 'rmButtons'
    __blueprint_flip_and_turn__/control.lua:388: in function 'manageButtons'
    __blueprint_flip_and_turn__/control.lua:402: in function 'manageButtonsAllPlayers'
    __blueprint_flip_and_turn__/control.lua:419: in function <__blueprint_flip_and_turn__/control.lua:417>"

I was able to correct the error to be able to restart my server without problem. I let you perhaps adapt the correction yourself but here is the correction code:


-- hide buttons = remove them --
local function rmButtons(player_index)
    if player_index ~= nil then
        if blpflip_location ~= nil then
            local ok = pcall(function() 
                if game.players[player_index].gui[blpflip_location].blpflip_flow then
                    game.players[player_index].gui[blpflip_location].blpflip_flow.destroy()
                end
            end)
            if ok then
                if game.players[player_index].gui[blpflip_location].blpflip_flow then
                    game.players[player_index].gui[blpflip_location].blpflip_flow.destroy()
                end
            end
        end
    end
end

Thank you.

3 years ago

Hello Ritn,

Thanks for your bug report.
You made a change in a "low level" function named rmButtons. I made a similar fix on the calling function manageButtons (to avoid the same issue when we create the buttons).

 -- create or hide buttons (per user) --
 local function manageButtons(player_index)
+       -- avoid strange case where player_index is nil
+       if not player_index then return end

Your issue should be fixed now.
Released in 17.5.0 and 18.5.0.

For your information, if you are insterested by improving your Lua skill,
there is a logic issue in you code...

When you use "pcall" it really execute the lua code.
The "ok" variable is only here to tell you if everything was good or bad.

Your code inside the "if ok " code block is duplicated. The job was already done in the function call by pcall.
If you just want to run a code and ignore any error, you can simply do (without any ok variable):

pcall(function()
   THE_CODE_HERE
end)

If you want to catch the error to send a warning message

local ok = pcall(function()
   THE_CODE_HERE
end)
if not ok then
     WARNING_CODE_HERE
end

Have fun!

3 years ago

oh thank you for the tip !
Lua is not the language I code most commonly, apart from Factorio mods.

3 years ago
(updated 3 years ago)

I understand why I just ignored the error: (version 18.5.0)


Error while running event blueprint_flip_and_turn::on_configuration_changed
__blueprint_flip_and_turn__/control.lua:355: attempt to index field '?' (a nil value)
stack traceback:
    __blueprint_flip_and_turn__/control.lua:355: in function 'rmButtons'
    __blueprint_flip_and_turn__/control.lua:391: in function 'manageButtons'
    __blueprint_flip_and_turn__/control.lua:405: in function 'manageButtonsAllPlayers'
    __blueprint_flip_and_turn__/control.lua:416: in function <__blueprint_flip_and_turn__/control.lua:414>"
3 years ago

Hello,

I rewrite the way to walk on the data struct to avoid error...
Released in 18.5.1

Let me know :
- if now it doesn't crash
- if now it show you Warning instead

Regards,

3 years ago
(updated 3 years ago)

149.539 Error AppManagerStates.cpp:1448: blueprint_flip_and_turn/control.lua:369: ')' expected near '}'

3 years ago
(updated 3 years ago)

149.539 Error AppManagerStates.cpp:1448: blueprint_flip_and_turn/control.lua:369: ')' expected near '}'

I found a typo on control.lua:

local function doButtons(player_index)
local gui_location = walk(game, {"players", player_index, "gui", blpflip_location})
if not gui_location then
-- avoid error but there are something strange!
modwarning("doButtons: there is no gui_location for player_index="..tostring(player_index)..". Please report it to the mod's Author.")
return
end
local exists = walk(gui_location, "blpflip_flow"})
if not exists then
local flow = gui_location.add{type = "flow", name = "blpflip_flow", direction = blpflip_flow_direction}
flow.add{type = "button", name = "blueprint_flip_horizontal", style = "blpflip_button_horizontal"}
flow.add{type = "button", name = "blueprint_flip_vertical", style = "blpflip_button_vertical"}
end
oldStrangeStuff(player_index)
end

on line
local exists = walk(gui_location, "blpflip_flow"})
There is a "}" that doesn't match accurately.

  • After deleting "}" got another error:
    blueprint_flip_and_turn/control.lua:2: attempt to index global "game" (a nil value)
    stack traceback:
    blueprint_flip_and_turn/control.lua:2: in main chunk
3 years ago
(updated 3 years ago)

Hello,

Indeed this error appears when starting the server:
"blueprint_flip_and_turn/control.lua:369: ')' expected near '}'"

3 years ago

Perfect !

3 years ago

Sorry I tried only locally and on server I have this error ...

3 years ago

I release the final version 18.5.2 and 17.5.2
There is no difference for you between 18.5.1 and 18.5.2. but I need it update the changelog and backport to the 17.x branch.

Have fun !

3 years ago

No there is still this error: (only on server)
"blueprint_flip_and_turn/control.lua:369: ')' expected near '}'"

3 years ago

Oups ...

3 years ago
(updated 3 years ago)

Typo fixed in 17.5.3 ands 18.5.3.
Is it ok for you ?

3 years ago

no :

3.226 Error ServerMultiplayerManager.cpp:90: MultiplayerManager failed: "__blueprint_flip_and_turn__/control.lua:2: attempt to index global 'game' (a nil value)
stack traceback:
    __blueprint_flip_and_turn__/control.lua:2: in main chunk"
3 years ago

Yeah still bugged for me too

3 years ago

Updated!

3 years ago

The server was able to start successfully and no problem at stake. Thank you!

3 years ago

Cool. I will consider it like really fixed ! ;-)

Have fun!

This thread has been locked.