on_player_selected_area

Place to get help with not working mods / modding interface.
User avatar
Stringweasel
Filter Inserter
Filter Inserter
Posts: 411
Joined: Thu Apr 27, 2017 8:22 pm
Contact:

Re: on_player_selected_area

Post by Stringweasel »

evandro_6565 wrote: Tue Oct 11, 2022 11:58 am in the debugger where exactly the location of the launch file would be. in the mod folder.. :
That's visible in the link I showed you. It should be

Code: Select all

mods/
    your_mod_1.0.0/
        .vscode/
            launch.json
            settings.json
        control.lua
        data.lua
        etc...
After that I usually just press F5 to start the debugger. Then it will ask you to where your factorio.exe is located. Just follow the prompts.
evandro_6565 wrote: Tue Oct 11, 2022 12:02 pm I have a question, do you know of a tool to visualize this code: shift = util.by_pixel(x, y) I have to keep opening and closing the game to test the positioning
I don't know of such a tool.
Alt-F4 Author | Factorio Modder
My Mods: Hall of Fame | Better Victory Screen | Fluidic Power | Biter Power | Space Spidertron | Spidertron Dock | Weasel's Demolition Derby
Official Contributor to Space Exploration
Pi-C
Smart Inserter
Smart Inserter
Posts: 1726
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: on_player_selected_area

Post by Pi-C »

evandro_6565 wrote: Tue Oct 11, 2022 12:02 pm I have a question, do you know of a tool to visualize this code: shift = util.by_pixel(x, y) I have to keep opening and closing the game to test the positioning
I wonder if you could abuse LuaRendering for testing by plotting on the ground.
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!
User avatar
evandro_6565
Inserter
Inserter
Posts: 35
Joined: Sat Mar 28, 2020 1:04 pm
Contact:

Re: on_player_selected_area

Post by evandro_6565 »

I found this site I tested it worked... :)
User avatar
evandro_6565
Inserter
Inserter
Posts: 35
Joined: Sat Mar 28, 2020 1:04 pm
Contact:

Re: on_player_selected_area

Post by evandro_6565 »

a table receiving another table directly only clones the values ​​but does not create another separate table... for example, tab[1].op and op with value 2 when I copy the table to tab[2] the index "op" if it is changed together the value of tab[1] is changed together.

Code: Select all

global.recorder[ tag ] = new_entity

global.recorder[ 1 ] = new_entity

global.recorder[ 2 ] = global.recorder[ 1 ] 
I used the code "table.insert" to insert "table.insert( global.recorder[ 1 ], global.recorder[ 2 ] )"
but returns an error

I copied this function to copy the table well it seems it worked but with time an error message appears but the game continues running and the message comes back again

Code: Select all

function table_copy(t)
  local t2 = {};
  for k,v in pairs(t) do
    if type(v) == "table" then
        t2[k] = table_copy(v);
    else
        t2[k] = v;
    end
  end
  return t2;
end

Sem título.png
Sem título.png (956.39 KiB) Viewed 2658 times
User avatar
Stringweasel
Filter Inserter
Filter Inserter
Posts: 411
Joined: Thu Apr 27, 2017 8:22 pm
Contact:

Re: on_player_selected_area

Post by Stringweasel »

evandro_6565 wrote: Thu Oct 13, 2022 10:26 am I copied this function to copy the table well it seems it worked but with time an error message appears but the game continues running and the message comes back again
Yeah, if you want a copy of a table then you need to do a deep copy. You're going the right way, but there's an easier way, by using a built-in library

Code: Select all

local util = require("util")

local foo = { "this is a table" }
local foo_copy = util.deepcopy(foo)
As for that crash you get, I haven't seen that before. But it looks like you're trying to save a function of a LuaObject in the table, instead of the LuaObject itself. Meaning something like

Code: Select all

function foo(event)
    local entity = event.entity
    global.bad = entity.launch_rocket -- This trying to save a function which we cannot do in global. 
    global.good = entity.launch_rocket() -- This is fine because we're executing the function
    global.good = entity -- We can safely store LuaObjects in global too
