Game Development Reference
In-Depth Information
function string:split(sep)
local sep, fields=sep or ":", {}
local pattern=string.format("([^%s]+)", sep)
self:gsub(pattern, function(c) fields[#fields+1]=c end)
return fields
end
This returns a table that has the strings split based on the separator. Here's an example of how we
can use this:
str="name=Jayant"
results=str:split("=")
print("The value of " .. results[1] .. " is " .. results[2])
× 5 that contains a start position, an
5-1 .
Figure 5-1. A graphic representation of the levels
In this example, the ' ' marks the position where the player is when the game starts. The '✪' marks
the spot the player needs to reach in order to complete the level. The gray squares are walls that
obstruct the player's movements. So, we can now convert this to level data. We can store it in a 2D
array, which would look like the following:
level1={
{0,0,0,0,0},
{0,0,0,1,0},
{0,0,0,1,0},
{0,1,1,1,0},
{0,0,0,0,0},
}
 
Search WWH ::




Custom Search