Threshold detection help

In my app there are three thresholds each with a different multiplier assigned to it.

So when you shoot the bullet depending on where the balloon is popped, that is what the score will be multiplied by. 

Code for thresholds:

thresholds[1]=display.newRect(0,0,768,200) --This is the region with 5x multiplier    thresholds[2]=display.newRect(0,0,768,60)  --This is the region with 10x multiplier    thresholds[3]=display.newRect(0,0,768,260) --This is the region with 1x multiplier    thresholds[1]:setFillColor(math.random(0, 255)/255, math.random(0, 255)/255, math.random(0, 255)/255)    thresholds[2]:setFillColor(math.random(0, 255)/255, math.random(0, 255)/255, math.random(0, 255)/255)    thresholds[3]:setFillColor(math.random(0, 255)/255, math.random(0, 255)/255, math.random(0, 255)/255)    thresholds[1].x=\_W/2    thresholds[1].y=\_H-(thresholds[1].height+112)    thresholds[2].x=\_W/2    thresholds[2].y=(\_H-thresholds[1].height-243)    thresholds[3].x=\_W/2    thresholds[3].y=\_H+(thresholds[3].height\*.5-210)    txt1=display.newText("1x",500, 500, native.systemFontBold, 30 )        txt1.x=\_W-50        txt1.y=\_H-150    txt2=display.newText("5x",100, 200, native.systemFontBold, 30 )        txt2.x=\_W-50        txt2.y=\_H-350    txt3=display.newText("10x",100, 200, native.systemFontBold, 30 )        txt3.x=\_W-50        txt3.y=\_H-452

To assign the multiplier for each threshold i do this:

 for i=1,#thresholds do     thresholds[i].boundary=math.ceil(thresholds[i].y+(thresholds[i].height\*.5))                   if (i==3) then         thresholds[i].multiplier=1         elseif (i==2) then          thresholds[i].multiplier=10         else         thresholds[i].multiplier=5          end      end

The multiplier for my 3rd and 1st threshold (so the 1x and 5x multiplier) work but when i pop a balloon in the x10 region/threshold[2] the multiplier is 1 not 10. Why is this?

Debugging this seems not especially worthwhile. Why don’t you simply assign the multiplier values when you are creating the threshold objects?

That doesn’t work due to my other code for the balloons which check the thresholds.boundary property in order to assign the value. That is why i included the boundary checking vs, just regularly assigning a multiplier. Do you know any other solutions because that doesn’t work.

Could you not just assign the multiplier based on the Y position of the balloon?

Quick (unchecked) example…

if balloon.y \< foo then -- foo = bottom edge of top area multiplier = 10 else if balloon.y \> foo2 then -- foo2 = bottom edge of middle area multiplier = 1 else multiplier = 5 end

I cannot do anything that omits the boundaries. Here is why, this is the code for how I make the balloon check which threshold it is in.

local function checkThreshold(obj1,obj2 ) &nbsp; &nbsp;if (obj1 and obj2) then &nbsp; &nbsp; &nbsp; if(obj1.y\<obj2[1].boundary and obj1.y \> obj2[2].boundary) then &nbsp; &nbsp; &nbsp; if (obj1.multiplier==nil) then &nbsp; &nbsp; &nbsp; end &nbsp; &nbsp; &nbsp; obj1.multiplier=obj2[1].multiplier&nbsp; &nbsp; &nbsp; &nbsp; elseif(obj1.y\<obj2[2].boundary and obj1.y\>obj2[3].boundary) then &nbsp; &nbsp; &nbsp; if(obj1.multiplier==obj2[1].multiplier) then &nbsp; &nbsp; &nbsp; obj1:flash() &nbsp; &nbsp; &nbsp; end &nbsp; &nbsp; &nbsp; &nbsp; obj1.multiplier=obj2[2].multiplier &nbsp; &nbsp; &nbsp; elseif(obj1.y\<obj2[3].boundary and obj1.y\>-10) then &nbsp; &nbsp; &nbsp; &nbsp; if(obj1.multiplier==obj2[2].multiplier) then &nbsp; &nbsp; &nbsp; &nbsp; obj1:flash() &nbsp; &nbsp; &nbsp; &nbsp; end &nbsp; &nbsp; &nbsp; &nbsp; obj1.multiplier=obj2[3].multiplier &nbsp; &nbsp; &nbsp; &nbsp; elseif(obj1.y\<-10) then &nbsp; &nbsp; &nbsp; &nbsp; if(obj1.timer) then &nbsp; &nbsp; &nbsp; &nbsp; obj1:pop() &nbsp; &nbsp; &nbsp; &nbsp; end &nbsp; &nbsp; &nbsp; &nbsp; end &nbsp; &nbsp; &nbsp;end end

Debugging this seems not especially worthwhile. Why don’t you simply assign the multiplier values when you are creating the threshold objects?

That doesn’t work due to my other code for the balloons which check the thresholds.boundary property in order to assign the value. That is why i included the boundary checking vs, just regularly assigning a multiplier. Do you know any other solutions because that doesn’t work.

Could you not just assign the multiplier based on the Y position of the balloon?

Quick (unchecked) example…

if balloon.y \< foo then -- foo = bottom edge of top area multiplier = 10 else if balloon.y \> foo2 then -- foo2 = bottom edge of middle area multiplier = 1 else multiplier = 5 end

I cannot do anything that omits the boundaries. Here is why, this is the code for how I make the balloon check which threshold it is in.

local function checkThreshold(obj1,obj2 ) &nbsp; &nbsp;if (obj1 and obj2) then &nbsp; &nbsp; &nbsp; if(obj1.y\<obj2[1].boundary and obj1.y \> obj2[2].boundary) then &nbsp; &nbsp; &nbsp; if (obj1.multiplier==nil) then &nbsp; &nbsp; &nbsp; end &nbsp; &nbsp; &nbsp; obj1.multiplier=obj2[1].multiplier&nbsp; &nbsp; &nbsp; &nbsp; elseif(obj1.y\<obj2[2].boundary and obj1.y\>obj2[3].boundary) then &nbsp; &nbsp; &nbsp; if(obj1.multiplier==obj2[1].multiplier) then &nbsp; &nbsp; &nbsp; obj1:flash() &nbsp; &nbsp; &nbsp; end &nbsp; &nbsp; &nbsp; &nbsp; obj1.multiplier=obj2[2].multiplier &nbsp; &nbsp; &nbsp; elseif(obj1.y\<obj2[3].boundary and obj1.y\>-10) then &nbsp; &nbsp; &nbsp; &nbsp; if(obj1.multiplier==obj2[2].multiplier) then &nbsp; &nbsp; &nbsp; &nbsp; obj1:flash() &nbsp; &nbsp; &nbsp; &nbsp; end &nbsp; &nbsp; &nbsp; &nbsp; obj1.multiplier=obj2[3].multiplier &nbsp; &nbsp; &nbsp; &nbsp; elseif(obj1.y\<-10) then &nbsp; &nbsp; &nbsp; &nbsp; if(obj1.timer) then &nbsp; &nbsp; &nbsp; &nbsp; obj1:pop() &nbsp; &nbsp; &nbsp; &nbsp; end &nbsp; &nbsp; &nbsp; &nbsp; end &nbsp; &nbsp; &nbsp;end end