<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[[pdlua]: loops in paint function]]></title><description><![CDATA[<p>Trying to use a loop to create graphical elements and what I gather is I need more context then just <code>g:</code> since it was be the loop's self in this case and not the functions? but I can not quite figure out what that context would be. Tried everything I can think of and did a fair amount of searching for an answer but I do not quite get lua's implementation of OOP and not completely sure I have it's scope and inheritance down, mostly I am just confusing myself at this point and blindly trying any solution I can think of.  Simple example of what I am trying to do:</p>
<pre><code>function boxes.paint(g)
   for i = 1, 8 do
      for j = 1, 8 do
         g:set_color(table.unpack(self.bg[i][j]))
         g:fill_rect(i*25, j*25, 25, 25)
      end
   end
end
</code></pre>
<p>Edit: Related question, is it possible to have each of those rectangles end up in their own layer?</p>
]]></description><link>http://forum.pdpatchrepo.info/topic/14902/pdlua-loops-in-paint-function</link><generator>RSS for Node</generator><lastBuildDate>Mon, 20 Jul 2026 03:19:48 GMT</lastBuildDate><atom:link href="http://forum.pdpatchrepo.info/topic/14902.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 17 Oct 2024 21:40:48 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to [pdlua]: loops in paint function on Thu, 17 Oct 2024 23:26:47 GMT]]></title><description><![CDATA[<p>Trying to use a loop to create graphical elements and what I gather is I need more context then just <code>g:</code> since it was be the loop's self in this case and not the functions? but I can not quite figure out what that context would be. Tried everything I can think of and did a fair amount of searching for an answer but I do not quite get lua's implementation of OOP and not completely sure I have it's scope and inheritance down, mostly I am just confusing myself at this point and blindly trying any solution I can think of.  Simple example of what I am trying to do:</p>
<pre><code>function boxes.paint(g)
   for i = 1, 8 do
      for j = 1, 8 do
         g:set_color(table.unpack(self.bg[i][j]))
         g:fill_rect(i*25, j*25, 25, 25)
      end
   end
end
</code></pre>
<p>Edit: Related question, is it possible to have each of those rectangles end up in their own layer?</p>
]]></description><link>http://forum.pdpatchrepo.info/topic/14902/pdlua-loops-in-paint-function</link><guid isPermaLink="true">http://forum.pdpatchrepo.info/topic/14902/pdlua-loops-in-paint-function</guid><dc:creator><![CDATA[oid]]></dc:creator><pubDate>Thu, 17 Oct 2024 23:26:47 GMT</pubDate></item><item><title><![CDATA[Reply to [pdlua]: loops in paint function on Fri, 18 Oct 2024 01:14:47 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-a" href="http://forum.pdpatchrepo.info/user/oid">@oid</a> I think you made a small typo, it should say boxes:paint instead of boxes.paint. Also make sure you define '<a href="http://self.bg" rel="nofollow">self.bg</a>' (don't click it, not a link) somewhere.</p>
<p>And yeah, you can put them on different layers too:</p>
<pre><code>function boxes:paint(g)
         g:set_color(table.unpack(self.bg[i][j]))
         g:fill_rect(0, 0, 25, 25)
end

function boxes:paint_layer_2(g)
         g:set_color(table.unpack(self.bg[i][j]))
         g:fill_rect(25, 0, 25, 25)
end

function boxes:in_1_repaint1()
    self:repaint(1) -- repaints layer 1
end

function boxes:in_1_repaint2()
  self:repaint(2) -- repaints layer 2
end

</code></pre>
<p>But it'd be more tricky to do that using a single loop. Might still be possible with some lua tricks though</p>
]]></description><link>http://forum.pdpatchrepo.info/topic/14902/pdlua-loops-in-paint-function/2</link><guid isPermaLink="true">http://forum.pdpatchrepo.info/topic/14902/pdlua-loops-in-paint-function/2</guid><dc:creator><![CDATA[timothyschoen]]></dc:creator><pubDate>Fri, 18 Oct 2024 01:14:47 GMT</pubDate></item><item><title><![CDATA[Reply to [pdlua]: loops in paint function on Sun, 20 Oct 2024 00:25:47 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-a" href="http://forum.pdpatchrepo.info/user/timothyschoen">@timothyschoen</a> said:</p>
<blockquote>
<p><a class="plugin-mentions-a" href="http://forum.pdpatchrepo.info/user/oid">@oid</a> I think you made a small typo,</p>
</blockquote>
<p>lol, not sure how that period snuck in but that fixed the problem.  Now I just need to figure out how to automate doing each cell as its own layer but I think I can manage that now. Thanks.</p>
]]></description><link>http://forum.pdpatchrepo.info/topic/14902/pdlua-loops-in-paint-function/3</link><guid isPermaLink="true">http://forum.pdpatchrepo.info/topic/14902/pdlua-loops-in-paint-function/3</guid><dc:creator><![CDATA[oid]]></dc:creator><pubDate>Sun, 20 Oct 2024 00:25:47 GMT</pubDate></item></channel></rss>