Also, if that’s your code, it’s not going to work because the init() and the .load() functions are asynchronous.
While this tutorial uses AdMob for its code, the text and explanation on how ads work covers all add providers. Please take the time and read this closely and try to get the general concepts from it.
The KIDOZ documentation says: “kidoz.init() initializes the KIDOZ plugin. Once initialized, you can load an ad using kidoz.load() and subsequently show it via kidoz.show().” So I used both…
Secondly, I’ve read the documentation you’ve sent. It talks about appID and adUnitID which I have no idea where to get from. I’ve searched throughout my dashboard in kidoz and added my application details to the dashboard, and still unable to find appID and adUnitID. And the KIDOZ documentation also doesn’t mention anything about appID and adUnitID.
The particular link that Rob provided wasn’t explicitly for Kidoz.
The important piece of advice that Rob gave you was that the functions are asynchronous. Asynchronous functions are something that are started but they won’t finish before the program continues on. So, when you call .init(), the plugin will start initialising but it will take some time. However, you call .load() a few rows later, i.e. on the same frame as the .init() function. This means that the plugin will not have had sufficient time to initialise and therefore you cannot yet use .load().
For simplicity sake, think of the following scenario:
A synchronous function : You come to a door and open it. You then step inside and close the door behind you.
> Everything happens in a perfect sequence and you don’t need to wait for anything to finish.
An asynchronousfunction (WRONG): You come to a door and knock for someone to come open it. No one has yet opened the door, so it remains closed, but you you step inside and close the door behind you.
> This obviously can’t happen because the door is locked and you can’t pass through.
An asynchronousfunction (CORRECT): You come to a door and knock for someone to come open it. You wait until someone comes and opens the door. Then you step inside and close the door behind you.
> You waited for the function to finish and now you were able to carry out the rest.
How do you know when your plugin has been initialised? That’s what the “init” phase is for in your sample code.
if ( event.phase == "init" ) then -- Successful initialization print( event.provider ) end
I’m going to suggest you go back an re-read the tutorial, but do not get hung up on the code. Read the concepts. The code is for AdMob and AdMob and Kidoz will use different names for various ID’s and such. Their API’s will be different.
The concepts about when to init, when to load, and when to show are explained in the tutorial.
The key is certainly understanding asynchronous vs. synchronous functions. The init() function returns immediately and finishes initialization in the background. In your code, because your .load() function is the very next statement, runs before .init() finishes, so it fails. You’re next line of code is .show(), but because .load() is also asynchronous, it fails because the ad isn’t loaded (and there’s a good chance .init() isn’t even finished yet.
Are you testing on a device or just the simulator (you have to be testing on a real device)?
Are you capturing the results of that device’s console log with “adb logcat”? If so what messages are showing up in that log file (this is where your “print()” statements will show up.
It works now (YAY!). Initialization is being called. Yes. But not successful initialization… I guess I’ll need to play around for a bit more time till I get it…
My main.lua:
----------------------------------------------------------------------------------------- -- -- main.lua -- ----------------------------------------------------------------------------------------- local ccx,ccy,acw,ach,cw,ch = display.contentCenterX, display.contentCenterY, display.actualContentWidth, display.actualContentHeight, display.contentWidth, display.contentHeight kidoz = require( "plugin.kidoz" ) local myText = display.newText( "Game loaded", ccx, 20, native.systemFont, 20 ) myText:setFillColor(1) function adListener( event ) local json = require( "json" ) print("Ad event: ") print( json.prettify( event ) ) local myText = display.newText( "Initialization called", ccx, 50, native.systemFont, 20 ) myText:setFillColor(1,0.5,0) if ( event.phase == "init" ) then -- Successful initialization print( event.provider ) local myText = display.newText( "Initialization successful!", ccx, 80, native.systemFont, 20 ) myText:setFillColor(1,1,0) --Load KIDOZ Ad kidoz.load( "interstitial" ) elseif ( event.phase == "loaded" ) then -- The ad was successfully loaded local myText = display.newText( "Load successful! \n Ready to show.", ccx, 150, native.systemFont, 20 ) myText:setFillColor(0,1,0) transition.blink(myText, { time=2000 }) --Show KIDOZ Ad kidoz.show( "interstitial" ) end end -- Initialize the KIDOZ plugin kidoz.init( adListener, { publisherID="13892", securityToken="3QDf5Nk2q4u1n48UhHfRCC5aPDMMPIhH"} )
If you’re still having problems, you’re going to have to figure out how to install adb and run “adb logcat” and capture those print statements. They contain critical information about what’s going on with your setup.
There are console log apps you can install on your device if you can’t get adb installed and working.
Without that information, no one can help you. I guess you could assign the output from json.prettify(event) into your myText.text
Also, if that’s your code, it’s not going to work because the init() and the .load() functions are asynchronous.
While this tutorial uses AdMob for its code, the text and explanation on how ads work covers all add providers. Please take the time and read this closely and try to get the general concepts from it.
The KIDOZ documentation says: “kidoz.init() initializes the KIDOZ plugin. Once initialized, you can load an ad using kidoz.load() and subsequently show it via kidoz.show().” So I used both…
Secondly, I’ve read the documentation you’ve sent. It talks about appID and adUnitID which I have no idea where to get from. I’ve searched throughout my dashboard in kidoz and added my application details to the dashboard, and still unable to find appID and adUnitID. And the KIDOZ documentation also doesn’t mention anything about appID and adUnitID.
The particular link that Rob provided wasn’t explicitly for Kidoz.
The important piece of advice that Rob gave you was that the functions are asynchronous. Asynchronous functions are something that are started but they won’t finish before the program continues on. So, when you call .init(), the plugin will start initialising but it will take some time. However, you call .load() a few rows later, i.e. on the same frame as the .init() function. This means that the plugin will not have had sufficient time to initialise and therefore you cannot yet use .load().
For simplicity sake, think of the following scenario:
A synchronous function : You come to a door and open it. You then step inside and close the door behind you.
> Everything happens in a perfect sequence and you don’t need to wait for anything to finish.
An asynchronousfunction (WRONG): You come to a door and knock for someone to come open it. No one has yet opened the door, so it remains closed, but you you step inside and close the door behind you.
> This obviously can’t happen because the door is locked and you can’t pass through.
An asynchronousfunction (CORRECT): You come to a door and knock for someone to come open it. You wait until someone comes and opens the door. Then you step inside and close the door behind you.
> You waited for the function to finish and now you were able to carry out the rest.
How do you know when your plugin has been initialised? That’s what the “init” phase is for in your sample code.
if ( event.phase == "init" ) then -- Successful initialization print( event.provider ) end
I’m going to suggest you go back an re-read the tutorial, but do not get hung up on the code. Read the concepts. The code is for AdMob and AdMob and Kidoz will use different names for various ID’s and such. Their API’s will be different.
The concepts about when to init, when to load, and when to show are explained in the tutorial.
The key is certainly understanding asynchronous vs. synchronous functions. The init() function returns immediately and finishes initialization in the background. In your code, because your .load() function is the very next statement, runs before .init() finishes, so it fails. You’re next line of code is .show(), but because .load() is also asynchronous, it fails because the ad isn’t loaded (and there’s a good chance .init() isn’t even finished yet.
Are you testing on a device or just the simulator (you have to be testing on a real device)?
Are you capturing the results of that device’s console log with “adb logcat”? If so what messages are showing up in that log file (this is where your “print()” statements will show up.
It works now (YAY!). Initialization is being called. Yes. But not successful initialization… I guess I’ll need to play around for a bit more time till I get it…
My main.lua:
----------------------------------------------------------------------------------------- -- -- main.lua -- ----------------------------------------------------------------------------------------- local ccx,ccy,acw,ach,cw,ch = display.contentCenterX, display.contentCenterY, display.actualContentWidth, display.actualContentHeight, display.contentWidth, display.contentHeight kidoz = require( "plugin.kidoz" ) local myText = display.newText( "Game loaded", ccx, 20, native.systemFont, 20 ) myText:setFillColor(1) function adListener( event ) local json = require( "json" ) print("Ad event: ") print( json.prettify( event ) ) local myText = display.newText( "Initialization called", ccx, 50, native.systemFont, 20 ) myText:setFillColor(1,0.5,0) if ( event.phase == "init" ) then -- Successful initialization print( event.provider ) local myText = display.newText( "Initialization successful!", ccx, 80, native.systemFont, 20 ) myText:setFillColor(1,1,0) --Load KIDOZ Ad kidoz.load( "interstitial" ) elseif ( event.phase == "loaded" ) then -- The ad was successfully loaded local myText = display.newText( "Load successful! \n Ready to show.", ccx, 150, native.systemFont, 20 ) myText:setFillColor(0,1,0) transition.blink(myText, { time=2000 }) --Show KIDOZ Ad kidoz.show( "interstitial" ) end end -- Initialize the KIDOZ plugin kidoz.init( adListener, { publisherID="13892", securityToken="3QDf5Nk2q4u1n48UhHfRCC5aPDMMPIhH"} )
If you’re still having problems, you’re going to have to figure out how to install adb and run “adb logcat” and capture those print statements. They contain critical information about what’s going on with your setup.
There are console log apps you can install on your device if you can’t get adb installed and working.
Without that information, no one can help you. I guess you could assign the output from json.prettify(event) into your myText.text