1. Subscript an atom Attempt Error
- Posted by Lone_EverGreen_Ranger Jan 15, 2012
- 1555 views
Hello All,
I got an attempt to subscript an atom error. I am trying to make the code for the game to animate a sprite. I'm using EuAllegro. I'll post my code. There are only two frames that need to be animated. I can post more code if it is needed. I only posted what I think is needed to solve the problem.
integer frame1 = 1 integer frame2 = 2 sequence ani = {frame1,frame2} atom link_up_buffer if key(KEY_UP) then for i = 1 to 2 do blit(link_up_buffer[i],screen,0,0,floor((640 - bitmap_w(link_up_buffer[i]))/2), floor((480 - bitmap_h(link_up_buffer[i]))/2), bitmap_w(link_up_buffer[i]), bitmap_h(link_up_buffer[i])) end for end if
2. Re: Subscript an atom Attempt Error
- Posted by LarryMiller Jan 16, 2012
- 1535 views
link_up_buffer is declared as an atom. But in several cases you are attempting to subscript it with link_up_buffer[i]. This is not legal in Euphoria. This syntax is only valid with sequences. Also, in the code nothing is ever assigned to this variable. I am not sure what you are trying to do but this cannot possibly work.
3. Re: Subscript an atom Attempt Error
- Posted by Lone_EverGreen_Ranger Jan 16, 2012
- 1532 views
link_up_buffer is declared as an atom. But in several cases you are attempting to subscript it with link_up_buffer[i]. This is not legal in Euphoria. This syntax is only valid with sequences. Also, in the code nothing is ever assigned to this variable. I am not sure what you are trying to do but this cannot possibly work.
atom g_palette link_up_buffer = load_bitmap("linkup.bmp",g_palette)
Forgot some lines of code. I'm guessing I probably have to declare it as a sequence, though I'm just trying to animate it. The images I'm trying to animate are both contained in one file. Its just getting the frames to animate right, its just frames.
4. Re: Subscript an atom Attempt Error
- Posted by ssallen Jan 16, 2012
- 1490 views
Ok, so I am guessing that you have a single bitmap with multiple images drawn into a grid. However, load_bitmap is not going to split those for you, its only going to load the entire image. You will need to programatically determine or specify where each frame begins and ends. A valid approach to your problem:
atom image integer cframe sequence framedata framedata = { {0, 0, 100, 100}, -- frame 1 upper left and lower right (x1, y1, x2, y2) {100, 0, 200, 100} -- frame 2 upper left and lower right (x1, y1, x2, y2) } cframe = 1 image = load_bitmap("mybitmap.bmp", 0) if key(KEY_UP) then if cframe = 1 then cframe = 2 else cframe = 1 end if end if blit(image,screen,0,0,framedata[cframe][1], framedata[cframe][2],framedata[cframe][3], framedata[cframe][4])
Framedata is going to contain the coordinates of each frame on the bitmap. The example I used above will be a filmstrip pattern with two images side by side on the same y-plane:
----------- *IM1* *IM2* ***** ***** ***** ***** -----------This code really isn't usable without some pacing mechanisms but hopefully you can at least see where you are going wrong.
Edit: Here is a small EuAllegro demo I was playing with a couple years back. It illustrates a very simple game fairly well. It is written in Eu 3.2 but the code should still be fairly handy. http://www.mediafire.com/download.php?6mjk96nr5v2yyda
5. Re: Subscript an atom Attempt Error
- Posted by Lone_EverGreen_Ranger Jan 16, 2012
- 1468 views
Ok, so I am guessing that you have a single bitmap with multiple images drawn into a grid. However, load_bitmap is not going to split those for you, its only going to load the entire image. You will need to programatically determine or specify where each frame begins and ends. A valid approach to your problem:
atom image integer cframe sequence framedata framedata = { {0, 0, 100, 100}, -- frame 1 upper left and lower right (x1, y1, x2, y2) {100, 0, 200, 100} -- frame 2 upper left and lower right (x1, y1, x2, y2) } cframe = 1 image = load_bitmap("mybitmap.bmp", 0) if key(KEY_UP) then if cframe = 1 then cframe = 2 else cframe = 1 end if end if blit(image,screen,0,0,framedata[cframe][1], framedata[cframe][2],framedata[cframe][3], framedata[cframe][4])
Framedata is going to contain the coordinates of each frame on the bitmap. The example I used above will be a filmstrip pattern with two images side by side on the same y-plane:
----------- *IM1* *IM2* ***** ***** ***** ***** -----------This code really isn't usable without some pacing mechanisms but hopefully you can at least see where you are going wrong.
Edit: Here is a small EuAllegro demo I was playing with a couple years back. It illustrates a very simple game fairly well. It is written in Eu 3.2 but the code should still be fairly handy. http://www.mediafire.com/download.php?6mjk96nr5v2yyda
Thanks. I kinda figured I was doing something wrong. Now I have a better idea of what I am doing.