Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

showAdFromBottom()

edited November 2014 in General Posts: 136

What would the proper usage of showAdFromBottom be on a portrait app? I keep getting error messages stating I'm trying to compare it with a nil value. Anyone know what it is I'm doing wrong? I have been just putting ~ showAdFromBottom() ~ whenever I want the ad to show, is this incorrect?

Comments

  • edited November 2014 Posts: 300

    This is how I use the ads:

    About 2/3 of the way down, I have 2 if statements that are my collision detection (one for ship hitting walls, and other for ship hitting asteroids), both cause the game to switch to gameState=2 which is the try again screen. That is where I call the ads with showAdFromBottom(). Then the try again screen goes to the main menu and I leave ads running, then when you press play button, it switches to gameState=1 which is the main game screen and I call hideAd() to hide the ads when the actual game is being played (about 1/3 of the way down the code).

    So it makes the ads show during the try again screen and main menu screen, but hides them when playing the game.

    You may want to check your spelling and capitalization. I had a problem where I had hideAds() in the code instead of hideAd() and got a similar error.

    It may also be from trying to call another Ad when one is already being shown, so maybe try to do hideAd() right before showAdFromBottom().

    For the record the ad codes will only work in Xcode, if you are trying to use them in codea it won't work and will give errors because there is no actual function in Codea for showAdFromBottom()/hideAd().


    displayMode(FULLSCREEN) supportedOrientations(PORTRAIT_ANY) function setup() ast={} ship=readImage("Space Art:Red Ship") asteroid=readImage("Space Art:Asteroid Large") astFreq=1.5 astSpeed=-9 score=0 -- starting score timer=0 rectMode(CENTER) if readLocalData("HS")== nil then saveLocalData("HS", 0) end music("A Hero's Quest:Battle",true,.5) gameState=0 font("Futura-CondensedExtraBold") fontSize(64) fill(0, 255, 0, 255) shipX=WIDTH/2 shipY=HEIGHT/4 end function spawn() table.insert(ast,vec2(math.random(96,WIDTH-96),1152)) end function draw() if gameState==0 then background(0, 0, 0, 255) text("PLAY",WIDTH/2,HEIGHT/2) if CurrentTouch.state==BEGAN then if CurrentTouch.x>WIDTH/2-256 and CurrentTouch.x<WIDTH/2+256 and CurrentTouch.y>HEIGHT/2-128 and CurrentTouch.y<HEIGHT/2+128 then gameState=1 hideAd() end end end if gameState==1 then background(0, 0, 0, 255) pushStyle() text("Score: "..score, WIDTH/2, HEIGHT/1.2) popStyle() for a,b in pairs(ast) do sprite(asteroid,b.x,b.y,192,256) b.y=b.y+astSpeed end timer=timer+DeltaTime if timer>astFreq then spawn() spawn() spawn() timer=0 end for a,b in pairs(ast) do if b.y<-128 then table.remove(ast,a) score=score+10 end end if CurrentTouch.x <= WIDTH / 2 and CurrentTouch.state ~= ENDED and CurrentTouch.state ~= CANCELLED then shipX=shipX-12 end if CurrentTouch.x>WIDTH/2 and CurrentTouch.state ~= ENDED and CurrentTouch.state ~= CANCELLED then shipX=shipX+12 end sprite(ship,shipX,shipY,64,96) for a,b in pairs(ast) do if b.y-96<=shipY+48 and b.y+160>=shipY-48 and b.x-96<=shipX+32 and b.x+96>=shipX-32 then gameState=2 showAdFromBottom() end end if shipX-32<0 or shipX+32>WIDTH then gameState=2 showAdFromBottom() end end if gameState==2 then background(0, 0, 0, 255) text("RETRY",WIDTH/2,HEIGHT/4) if score > readLocalData("HS") then saveLocalData("HS", score) end text("Score: "..score, WIDTH/2,HEIGHT/1.2) text("HighScore: "..readLocalData("HS"),WIDTH/2,HEIGHT/2) if CurrentTouch.state==BEGAN then if CurrentTouch.x>WIDTH/2-128 and CurrentTouch.x<WIDTH/2+128 and CurrentTouch.y>HEIGHT/4-64 and CurrentTouch.y<HEIGHT/4+64 then score=0 gameState=0 shipX=WIDTH/2 for i,t in pairs(ast) do ast[i]= nil end end end end end
  • edited November 2014 Posts: 136

    @ Crumble , do the ads work with iPhone?

    edit: figured it out

Sign In or Register to comment.