ss_Baum's questions, now:Add circuit network condition

Place to get help with not working mods / modding interface.
ss_Baum
Long Handed Inserter
Long Handed Inserter
Posts: 61
Joined: Wed Apr 04, 2018 10:58 am
Contact:

Re: ss_Baum's questions, now:string.find doesn't work

Post by ss_Baum »

Today's question: String.find doesn't work

So there is my code:

Code: Select all

function cleanname(name)  --cleans the name from the numbers with returning the right one

	local name = name
	if string.find(name, "custom-belt") then
		return "custom-belt"
	end

	if string.find(name, "custom-underground-belt") then
		return "custom-underground-belt"
	end
	
	if string.find(name, "custom-splitter") then
		return "custom-splitter"
	end
	print("log","name: ", name)
	return nil

end
it print's the log

Code: Select all

log     name:   custom-belt
so as you can see, it should find the string in the first statement, but this return's nil. where is my error?

edit: I actually found the problem. It does not work, when the string and the pattern are the same. so because both was custom-belt it didn't work. But just belt work's. a little confusing.
Last edited by ss_Baum on Fri Jan 29, 2021 9:19 pm, edited 3 times in total.
Bilka
Factorio Staff
Factorio Staff
Posts: 3309
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: ss_Baum's questions, now:string.find doesn't work

Post by Bilka »

