problem with object.fill

Hello again corona and app devs. I’m on a quest to fill in our level select map, with images based on progress, Basically, we’re going to have 3 states a level can be in, “played” (but can be re-played), “Next level”, and “can’t play” I had it set to change colors based on those categories, but was then told we may be using different images instead, so now I need to re-work it :smiley:

so, when initiating the points on the map, I added this:

 local paint = {type = "image", filename ="img/character.png" } local closedPaint = {type="image", filename = "img/close.png"} local played = {type = "image", filename = "img/characterGreen.png" } circ = display.newCircle(0,0,rad\*1.7) circ.fill = paint

as my fill images. The logic to switch in part, looks like this:

elseif(self.index\>currLoc)then circ.fill = closedPaint --self.circ = display.newImage("img/close.png"); group.isVisible = true --self.isTouchEnabled = true group.xScale = config.xScale or self.xScaleInit group.yScale = config.yScale or self.yScaleInit end

The problem is, it doesn’t switch. If I change circ.fill up top, than all of the circles will have that image, but changing them within the logic, isn’t doing anything. Any advice?

Not seeing enough code to get full few of problem, but problem is likely scope.

You’re using the handle ‘circ’, but my guess is you used that to make several circles…

local circ = display.newCircle(...) circ = display.newCircle(...) circ = display.newCircle(...) .... Some time later in your code circ.fill = ... -- Only changes last circ

What is the ‘self’ object in your code?  Is that the  circle?  If so, try:

self.fill = ...

Thanks for the help. Yes, self. SHOULD be the circ.

Here’s the rest of the init function, it’s a bit of a mash between my work and another programmers (and i’m faaar the Jr. programmer, calling me a “trainee” sometimes is generous :P:

function Points:init(config) --init for the instance config = config or {} self.index = config.index local group = display.newGroup(); group.isVisible = false self.group = group group.x, group.y = config.x or 0, config.y or 0 local disp = config.disp or display.getCurrentStage() --always good to have a fallback disp:insert(group); self.disp = disp local scope = config.scope or disp self.scope = scope --create the visual points local rad = 15 local paint = {type = "image", filename ="img/character.png" } local closedPaint = {type="image", filename = "img/close.png"} local played = {type = "image", filename = "img/characterGreen.png" } circ = display.newCircle(0,0,rad\*1.7) circ.fill = paint --circ.strokeWidth=1 --circ:setStrokeColor(0) --circ:setFillColor(0.6) --local circ = display.newImage("img/character.png"); --circ:setFillColor(0.6) group:insert(circ) self.circ = circ

I tried yesterday, to wrap my head around the image swap tutorial yesterday, but just wasn’t grasping it, might have another go at it today, if you think that’s a better approach.

  1. Assuming the circle was self, then my last answer still stands:  “self.fill = …”

  2. In your code I see a bad practice.  You’re creating a global variable called ‘circ’ and storing a reference to a circle in it.  Your code should be changed to this to make it safer (less likely to leak memory):

    local circ = display.newCircle(0,0,rad*1.7) circ.fill = paint

ok I will double check and double try. I thought whenever I set the circ to local, it wasn’t registering it down in the other function, local should be file/“class” wide, correct?

edit to add: I’m dense aren’t I? I just need to pass self to he function to get it to work, don’t I? /facepalm

Not seeing enough code to get full few of problem, but problem is likely scope.

You’re using the handle ‘circ’, but my guess is you used that to make several circles…

local circ = display.newCircle(...) circ = display.newCircle(...) circ = display.newCircle(...) .... Some time later in your code circ.fill = ... -- Only changes last circ

What is the ‘self’ object in your code?  Is that the  circle?  If so, try:

self.fill = ...

Thanks for the help. Yes, self. SHOULD be the circ.

Here’s the rest of the init function, it’s a bit of a mash between my work and another programmers (and i’m faaar the Jr. programmer, calling me a “trainee” sometimes is generous :P:

function Points:init(config) --init for the instance config = config or {} self.index = config.index local group = display.newGroup(); group.isVisible = false self.group = group group.x, group.y = config.x or 0, config.y or 0 local disp = config.disp or display.getCurrentStage() --always good to have a fallback disp:insert(group); self.disp = disp local scope = config.scope or disp self.scope = scope --create the visual points local rad = 15 local paint = {type = "image", filename ="img/character.png" } local closedPaint = {type="image", filename = "img/close.png"} local played = {type = "image", filename = "img/characterGreen.png" } circ = display.newCircle(0,0,rad\*1.7) circ.fill = paint --circ.strokeWidth=1 --circ:setStrokeColor(0) --circ:setFillColor(0.6) --local circ = display.newImage("img/character.png"); --circ:setFillColor(0.6) group:insert(circ) self.circ = circ

I tried yesterday, to wrap my head around the image swap tutorial yesterday, but just wasn’t grasping it, might have another go at it today, if you think that’s a better approach.

  1. Assuming the circle was self, then my last answer still stands:  “self.fill = …”

  2. In your code I see a bad practice.  You’re creating a global variable called ‘circ’ and storing a reference to a circle in it.  Your code should be changed to this to make it safer (less likely to leak memory):

    local circ = display.newCircle(0,0,rad*1.7) circ.fill = paint

ok I will double check and double try. I thought whenever I set the circ to local, it wasn’t registering it down in the other function, local should be file/“class” wide, correct?

edit to add: I’m dense aren’t I? I just need to pass self to he function to get it to work, don’t I? /facepalm