PDA

View Full Version : Is there a "split()" function? (In LUA)



Prasoc
August 17th, 2006, 13:35
Hi, I was wandering if there was a command to split all of a string into arrays for my game that uses text files to show the level. It is in the format:


0,0,0,0,2,2,2,2,2,2,2,2,2,2,2,
0,0,0,0,2,1,1,1,1,1,1,1,1,1,2,
0,0,0,0,2,1,1,1,1,1,1,1,1,1,2,
0,0,0,0,0,1,1,1,1,1,1,1,1,1,2,
0,0,0,0,2,1,1,1,1,1,1,1,1,1,2,
0,0,0,0,2,2,2,2,2,2,2,2,2,2,2

which "0" is blackness, "1" is wooden flooring and "2" is the wall.

yaustar
August 17th, 2006, 14:31
Try the string library: http://lua-users.org/wiki/StringLibraryTutorial

You should be able to get away with using the byte function and iterating through the string.

Prasoc
August 17th, 2006, 14:45
trying it now

yaustar
August 17th, 2006, 14:51
I was just wondering, why not use a two dimensional array of numbers/integers instead of strings? It be quicker to process and manage.

Prasoc
August 17th, 2006, 15:40
ah yes, i could put it into another lua file like level1.lua and have it as an array and use dofile() to get it. hmmm..