Thank you Naomi. I think the IAP is working. Following the indications of D3mac. My app consists of a initial screen with four images corresponding to the four levels. I’m tryng to implement something that send to the level in the case is purchased and send to the buy screen in the other case. But still having troubles with that. I’m tryng to create a file for the case “purchased” in the buy screen and then to read it in the menu and depends of that send to each screen but doesn’t works. Here I post a part of the code if you could help me. Thank you!
Here is the part to create the file:
[code]function transactionCallback( event )
if event.transaction.state == “purchased” then
savePurchase(“com.bigteethmedia.funkyinstruments.TheSportsAlley”)
elseif event.transaction.state == “purchased” then
– escribe
local filePath = system.pathForFile( “datas.txt”, system.DocumentsDirectory )
print( “Creating file…” )
– create file b/c it doesn’t exist yet
file = io.open( filePath, “w” )
file:write( “Purchased\n” )
io.close( file )
–os.remove( filePath )
elseif event.transaction.state == “restored” then
savePurchase(“com.bigteethmedia.funkyinstruments.TheSportsAlley”)
elseif event.transaction.state == “cancelled” then
elseif event.transaction.state == “failed” then
infoString = "Transaction failed, type: ", event.transaction.errorType, event.transaction.errorString
local alert = native.showAlert("Failed ", infoString,{ “OK” })
else
infoString = “Unknown event”
local alert = native.showAlert("Unknown ", infoString,{ “OK” })
end
store.finishTransaction( event.transaction )
end
[/code]
And here is the complete code in the menu to change the screen depending on is purchased or not
module(..., package.seeall)
system.activate("multitouch")
function new()
local localGroup = display.newGroup()
local background = display.newImageRect("portada.png", \_W, \_H)
background:setReferencePoint(display.CenterReferencePoint)
background.x = \_W / 2
background.y = \_H / 2
local play = display.newImage("tolevel.png")
play:setReferencePoint(display.TopLeftReferencePoint)
play.x = 5
play.y = 4
play.scene = "level1"
local play2 = display.newImage("tolevel.png")
play2:setReferencePoint(display.TopLeftReferencePoint)
play2.x = 246
play2.y = 5
play2.scene = "level2"
local filePath = system.pathForFile( "datas.txt", system.DocumentsDirectory )
local file = io.open( filePath, "r" )
if file then
-- read all contents of file into a string
local contents = file:read( "\*a" )
--print( "Contents of " .. filePath )
print( contents )
io.close( file )
--end
if not contents == "Purchased" then
local playblock2 = display.newImage("tocompras.png")
playblock2:setReferencePoint(display.TopLeftReferencePoint)
playblock2.x = 5
playblock2.y = 4
playblock2.scene = "levelcompras"
local play3 = display.newImage("tolevel.png")
play3:setReferencePoint(display.TopLeftReferencePoint)
play3.x = 5
play3.y = 163
play3.scene = "level3"
local filePath = system.pathForFile( "datas.txt", system.DocumentsDirectory )
local file = io.open( filePath, "r" )
if file then
-- read all contents of file into a string
local contents = file:read( "\*a" )
print( "Contents of " .. filePath )
print( contents )
io.close( file )
--end
if not contents == "Purchased" then
local playblock3 = display.newImage("tocompras.png")
playblock3:setReferencePoint(display.TopLeftReferencePoint)
playblock3.x = 5
playblock3.y = 4
playblock3.scene = "levelcompras"
local play4 = display.newImage("tolevel.png")
play4:setReferencePoint(display.TopLeftReferencePoint)
play4.x = 246
play4.y = 163
play4.scene = "level4"
local filePath = system.pathForFile( "datas.txt", system.DocumentsDirectory )
local file = io.open( filePath, "r" )
if file then
-- read all contents of file into a string
local contents = file:read( "\*a" )
print( "Contents of " .. filePath )
print( contents )
io.close( file )
--end
if not contents == "Purchased" then
local playblock4 = display.newImage("tocompras.png")
playblock4:setReferencePoint(display.TopLeftReferencePoint)
playblock4.x = 5
playblock4.y = 4
playblock4.scene = "levelcompras"
end
function changeScene(event)
if(event.phase == "ended") then
director:changeScene("level1", "fade")
end
end
function changeScenes(event)
if(event.phase == "ended") then
director:changeScene("level2", "fade")
end
end
function changeScenes3(event)
if(event.phase == "ended") then
director:changeScene("level3", "fade")
end
end
function changeScenes4(event)
if(event.phase == "ended") then
director:changeScene("level4", "fade")
end
end
function changeScenesBlock2(event)
if(event.phase == "ended") then
director:changeScene("levelcompras", "fade")
end
end
function changeScenesBlock3(event)
if(event.phase == "ended") then
director:changeScene("levelcompras", "fade")
end
end
function changeScenesBlock4(event)
if(event.phase == "ended") then
director:changeScene("levelcompras", "fade")
end
end
localGroup:insert(background)
localGroup:insert(play)
localGroup:insert(play2)
localGroup:insert(play3)
localGroup:insert(play4)
localGroup:insert(playblock2)
localGroup:insert(playblock3)
localGroup:insert(playblock4)
play:addEventListener("touch", changeScene)
play2:addEventListener("touch", changeScenes)
play3:addEventListener("touch", changeScenes3)
play4:addEventListener("touch", changeScenes4)
playblock2:addEventListener("touch", changeScenesBlock2)
playblock3:addEventListener("touch", changeScenesBlock3)
playblock4:addEventListener("touch", changeScenesBlock4)
return localGroup
end
Naomi and D3mac. Thanks for your interest and your time in helping [import]uid: 81363 topic_id: 16336 reply_id: 61869[/import]