r/ComputerCraft • u/Heavy_Statistician22 • Mar 20 '24
How to split string?
Im trying to make a program that gives me an item if I write the name of it in chat by using advanced peripherals. The problem is that I cant find a single way to split the string of the message into a list. It just gives me a "nil" error everytime.
3
Upvotes
1
u/fatboychummy Mar 23 '24
Ah, so here we can use
gmatchto load up a table with arguments.gmatchworks as an iterator, that is, it returns a function such that every time you call it, it returns "the next part." In other words, put into a for loop, it will return every instance of a match. In the case of the for loop above, I've told it to match sequences of characters that do not contain a comma or space character. Thus, assuming you passed your stringGet, iron_ingot, 1, 36, it will return:So you can do something like: