Hello!
I build my Html game into the site and use html5.run. I’m trying to return the data in defold (Json as a string), but the string does not return all and with strange characters at the end.
At the top of the line, which should return, from below, as it takes a defold. I made this line much longer - the result is the same - a few last characters are replaced
lua code
html5.run("callApi('".. self.method.."', { "..self.params_str_html5.." }, "..self.key..");")
local timer_id = nil
timer_id = timer.delay(0.1, true, function()
local response = html5.run("vkCallback("..self.key..")")
if response ~= '' then
timer.cancel(timer_id)
print(response)
local jd = json.decode(response)
self.cb(jd.response)
end
end)
js code
var api_responses = [];
function callApi(method, params, key) {
VK.api(method, params, function (data) {
api_responses[key] = JSON.stringify(data);
});
}
function vkCallback(key) {
var response = '';
if (api_responses[key]) {
response = api_responses[key];
delete api_responses[key];
console.log(response);
}
return response;
}
If I try to get a string directly, I get an error and the app is stopped
-- lua
local test_resp = html5.run('getStartParameters()')
print(test_resp)
-- js
function getStartParameters() {
return '[{"id":35917273,"first_name":"Любовь","last_name":"Чижевская","sex":1,"photo_50":"https://pp.userapi.com/c824603/v824603160/145e9d/WF05WuJXMvE.jpg?ava=1","photo_100":"https://pp.userapi.com/c824603/v824603160/145e9c/oa-4TJpv55Q.jpg?ava=1"},{"id":59262819,"first_name":"Витя","last_name":"Гиль","sex":2,"photo_50":"https://pp.userapi.com/c834200/v834200115/1783c4/N5vHRfxXhqM.jpg?ava=1","photo_100":"https://pp.userapi.com/c834200/v834200115/1783c3/gcTnQ0qwRBs.jpg?ava=1"}]';
}
I will be grateful for your advice on solving this problem!
Thank you!