Hi, I am Maxi from QkyGames Studio. We are just starting using defold and we are already making some games, but we need to use this API to show ads in our games, please check it here: http://www.gamedistribution.com/Api/1
Is it possible use this API to show ads in html5 games? For mobile games we use Appnext and for that I’ve already found a library here in the forums.
they have fullscreen ads for games, video or image.
I try make this in my game:
function webview_callback(self, webview_id, request_id, type, data)
if type == webview.CALLBACK_RESULT_URL_OK then
-- the page is now loaded, let's show it
webview.set_visible(webview_id, 1)
elseif type == webview.CALLBACK_RESULT_URL_ERROR then
print("Failed to load url: " .. data["url"])
print("Error: " .. data["error"])
elseif type == webview.CALLBACK_RESULT_EVAL_OK then
print("Eval ok. Result: " .. data['result'])
elseif type == webview.CALLBACK_RESULT_EVAL_ERROR then
print("Eval not ok. Request # " .. request_id)
end
end
function init(self)
local webview_id = webview.create(webview_callback)
end
but I get this error: main/gd_ads.script:16: attempt to index global 'webview' (a nil value) stack traceback:
There is no way to directly communicate between your game and scripts running on the page yet unfortunately… you could communicate with a server but that’s more messy. I wish there was some way to send messages back and forth between the game and a script on the page.
I am not sure how this works on HTML5 builds - if it checks the canvas focus or window focus - but you could try it for detecting if game is out of focus http://www.defold.com/ref/window/
You could make the game fullscreen, and then have a permanent rotating banner ad anchored at the bottom middle above the canvas.
Are you zipping all of the files together and not just the index on its own? You should contact them to figure out why the game is not uploading properly.
so, I can add a setInterval() function in my index to check every time if my localstorage is changed, so i can check if ads = 1 call function showad() and set ads = 0 in localstorage, the question is, how can create a localstorage in defold to read and set from my index.html (javascript), the game is HTML5.
Have your Defold game and Javascript constantly check a file for any communication. You could set up a method of message passing between the game and the local Javascript files with this method. Each side can have their own inbox which they can clear, and put messages into the other’s inbox. Or share a file. I’m not sure what would be ideal in this case.
From there, you can then do any logic you need.
You can use Lua io save/load functions.
Defold uses IndexedDB API for dealing with a kind of filesystem on HTML5 builds. It uses the “/data” database version 21. If you used sys.get_save_file(“html5_inbox”, “html5_inbox_state”) it would be the text of a path “/data/.html5_inbox/html5_inbox_state” so in JS you would connect to the “/data” db and then access the “/data/.html5_inbox/html5_inbox_state” key to be able to load that file.
Here’s an indexedDB example although as the comments there say it may be a better idea to use a pre-made solution and not work with the indexedDB api directly. I have not experimented with all of these things together yet so I can’t say for sure how to make this all work for sure but if you time give it a try.
I want to make an example but I do not have the spare time right now. This should be possible to do though. Again, great idea! It will probably be a workable html5 game to browser JS communication problem solution.