Page 1 of 1
need a simple button on the top left corner/edge
Posted: Sun Jan 07, 2018 5:05 pm
by unfunf22
I just need a button in the upper left corner and when I click on it execute commands.
I don't need a picture in the button, it's enough if a name is there and the command is executed.
unfortunately, this command doesn't work in the "data.lua"
every time I start the game I get an error message with "attempt to index global' game' (a nil value)
Translated with
http://www.DeepL.com/Translator
Code: Select all
game.players[1].gui.top.add{type = "button", caption = "My First Button", name = "ups-up-lite"}
Re: need a simple button on the top left corner/edge
Posted: Sun Jan 07, 2018 5:12 pm
by DaveMcW
Code: Select all
script.on_event(defines.events.on_player_created, function(event)
game.players[event.player_index].gui.top.add{type = "button", caption = "My First Button", name = "ups-up-lite"}
end)
Re: need a simple button on the top left corner/edge
Posted: Sun Jan 07, 2018 5:48 pm
by unfunf22
so now im not complete ready but i have a small problem, i need a code for enemy destroy but the code kills all what i see but not what im not see.
like get chunk for chunk.x * 32, chunk.y * 32 find entity enemy do destroy()
Re: need a simple button on the top left corner/edge
Posted: Mon Jan 08, 2018 11:47 am
by eradicator
Re: need a simple button on the top left corner/edge
Posted: Mon Jan 08, 2018 5:01 pm
by unfunf22
could this code work?
Code: Select all
for key, surface in pairs(game.surfaces) do
game.surfaces[1].find_entities_filtered{force= "enemy"} do
game.forces["enemy"].kill_all_units()
end
end
Re: need a simple button on the top left corner/edge
Posted: Mon Jan 08, 2018 6:59 pm
by darkfrei
No, but this:
Code: Select all
for i, surface in pairs(game.surfaces) do
local enemies_list = surface.find_entities_filtered{force= "enemy"}
for j, enemy in pairs (enemies_list) do
enemy.destroy()
end
end
Or for units only
Code: Select all
local enemy_force = game.forces["enemy"]
enemy_force.kill_all_units()
Re: need a simple button on the top left corner/edge
Posted: Mon Jan 08, 2018 7:00 pm
by darkfrei
unfunf22 wrote:could this code work?
No, but this:
Code: Select all
for i, surface in pairs(game.surfaces) do
local enemies_list = surface.find_entities_filtered{force= "enemy"}
for j, enemy in pairs (enemies_list) do
enemy.destroy()
end
end
Or for units only
Code: Select all
local enemy_force = game.forces["enemy"]
enemy_force.kill_all_units()
See wiki console page:
https://wiki.factorio.com/Console#Kill_ ... y.22_force
Re: need a simple button on the top left corner/edge
Posted: Tue Jan 09, 2018 1:28 am
by eradicator
darkfrei wrote:
No, but this:
Code: Select all
for i, surface in pairs(game.surfaces) do
local enemies_list = surface.find_entities_filtered{force= "enemy"}
for j, enemy in pairs (enemies_list) do
enemy.destroy()
end
end
Remember that scanning one (or several) complete surfaces like that will be extremely slow and visually "freeze" the game until its finished.
Re: need a simple button on the top left corner/edge
Posted: Tue Jan 09, 2018 7:43 am
by darkfrei
This mod
https://mods.factorio.com/mods/darkfrei/DisableEntities scans whole map for flying robots. It's fast.
Re: need a simple button on the top left corner/edge
Posted: Tue Jan 09, 2018 11:12 pm
by unfunf22
when i disable the entitys through your mod, can i use the roboport and/or is it completly gone?
Re: need a simple button on the top left corner/edge
Posted: Tue Jan 09, 2018 11:20 pm
by darkfrei
unfunf22 wrote:when i disable the entitys through your mod, can i use the roboport and/or is it completly gone?s
Click - all disabled, click again - enabled. Robots too.
Re: need a simple button on the top left corner/edge
Posted: Wed Jan 10, 2018 1:43 am
by eradicator
Test it again in a megafactory with 10k+ bots, at least 100MB map size, running on an Intel Atom. We'll see if it's "fast" then (hint: it's not, because find_entities(_filters) is a slow operation).
Re: need a simple button on the top left corner/edge
Posted: Sun Jan 14, 2018 3:21 pm
by unfunf22
Has something changed that I can't use it like this anymore?
Code: Select all
data.raw["gui-style"].default["test-button"]