end
However, this is pure speculation, because I don't really know.
Alt-F4 Author | Factorio Modder
My Mods: Hall of Fame | Better Victory Screen | Fluidic Power | Biter Power | Space Spidertron | Spidertron Dock | Weasel's Demolition Derby
Official Contributor to Space Exploration
User avatar
evandro_6565
Inserter
Inserter
Posts: 35
Joined: Sat Mar 28, 2020 1:04 pm
Contact:

Re: on_player_selected_area

Post by evandro_6565 »

Stringweasel wrote: Thu Oct 13, 2022 11:37 am
about the "for_n_of" loop i was using table.remove and i noticed that the loop is stopping :( and i reread the flib article and i noticed this

do you know how to remove without stopping the loop
DO NOT delete entires from tbl from within callback, this will break the iteration. Use the deletion flag instead.
User avatar
Stringweasel
Filter Inserter
Filter Inserter
Posts: 411
Joined: Thu Apr 27, 2017 8:22 pm
Contact:

Re: on_player_selected_area

Post by Stringweasel »

It explains it in the documentation. The function you give it should return if the current entry should be deleted. I guess it should be something like this:

Code: Select all

event.on_tick(function()

    global.from_k = table.for_n_of(extremely_large_table, global.from_k, 10, function(value, key) 
    	
    	-- Do whatever
    	
    	local should_delete_entry = should_delete(key) -- this is a bool
    
        return nil, should_delete_entry
    end)
    
end)
Alt-F4 Author | Factorio Modder
My Mods: Hall of Fame | Better Victory Screen | Fluidic Power | Biter Power | Space Spidertron | Spidertron Dock | Weasel's Demolition Derby
Official Contributor to Space Exploration
User avatar
evandro_6565
Inserter
Inserter
Posts: 35
Joined: Sat Mar 28, 2020 1:04 pm
Contact:

Re: on_player_selected_area

Post by evandro_6565 »

worked, returning boolean true value :)


do you know the code to create this hole through this script
as.png
as.png (587.87 KiB) Viewed 2603 times
User avatar
Stringweasel
Filter Inserter
Filter Inserter
Posts: 411
Joined: Thu Apr 27, 2017 8:22 pm
Contact:

Re: on_player_selected_area

Post by Stringweasel »

evandro_6565 wrote: Fri Oct 14, 2022 10:31 am do you know the code to create this hole through this script
Pretty sure it's an entity, as seen here in the prototype for an explosive rocket

Code: Select all

entity_name = "medium-scorchmark-tintable",
The file is here though, you can even make a sprite out of it:

Code: Select all

Factorio_1.1.69\data\base\graphics\entity\scorchmark\big-scorchmark-top.png
Alt-F4 Author | Factorio Modder
My Mods: Hall of Fame | Better Victory Screen | Fluidic Power | Biter Power | Space Spidertron | Spidertron Dock | Weasel's Demolition Derby
Official Contributor to Space Exploration
User avatar
evandro_6565
Inserter
Inserter
Posts: 35
Joined: Sat Mar 28, 2020 1:04 pm
Contact:

Re: on_player_selected_area

Post by evandro_6565 »

here is my repository, I couldn't do the division of the table tab.car, tab.entity but I removed those loops and only the one from the flib was left
User avatar
Stringweasel
Filter Inserter
Filter Inserter
Posts: 411
Joined: Thu Apr 27, 2017 8:22 pm
Contact:

Re: on_player_selected_area

Post by Stringweasel »

evandro_6565 wrote: Fri Oct 14, 2022 11:20 pm here is my repository,
I think your profile and/or repository is set to private because I can't open the page :)
Alt-F4 Author | Factorio Modder
My Mods: Hall of Fame | Better Victory Screen | Fluidic Power | Biter Power | Space Spidertron | Spidertron Dock | Weasel's Demolition Derby
Official Contributor to Space Exploration
User avatar
evandro_6565
Inserter
Inserter
Posts: 35
Joined: Sat Mar 28, 2020 1:04 pm
Contact:

Re: on_player_selected_area

Post by evandro_6565 »

Stringweasel wrote: Sat Oct 15, 2022 6:38 am
evandro_6565 wrote: Fri Oct 14, 2022 11:20 pm here is my repository,
I think your profile and/or repository is set to private because I can't open the page :)
I have this problem, I don't know how to solve it. I think it's because of that
User avatar
evandro_6565
Inserter
Inserter
Posts: 35
Joined: Sat Mar 28, 2020 1:04 pm
Contact:

