Hi, again! Thanks for fixing the bugs! :-)
My studies have just begun, the load on me has increased, so I don’t remember everything that I made a note in my head about.
I've had a look again and found some more issues. Let's start with button.lua:
This works alright, but isn't looking really nice. Your way will place the button at the very top of the screen. The recommended way is to put it into a frame that's at the top of the screen ('button_flow'):
mod_gui = require('mod-gui')
local function createHelloButton(player)
local button_flow = mod_gui.get_button_flow(player)
local button = button_flow["kagebunshins_spawn"]
For defining the button, try this:
button = player.gui.top.add{
type = "button",
name = "kagebunshins_spawn",
caption = {"kagebunshin-gui.caption"},
tooltip = {"kagebunshin-gui.tooltip"}
}
That will work if you create a file locale/en/gui.lua:
[kagebunshin-gui]
caption=Clones
tooltip=Click to spawn clone
(Don't put spaces around the '='! caption = Clones
would mean that the field name is 'caption ' instead of 'caption', and the translation would become ' Click to spawn clone', with a leading space.)
You can add translations to other languages by creating a new sub directory in 'locale', copying all files in locale/en to the new folder, and replace the texts on the right side of the '='. If no locale is found for a language, English ('en') will be used as fallback.
-
For function onHelloButtonClick, I have an idea: Sending the clone in the direction of the closest chunk isn't really intuitive because you usually don't see the grid with the chunk borders. How about using the direction in which the player's character is moving (player.character.direction
), and falling back to the direction of the closest chunk if the player doesn't have a valid character?
-
You create a button for each player who has joined the game, but if any of these buttons is clicked, you always spawn a clone of game.players[1]
. The on_gui_click
event passes on player_index
, so it's trivial to call onHelloButtonClick()
with the correct player:
if event.element and event.element.name == "kagebunshins_spawn" then
onHelloButtonClick(game.players[event.player_index])
end
File clones.lua has some big problems!
-
The character data you save in kagebunshins_coords won't persist between saves because they aren't stored in the global table. That's just a slight nuisance in single player mode, but will cause desyncs in multiplayer games. Remember: Factorio distinguishes between "a global table" (any table that has not been declared with the keyword local
), and "the table global", which will be stored in saved game. Make sure that you rename all instances of kagebunshins_coords
to global.kagebunshins_coords
and you're on the safe side.
-
Entities should never be used as table index! According to Bilka (one of the devs), this will also cause desyncs. Instead, use a structure like this:
kagebunshins[character.unit_number] = character
kagebunshins_cords[character.unit_number] = {
old_x = character.position.x,
old_y = character.position.y
}
-
In control.lua, there's something fishy in your handler for the on_tick event:
script.on_event(defines.events.on_tick,
function(event)
--Узнаём путь до близжайсшего чанка(внести в отдельное событие.)
if event.tick % 1 == 0 then
…
end
end
end)
The check for event.tick %1 == 0
is just a waste of computing power because the condition is always true. Something like this only makes sense if you want to wait for >1 ticks between actions.