Implement Gamedistribution ads using webview

I remove the index.html from defold and game.project work fin with ctrl+b but for html5 launch get the same error

Are you trying to open a file which doesnā€™t exist yet? You should check if it exists first in the Defold script before doing the other code.

function file_exists(name)
   local f=io.open(name,"r")
   if f~=nil then io.close(f) return true else return false end
end

Does the file you are trying to load show up in the filesystem in the Chrome console?

I remove all code, remove __htmlLaunchDir, all but get the same error, weird.
I export the game and upload to my local server and work, but build and launc html5 from defold not is working.

now is working, this is very crazy lol

Wait for the clean and standalone example. There are a few things which I did that are too messy to use / cause it to break / donā€™t work at all right yet. Iā€™ve already fixed a few major issues so far but itā€™s really late for me so I must stop now for real.

If you want ads very easily, consider using giftgaming which is completely SDK-less

1 Like

this is my code in defold:

local path = sys.get_save_file("html5_inbox", "data.json")

-- set content of a file on the filesystem
local html5_data = "1"

function write_file(file, data)
local file = io.open(path, "w")
file:write(data)
file:close()
end

function read_file(file)
local f = io.open(path, "r")
local content = f:read("*all")
f:close()
return content
end

function update()
	print(read_file(path))
end

in the console always get nil, but I should have ā€œtest data hereā€?

your index:

var test_data_array = {timestamp: {}, mode: 33206};
test_data_array.contents = stringToUint("test data here"); // this is obviously not JSON, 
store.put(test_data_array, "/data/.html5_inbox/data.json")

The JS needs to be modified too to make it work. Donā€™t need to be using atbo / btoa, they both need to be removed to work with Defoldā€™s data. There are other changes which need to be made too but I canā€™t do right now.

	function stringToUint(string) {
		var string = unescape(encodeURIComponent(string)),
			charList = string.split(''),
			uintArray = [];
		for (var i = 0; i < charList.length; i++) {
			uintArray.push(charList[i].charCodeAt(0));
		}
		return new Uint8Array(uintArray);
	}

	function uintToString(uintArray) {
		var encodedString = String.fromCharCode.apply(null, uintArray),
			decodedString = decodeURIComponent(escape(encodedString));
		return decodedString;
	}

No problem, Pkeod, thank you very much for your help! you are the best!

2 Likes

Hi,

new news? I am very anxious to use defold :slight_smile:

Maxi.

1 Like

Iā€™ll spend some more time on this later today. Will post when Iā€™m done with whatever I have.

Edit: Didnā€™t have the time, will early tomorrow.

1 Like

I fixed the last bug, but still not ready to upload. Iā€™ll make a new thread for the example, and post here when ready hopefully will have time tomorrow to finish. Too busy with work and lifeā€¦

3 Likes

Very goods news :slight_smile:

I thought I had it fixed, but I only tested with static data. Dynamic data shows that apparently Defold (via emscripten) only loads from the indexeddb once, and then works with a virtual file system cache after. I have some ideas on how to deal with it, but I am severely low on time right now. It may require us slightly modifying the HTML5 runtime. There may be a proper way in Defold to get it to load from the actual data store instead of virtual filesystem cache that I donā€™t know about. Iā€™m confident itā€™s possible to solve, but would have to read more of the source and docs more to understand how things really work. I can do this later, but not right now. Anyone else interested in it should give it a shot. Maybe there is a simple fix that I didnā€™t see.

https://kripken.github.io/emscripten-site/docs/api_reference/Filesystem-API.html

html5_inbox.zip (17.7 KB)

2 Likes

@sven has a good knowledge of the HTML5 implementation of the file system. He should be able to provide more information.

Just so people know there is more information here, I have not had time yet to try more, but anyone else is welcome to look into it.

1 Like