Current code which achieves matrix representation of a variety of 3 x 3 tiles in the output window.
No problems in functionality. Possible problems with style
function setup()
parameter.action("Get matrix",devtab)
parameter.integer("k",1,512,432)
parameter.action("Clear Output", function() output.clear() end )
basetile=readImage("Documents:newtile") --these are to be used in the draw function section
shady=readImage("Documents:newshade") -- ditto
xcoord={0,41,82,0,41,82,0,41,82} -- ditto
ycoord={0,0,0,41,41,41,82,82,82} -- ditto
m={}
for ident = 1, 512 do
m[ident]={}
for y=1,9 do
m[ident][y]=0
end
binary(ident,ident-1,1)
end
end
function devtab()
print("new matrix")
print(m[k][7],m[k][8],m[k][9])
print(m[k][4],m[k][5],m[k][6])
print(m[k][1],m[k][2],m[k][3])
end
function binary(ident,rntot,i)
rntot,r=math.modf(rntot/2)
if r>0 then r=1 else r=0 end
m[ident][i]=r
i = i + 1
if rntot>0 then binary(ident,rntot,i) else return
end
end
So at this point I have a tile image a 3x3 grid upon which I wish to add additional images (shaded squares). Everything has been converted to the correct size so as to overlay nicely. Now, I can generate a single composite image using codea and save it no problem (learnt that bit)…except I want to create a bank of 512 of these tiles…so I want the computer to do it all for me. So it would seem obvious (and herein lies my downfall) that I should be able to say for example: if the entry in the matrix representation of matrix k which corresponds to the middle square m[k][5] of the grid m is equal to 1 then lay shady on top of basetile using corner coordinate 41,41
Which is looking something like this…(we are in the draw function and the basetile is already on screen and the sprite mode setting is okay etc)
If m[k][5] ==1 then sprite(shady,41,41)
So I have a list of 9 of these statements and generally nothing happens, or at most the three bottom shades randomly appear.
If I however remove the table references and replace them with a manual input of let’s say squareA = 1 and/or squareB = 1 etc as defined variables at the beginning of the draw function and then run the same conditional statements using these then it works perfectly…but then I’m back to doing everything myself again…
The problem is obviously the use of the table references as if these are removed the conditionals work fine and the composite image is generated…but why will they not transfer over…when they work fine for the print command into the output? What has it taken me 6 hours of my life to not get…To mix movie metaphors, Help me Obi wan Kenobi I’m shrinking!.. And losing the will to live.