- is a special character in Lua search patterns, you need to escape it with % (see https://www.lua.org/pil/20.2.html). Alternatively, you can use the "plain" option of string.find to turn off the pattern matching: https://www.lua.org/manual/5.2/manual.h ... tring.find.
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.
ss_Baum
Long Handed Inserter
Long Handed Inserter
Posts: 61
Joined: Wed Apr 04, 2018 10:58 am
Contact:

Re: ss_Baum's questions, now:string.find doesn't work

Post by ss_Baum »

Bilka wrote: Fri Jan 29, 2021 8:17 pm - is a special character in Lua search patterns, you need to escape it with % (see https://www.lua.org/pil/20.2.html). Alternatively, you can use the "plain" option of string.find to turn off the pattern matching: https://www.lua.org/manual/5.2/manual.h ... tring.find.
I will take a look, thank you very much.
ss_Baum
Long Handed Inserter
Long Handed Inserter
Posts: 61
Joined: Wed Apr 04, 2018 10:58 am
Contact:

Re: ss_Baum's questions, now:string.find doesn't work

Post by ss_Baum »

Bilka wrote: Fri Jan 29, 2021 8:17 pm - is a special character in Lua search patterns, you need to escape it with % (see https://www.lua.org/pil/20.2.html). Alternatively, you can use the "plain" option of string.find to turn off the pattern matching: https://www.lua.org/manual/5.2/manual.h ... tring.find.
I actually found the problem. It does not work, when the string and the pattern are the same. so because both were custom-belt it didn't work. But just belt work's. a little confusing.
ss_Baum
Long Handed Inserter
Long Handed Inserter
Posts: 61
Joined: Wed Apr 04, 2018 10:58 am
Contact:

Re: ss_Baum's questions, now:string.find doesn't work

Post by ss_Baum »

Today's question: Start a for-loop for a table from a specific entry

this is, how I call the loop

Code: Select all

for pos, entity in pairs(entities) do
Is there a way to start from a specified position ore do I need to create a table, for every, let's say 100 entities?
PFQNiet
Filter Inserter
Filter Inserter
Posts: 289
Joined: Sat Sep 05, 2020 7:48 pm
Contact:

Re: ss_Baum's questions, now:Start a for-loop for a table from a specific entry

Post by PFQNiet »

If your table is an array then you can use a more "typical" for loop:

Code: Select all

for i=start,start+100 do
  local entity = entities[i]
  if not entity then break end
  -- ...
end
ss_Baum
Long Handed Inserter
Long Handed Inserter
Posts: 61
Joined: Wed Apr 04, 2018 10:58 am
Contact:

Re: ss_Baum's questions, now:Start a for-loop for a table from a specific entry

Post by ss_Baum »

PFQNiet wrote: Sun Jan 31, 2021 1:06 am If your table is an array then you can use a more "typical" for loop:
I can't do this because I need to access the belt's with the position data, to figure out, with which belt the player interacts.
But I could store the position data in an array and access the entities via this array. In a separate table I would just have to store the position of this array entry, so i can access the entry with the position-data.
But I actually have no, how I could update the array position in the separate table.
But I have to do this to figure out, what to delete if the player ore a robot mines a belt. I could again loop through every entry and update them, but that wouldn't be very efficient.
I have the same problem with using separate tables for every 100 belt's but it would probably reduce the number of entries to update.
ss_Baum
Long Handed Inserter
Long Handed Inserter
Posts: 61
Joined: Wed Apr 04, 2018 10:58 am
Contact:

Re: ss_Baum's questions, now:Event code runtime

Post by ss_Baum »

Just a short, general question.
If I have an Event, tries Factorio to run the event code in the same tick the event is fired? Or are the ticks not relevant for running the event-code?
PFQNiet
Filter Inserter
Filter Inserter
Posts: 289
Joined: Sat Sep 05, 2020 7:48 pm
Contact:

Re: ss_Baum's questions, now:Event code runtime

Post by PFQNiet »

Yes, when an event is triggered, it happens immediately. Factorio is (mostly) single-threaded and everything happens in sequence.
ss_Baum
Long Handed Inserter
Long Handed Inserter
Posts: 61
Joined: Wed Apr 04, 2018 10:58 am
Contact:

Re: ss_Baum's questions, now:Event code runtime

Post by ss_Baum »

PFQNiet wrote: Mon Feb 01, 2021 12:39 pm Yes, when an event is triggered, it happens immediately. Factorio is (mostly) single-threaded and everything happens in sequence.
So that would mean, it makes no runtime difference when I do something in the on_tick event with an if_condition or fire an event, that run's the same code?
ss_Baum
Long Handed Inserter
Long Handed Inserter
Posts: 61
Joined: Wed Apr 04, 2018 10:58 am
Contact:

Re: ss_Baum's questions, now:Can I set the item in the player hand?

Post by ss_Baum »

Can I set the item in the player hand?

Is there in the control.lua a way, to set the Item, the player has in the hand?
the cursor_stack is read only https://lua-api.factorio.com/latest/Lua ... rsor_stack
This would be nice, that the player can use the pipette
Xorimuth
Filter Inserter
Filter Inserter
Posts: 695
Joined: Sat Mar 02, 2019 9:39 pm
Contact:

Re: ss_Baum's questions, now:Can I set the item in the player hand?

Post by Xorimuth »

ss_Baum wrote: Tue Feb 02, 2021 8:42 pm Can I set the item in the player hand?

Is there in the control.lua a way, to set the Item, the player has in the hand?
the cursor_stack is read only https://lua-api.factorio.com/latest/Lua ... rsor_stack
This would be nice, that the player can use the pipette
`player.cursor_stack` returns a LuaItemStack that you can use .set_stack, .swap_stack or .transfer_stack, depending on which is appropriate. (.clear may also be useful).

PS You may find it useful to join the discord server and ask in #mod-making. Lots of helpful people there and you may find that you get quicker answers with easier back-and-forth!
My mods
Content: Lunar Landings | Freight Forwarding | Spidertron Patrols | Spidertron Enhancements | Power Overload
QoL: Factory Search | Module Inserter Simplified | Wire Shortcuts X | Ghost Warnings
ss_Baum
Long Handed Inserter
Long Handed Inserter
Posts: 61
Joined: Wed Apr 04, 2018 10:58 am
Contact:

Re: ss_Baum's questions, now:Can I set the item in the player hand?

Post by ss_Baum »

Xorimuth wrote: Tue Feb 02, 2021 8:48 pm PS You may find it useful to join the discord server and ask in #mod-making. Lots of helpful people there and you may find that you get quicker answers with easier back-and-forth!
Thank you very much, i forgot to show there. :oops:
ss_Baum
Long Handed Inserter
Long Handed Inserter
Posts: 61
Joined: Wed Apr 04, 2018 10:58 am
Contact:

Re: ss_Baum's questions, now:Add circuit network condition

Post by ss_Baum »

Is there a way to add a circuit network condition ore do I have to do this with an own gui and control-script?
Post Reply

Return to “Modding help”