Timage and arrays
BlitzMax Forums/BlitzMax Beginners Area/Timage and arrays
| ||
what is wrong with this.....Global me:timage[6] me[0] = LoadImage("incbin::gfx/circle01.png") me[1] = LoadImage("incbin::gfx/circle02.png") me[2] = LoadImage("incbin::gfx/triangle01.png") me[3] = LoadImage("incbin::gfx/triangle02.png") me[4] = LoadImage("incbin::gfx/triangle03.png") me[5] = LoadImage("incbin::gfx/triangle04.png") its something silly i know....i just can not figure it... |
| ||
Global me:timage[] = new TImage[6] |
| ||
you should have the images declared first: incbin "gfx/circle01.png" the same for all the other images. |
| ||
its still coming up with syntax errorGlobal me:timage[] = New Timage[9] me[0] = LoadImage("incbin::gfx/circle01.png") images declared......why is this? |
| ||
First thing is you don't say what the syntax error is. Second is that the code to reproduce your problem should be so small I don't understand why you don't post it all. Anyway, this works : |
| ||
incbin "...." puts the images in your executable code. then to extract the images from your code you need to: loadimage("incbin::........") |
| ||
ok....i figured out why it was not working....this is what i had.Global cb Type brush Global me:timage[] = New Timage[9] me[0] = LoadImage("incbin::gfx/circle01.png") me[1] = LoadImage("incbin::gfx/circle02.png") me[2] = LoadImage("incbin::gfx/triangle01.png") me[3] = LoadImage("incbin::gfx/triangle02.png") me[4] = LoadImage("incbin::gfx/triangle03.png") me[5] = LoadImage("incbin::gfx/triangle04.png") me[6] = LoadImage("incbin::gfx/circle01_blue.png") me[7] = LoadImage("incbin::gfx/circle01_yellow.png") me[8] = LoadImage("incbin::gfx/blob_alpha_blue.png") Function draw() SetAlpha 0.5 DrawImage me[cb], MouseX(), MouseY(), 0 SetAlpha 1 End Function End Type I now realise it was giving me a "syntax error in user defined type" I was trying to set the values for the array, and i had not made an instance of this type and then declared the array values... so if i added a function create().....then declared them it all works....sorry for not having the full story....but thanks for your help.. or just made the array global to the whole code it works perfectly... thanks again |
| ||
Hello. You put code inside a type and outside any method or function. Make a method or function for load all images. Bye, Paposo |
| ||
and read the documentation on types |
| ||
Ok Sorted that, I am just not getting the whole array thing in my head very straight.....this is what I have....Type Tbrush Global no:Int, on:Int, getbrush:Int Global sx:Int, sy:Int, wx:Int, wy:Int Global brushlist:TList = New TList Field brushmap:Int[] Function Create(sx,sy,wx,wy) b:Tbrush = New Tbrush b.wx = wx b.wy = wy b.brushmap[]=New Int[wx,wy] For Local x = 0 To wx - 1 For Local y = 0 To wy - 1 b.brushmap[x, y] = (sx + x) + ((sy + y) * 20) Next Next brushlist.AddLast b sx = 0; sy = 0;wx = 0; wy = 0 End Function Function draw() For b:Tbrush = EachIn brushlist For Local x = 0 To b.wx For Local y = 0 To b.wy DrawImage Ttiles.tileimg, MouseX() + x * 32, MouseY() + y * 32, b.brushmap[x, y] DrawText "wx= " + b.wx + " wy= " + b.wy, MouseX() + 12, MouseY() + 12 Next Next Next End Function End Type compile error expecting identifier is what error i get on the line where i am trying to resize the array.....I am assuming you can resize an array at any point... What i am trying to do is make a tiled brush, based on a drag and click off another screen with my tiles on. sx and sy are the starting positions on that page of the tiles and wx and wy are how many tiles wide and high the brush will be in tiles....so i want to be able to make any size brush based on what i click and drag...... Any ideas what i am doing wrong....... |
| ||
I just found this post...... http://www.blitzbasic.com/Community/posts.php?topic=57229#636139 So am i now too assume you can only have square fake multidimensional arrays... you couldn't have something like array[12][22] you would have to have array[12][12]..... Is there any other way of storing such information like map data..... |
| ||
That is for resizing arrays. If you know their size I think you can use anything. |
| ||
ok i modified it according to that last post....Type Tbrush Global no:Int, on:Int, getbrush:Int Global sx:Int, sy:Int, wx:Int, wy:Int,ww% Global brushlist:TList = New TList Field brushmap:Int[][] Function Create(sx,sy,wx,wy) b:Tbrush = New Tbrush b.wx = wx b.wy = wy If wy>wx Then b.ww=wy Else b.ww=wx b.brushmap=b.brushmap[..b.ww] For Local i=0 To b.ww-1 b.brushmap[i]=b.brushmap[i][..b.ww] Next For Local x = 0 To b.wx - 1 For Local y = 0 To b.wy - 1 b.brushmap[x][y] = (sx + x) + ((sy + y) * 20) Next Next brushlist.AddLast b sx = 0; sy = 0;wx = 0; wy = 0 End Function Function draw() For b:Tbrush = EachIn brushlist For Local x = 0 To b.wx-1 For Local y = 0 To b.wy-1 Print "x= "+x+" y= "+y DrawImage Ttiles.tileimg, MouseX() + x * 32, MouseY() + y * 32, b.brushmap[x][y] DrawText "wx= " + b.wx + " wy= " + b.wy, MouseX() + 12, MouseY() + 12 Next Next Next End Function End Type this is what i end up with but it gives me a "Unhandled Exception:Attempt to index array element beyond array length" eror at the line in the draw() function "DrawImage Ttiles.tileimg, MouseX() + x * 32, MouseY() + y * 32, b.brushmap[x][y]" I am guessing my array hasn't for some reason been sized...... any ideas.. |
| ||
Hi DREAM change this line... Field brushmap:Int[]to this... Field brushmap:Int[,] and change b.brushmap[]=New Int[wx,wy]to b.brushmap=New Int[wx,wy] In the code above (four posts up) your not really resizing the array, just replacing it with a new one of a different size. The resizing mentioned on that other thread refers to array slicing, which cant be done on 2d+ arrays. |
| ||
Thanks REDi....works a treat....just in case anybody else does a search for arrays and resizing....heres what worked for me...Type Tbrush Global no:Int, on:Int, getbrush:Int Global sx:Int, sy:Int, wx:Int, wy:Int Global brushlist:TList = New TList Field brushmap:Int[,] Function Create(sx,sy,wx,wy) b:Tbrush = New Tbrush b.wx = wx b.wy = wy b.brushmap=New Int[wx,wy] For Local x = 0 To b.wx-1 For Local y = 0 To b.wy-1 b.brushmap[x,y] = (Int(sx/32) + x) + ((Int(sy/32) + y) * 20) Next Next brushlist.AddLast b sx = 0; sy = 0;wx = 0; wy = 0 End Function Function draw() For b:Tbrush = EachIn brushlist For Local x = 0 To b.wx-1 For Local y = 0 To b.wy-1 DrawImage Ttiles.tileimg, MouseX() + x * 32, MouseY() + y * 32, b.brushmap[x, y] Next Next Next End Function End Type ta...... Ian |