2-D string array with more columns than rows issue
-
I am working an game, based on text characters and run into this. Blame me, if its just not the approach how to use an array. I probably better switch to a 1-D array of strings ;-)
ID: LXK738YWK8a = [ [".", ".", ".", "."], [".", ".", ".", "."], [".", ".", ".", "."] ] print(len(a), "x", len(a[0])) print() a[0][3] = "X" // should not change the amount of rows, just the 3rd element in the first row print(len(a), "x", len(a[0]))
output:
3x4 4x4
-
They start off at 0. By setting a[0][3] to ”x”, you’re adding a 4th element. I think it’s fine...
-
@toxibunny Thanks for reading, but I am not convinced yet.
print(a)
at the end, returns Unknown type: 4. print() with an array should always return that array, I guess. -
I agree with @spikey that this is a bug.
If you print a[0] a[1] and a[2] individually, you do see
[".", ".", ".", "X"], [".", ".", ".", "."], [".", ".", ".", "."]
, but len(a) indicates that there is an a[3], which is not the case and trying to read it, does throw an error. -
Oh yeah. Sorry, my mistake.
-
@spikey said in 2-D string array with more columns than rows issue:
a = [ [".", ".", ".", "."], [".", ".", ".", "."], [".", ".", ".", "."] ]
Do you get the same issue if you initialise a like this instead:
a = [ "....", "....", "...." ]
-
@vinicity interesting, this works for reading form
a[0][3]
but not writing to it. To write you can only access the whole string then, likea[0]='...X'
.
My workaround right now, is just to define the row numbers as fix and not uselen(a)
to determine it. -
Great that you have a workaround. Also, I’m really curious about your new game!
-
Hello guys
I have a similar problem. I don't understand code very well yet to say whether it is identical to the problem described here or has something to do with it.
This code works very well
myArray = [ [0,0,0,0,0], [0,0,0,0,0], [0,0,0,0,0] ] myArray[1][2] = 1 print[myArray]
Returns:
[ [0,0,0,0,0], [0,0,1,0,0], [0,0,0,0,0] ]
But this code ... :
myArray = [ [0,0,0,0,0], [0,0,0,0,0], [0,0,0,0,0] ] myArray[1][3] = 1 print[myArray]
Returns a ---Error--- : Unknown type: 4
My workaround is to add twice as many rows:
myArray = [ [0,0,0,0,0], [0,0,0,0,0], [0,0,0,0,0], [0,0,0,0,0] ] myArray[1][3] = 1 print[myArray]
Returns:
[ [0,0,0,0,0], [0,0,0,1,0], [0,0,0,0,0] ]
Is that a bug in Fuze4 ???
-
@Starshine-Vixen Yes this seems to be a bug. I have tried it with the latest patch (which should be out soon) and it works as expected