need a simple button on the top left corner/edge

Place to get help with not working mods / modding interface.
User avatar
unfunf22
Inserter
Inserter
Posts: 31
Joined: Fri May 20, 2016 9:00 pm
Contact:

need a simple button on the top left corner/edge

Post 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"}
User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3733
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: need a simple button on the top left corner/edge

Post 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)
User avatar
unfunf22
Inserter
Inserter
Posts: 31
Joined: Fri May 20, 2016 9:00 pm
Contact:

Re: need a simple button on the top left corner/edge

Post 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()
User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5211
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: need a simple button on the top left corner/edge

Post by eradicator »

Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
User avatar
unfunf22
Inserter
Inserter
Posts: 31
Joined: Fri May 20, 2016 9:00 pm
Contact:

Re: need a simple button on the top left corner/edge

Post 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
User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2905
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: need a simple button on the top left corner/edge

Post 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()
User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2905
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: need a simple button on the top left corner/edge

Post 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
User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5211
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: need a simple button on the top left corner/edge

Post 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.
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2905
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: need a simple button on the top left corner/edge

Post by darkfrei »

This mod https://mods.factorio.com/mods/darkfrei/DisableEntities scans whole map for flying robots. It's fast.
User avatar
unfunf22
Inserter
Inserter
Posts: 31
Joined: Fri May 20, 2016 9:00 pm
Contact:

Re: need a simple button on the top left corner/edge

Post by unfunf22 »

darkfrei wrote:This mod https://mods.factorio.com/mods/darkfrei/DisableEntities scans whole map for flying robots. It's fast.
when i disable the entitys through your mod, can i use the roboport and/or is it completly gone?
Last edited by unfunf22 on Tue Jan 09, 2018 11:23 pm, edited 1 time in total.
User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2905
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: need a simple button on the top left corner/edge

Post by darkfrei »

unfunf22 wrote:
darkfrei wrote:This mod https://mods.factorio.com/mods/darkfrei/DisableEntities scans whole map for flying robots. It's fast.
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.
User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5211
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: need a simple button on the top left corner/edge

Post by eradicator »

darkfrei wrote:This mod https://mods.factorio.com/mods/darkfrei/DisableEntities scans whole map for flying robots. It's fast.
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).
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
User avatar
unfunf22
Inserter
Inserter
Posts: 31
Joined: Fri May 20, 2016 9:00 pm
Contact:

Re: need a simple button on the top left corner/edge

Post by unfunf22 »

Has something changed that I can't use it like this anymore?

Code: Select all

data.raw["gui-style"].default["test-button"]
Post Reply

Return to “Modding help”