mranderson455 [Lexaloffle Blog Feed]https://www.lexaloffle.com/bbs/?uid=42667 Help with recursive functions and memory <p>Hello all!</p> <p>I have been trying to make a minesweeper clone in order to practice grid based games. Everything was going well, until I tried to make the mechanic where adjacent 0 tiles are revealed. I made a recursive function, but when set to all eight directions, it would run out of memory almost instantly. Any tips on how to either optimize the function or replace it? Any help would be awesome, I'm not the best programmer, thanks!</p> <p>Recursive function:</p> <div> <div class=scrollable_with_touch style="width:100%; max-width:800px; overflow:auto; margin-bottom:12px"> <table style="width:100%" cellspacing=0 cellpadding=0> <tr><td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> <td background=/gfx/code_bg0.png> <div style="font-family : courier; color: #000000; display:absolute; padding-left:10px; padding-top:4px; padding-bottom:4px; "> <pre>function tile_reveal(x,y) if y &gt; 0 and y &lt;= #board.board and x &gt; 0 and x &lt;= #board.board[1] then if board.overlay[y][x] == 11 then if board.board[y][x] != 9 then for d=1,#dirs do if y+dirs[d][2] &gt; 0 and y+dirs[d][2] &lt;= #board.board and x+dirs[d][1] &gt; 0 and x+dirs[d][1] &lt;= #board.board[1] and board.overlay[y+dirs[d][2]][x+dirs[d][1]] == 11 then board:change_overlay(x+dirs[d][1],y+dirs[d][2],0) end end end board:change_overlay(x,y,0) end end end</pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> <p> <table><tr><td> <a href="/bbs/?pid=78805#p"> <img src="/bbs/thumbs/pico8_tyofagzi-0.png" style="height:256px"></a> </td><td width=10></td><td valign=top> <a href="/bbs/?pid=78805#p"> tyofagzi</a><br><br> by <a href="/bbs/?uid=42667"> mranderson455</a> <br><br><br> <a href="/bbs/?pid=78805#p"> [Click to Play]</a> </td></tr></table> </p> https://www.lexaloffle.com/bbs/?tid=38646 https://www.lexaloffle.com/bbs/?tid=38646 Thu, 02 Jul 2020 22:00:40 UTC