- Home /
How do I indicate that an Array is an Array?
The code below is a script intended to yield a two dimensional array. However whenever I run the code It cannot splice the arrays because it thinks that thy are objects. I've written the same code in C# and Boo but get the same error.
import UnityEngine
class Chunk_assignment (MonoBehaviour):
count = 20
times = 20
def Start ():
world = []
line_template = []
for y in range(0,127):
#sets up a template that is 128 long and consists entirely of '~'#
line_template.Add('~')
for x in range(0,127):
#creates an arrray, the world, that is 128 lines of the template just created#
world.Add(line_template)
for x in range(count):
#Creates 20 'X's at random inside the world#
world[Random.Range(1,len(world)-2)][Random.Range(1,len(world[0])-2)] = 'X'
for x in range(times):
#makes the first and last lines empty to prevent errors when expanding#
world[0] = line_template
world[len(world)-1] = line_template
for x in range(0,len(world)-1):
world[0].Add('~')
world[len(world)-1].Add('~')
linenum = 0
for line in world:
newline = ['~']
#cleans up the vartical edges (makes all entries '~')#
for tilenum in range(1,len(world[linenum])-2):
newline.Add(world[linenum][tilenum])
world[linenum] = newline.Add('~')
linenum += 1
linenum = 0
for line in world:
tilenum = 0
for tile in line:
#planned code, currently not needed#
# if tile == 'X' == world[Linenum+1][tilenum+1] == world[Linenum+1][tilenum] == world[Linenum+1][tilenum-1] == world[Linenum][tilenum+1] == world[Linenum][tilenum-1] == world[Linenum-1][tilenum+1] == world[Linenum-1][tilenum] == world[Linenum-1][tilenum-1]:
# world[linenum][tilenum] = 'x'
if tile == 'X':
#for each X creates one new X near (or in) it#
world[linenum+Random.Range(-1,1)][tilenum+Random.Range(-1,1)] = 'X'
tilenum += 1
linenum += 1
def Update ():
pass
You got the C# version handy? I'm having a really hard time reading Boo. You'll find far more people here that are familiar with C# then with Boo.
Answer by Eric5h5 · Nov 24, 2014 at 12:44 AM
You can't change the size of arrays. Use a generic List instead.
That doesn't seem to work. Even as a generic list when I put a list in a list it reverts to the object class ins$$anonymous$$d of retaining the list class.
I don't know what the syntax for generics is in Boo, but it sounds like you're using an untyped list. A generic list is declared with a specific type, so only that type can be used in it.