Re: on_player_selected_area

Post by evandro_6565 »

evandro_6565 wrote: Sat Oct 15, 2022 10:28 am
Stringweasel wrote: Sat Oct 15, 2022 6:38 am
evandro_6565 wrote: Fri Oct 14, 2022 11:20 pm here is my repository,
I think your profile and/or repository is set to private because I can't open the page :)
I have this problem, I don't know how to solve it. I think it's because of that
sm.png
sm.png (26.68 KiB) Viewed 2552 times
User avatar
Stringweasel
Filter Inserter
Filter Inserter
Posts: 411
Joined: Thu Apr 27, 2017 8:22 pm
Contact:

Re: on_player_selected_area

Post by Stringweasel »

I've never seen that before. I would just click `Contact Support` and try to get it fixed somehow :)
Alt-F4 Author | Factorio Modder
My Mods: Hall of Fame | Better Victory Screen | Fluidic Power | Biter Power | Space Spidertron | Spidertron Dock | Weasel's Demolition Derby
Official Contributor to Space Exploration
User avatar
evandro_6565
Inserter
Inserter
Posts: 35
Joined: Sat Mar 28, 2020 1:04 pm
Contact:

Re: on_player_selected_area

Post by evandro_6565 »

Stringweasel wrote: Sat Oct 15, 2022 1:21 pm I've never seen that before. I would just click `Contact Support` and try to get it fixed somehow :)
I already sent a message today and I'll have to wait

"Due to the high volume of support calls, it may take up to seven business days for our support engineers to respond."


I already tried to delete the account to open another but the delete button is blocked :lol:
User avatar
evandro_6565
Inserter
Inserter
Posts: 35
Joined: Sat Mar 28, 2020 1:04 pm
Contact:

Re: on_player_selected_area

Post by evandro_6565 »


try testing again

the message has been withdrawn
User avatar
Stringweasel
Filter Inserter
Filter Inserter
Posts: 411
Joined: Thu Apr 27, 2017 8:22 pm
Contact:

Re: on_player_selected_area

Post by Stringweasel »

Now it works!
Alt-F4 Author | Factorio Modder
My Mods: Hall of Fame | Better Victory Screen | Fluidic Power | Biter Power | Space Spidertron | Spidertron Dock | Weasel's Demolition Derby
Official Contributor to Space Exploration
User avatar
evandro_6565
Inserter
Inserter
Posts: 35
Joined: Sat Mar 28, 2020 1:04 pm
Contact:

Re: on_player_selected_area

Post by evandro_6565 »

do you know how to block the player from mining an entity... i want the entity to remain operable but the player cannot mine
User avatar
Stringweasel
Filter Inserter
Filter Inserter
Posts: 411
Joined: Thu Apr 27, 2017 8:22 pm
Contact:

Re: on_player_selected_area

Post by Stringweasel »

evandro_6565 wrote: Sun Oct 16, 2022 7:50 pm do you know how to block the player from mining an entity... i want the entity to remain operable but the player cannot mine
Maybe you can use this? https://lua-api.factorio.com/latest/Lua ... ty.minable

Or some players seem to listen for the mine event, and then clone the entity again before the player notices. Almost like this one: https://github.com/Wiwiweb/FactorioUndeletableFluids
Alt-F4 Author | Factorio Modder
My Mods: Hall of Fame | Better Victory Screen | Fluidic Power | Biter Power | Space Spidertron | Spidertron Dock | Weasel's Demolition Derby
Official Contributor to Space Exploration
User avatar
evandro_6565
Inserter
Inserter
Posts: 35
Joined: Sat Mar 28, 2020 1:04 pm
Contact:

Re: on_player_selected_area

Post by evandro_6565 »

Stringweasel wrote: Sun Oct 16, 2022 7:54 pm
evandro_6565 wrote: Sun Oct 16, 2022 7:50 pm do you know how to block the player from mining an entity... i want the entity to remain operable but the player cannot mine
Maybe you can use this? https://lua-api.factorio.com/latest/Lua ... ty.minable

Or some players seem to listen for the mine event, and then clone the entity again before the player notices. Almost like this one: https://github.com/Wiwiweb/FactorioUndeletableFluids
well it worked...thanks :)
Post Reply

Return to “Modding help”