Page 2 of 2
Re: ss_Baum's questions, now:string.find doesn't work
Posted: Fri Jan 29, 2021 8:05 pm
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
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.
Re: ss_Baum's questions, now:string.find doesn't work
Posted: Fri Jan 29, 2021 8:17 pm
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.
Re: ss_Baum's questions, now:string.find doesn't work
Posted: Fri Jan 29, 2021 8:22 pm
by ss_Baum
I will take a look, thank you very much.
Re: ss_Baum's questions, now:string.find doesn't work
Posted: Fri Jan 29, 2021 9:18 pm
by ss_Baum
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.
Re: ss_Baum's questions, now:string.find doesn't work
Posted: Sat Jan 30, 2021 5:10 pm
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?
Re: ss_Baum's questions, now:Start a for-loop for a table from a specific entry
Posted: Sun Jan 31, 2021 1:06 am
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
Re: ss_Baum's questions, now:Start a for-loop for a table from a specific entry
Posted: Sun Jan 31, 2021 10:37 am
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.
Re: ss_Baum's questions, now:Event code runtime
Posted: Mon Feb 01, 2021 5:19 am
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?
Re: ss_Baum's questions, now:Event code runtime
Posted: Mon Feb 01, 2021 12:39 pm
by PFQNiet
Yes, when an event is triggered, it happens immediately. Factorio is (mostly) single-threaded and everything happens in sequence.
Re: ss_Baum's questions, now:Event code runtime
Posted: Mon Feb 01, 2021 12:41 pm
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?
Re: ss_Baum's questions, now:Can I set the item in the player hand?
Posted: Tue Feb 02, 2021 8:42 pm
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
Re: ss_Baum's questions, now:Can I set the item in the player hand?
Posted: Tue Feb 02, 2021 8:48 pm
by Xorimuth
`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!
Re: ss_Baum's questions, now:Can I set the item in the player hand?
Posted: Tue Feb 02, 2021 8:51 pm
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.

Re: ss_Baum's questions, now:Add circuit network condition
Posted: Wed Feb 03, 2021 7:32 pm
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?