Log In  
Follow
windigo
Follow

Cart #37984 | 2017-03-01 | Code ▽ | Embed ▽ | Forks ▽ | License: CC4-BY-NC-SA

P#37938 2017-02-28 15:39 ( Edited 2017-02-28 20:39)

Hi,

I get an out of memory when calling this function (recursive)

when i click a button, i will call select_ball(4,4,3) -> now all objects with the same index (neighbours) wil get index 7
This works perfectly fine, but no matter how many objects will be selected, in the end there is an out of memory exception

balls is a 16x10 multidimensional array.

arrow keys to move the cursor and 'z' to click on a ball

function select_ball(x,y,index)
    if balls[x][y].index==index then
        balls[x][y]={index=7}
        if x>1 and balls[x-1][y].index==index then
            select_ball(x-1,y,index)
        end
        if x<width and balls[x+1][y].index==index then
            select_ball(x+1,y,index)
        end
        if y>1 and balls[x][y-1].index==index then
            select_ball(x,y-1,index)
        end
        if y<height and balls[x][y+1].index==index then
            select_ball(x,y+1,index)
        end
    end
end

Cart #37921 | 2017-02-28 | Code ▽ | Embed ▽ | Forks ▽ | No License

P#37901 2017-02-27 18:20 ( Edited 2017-02-28 11:53)

Cart #37701 | 2017-02-22 | Code ▽ | Embed ▽ | Forks ▽ | License: CC4-BY-NC-SA
1

Not very original to make a snake game, but it's my first attempt to finish something :-)

P#37702 2017-02-22 12:24 ( Edited 2017-02-28 20:35)

Follow Lexaloffle:        
Generated 2022-09-28 23:20:38 | 0.066s | Q:14