While my game works properly on desktop, I’m encountering crashes on mobile devices (HTML5).
After isolating the problem, it seems that the string.gmatch() function seems to be causing the issue. The game works as intended on mobile HTML5 when I avoid using this function, so…
Is there a known problem related to this function specifically on mobile devices?
PS: I can provide more context if it seems strange to you.
Sorry for the late reply… I’ve been sick as hell recently.
Anyway!
Here is the function that seems to make the game crash on mobile (html5) but not on desktop.
----------------------------------
-- Extracts the numeric values and returns them as an array.
----------------------------------
function extractNumbersFromString(pString)
local numbers = {}
for char in string.gmatch(pString,"(%d+)") do
table.insert(numbers, tonumber(char))
end
return numbers
end
When I used game properties, the game work fine on both desktop and mobile.
Consequently, I have to set the game object properties by hand. It’s not a hard task at all, but it can be tedious when there are many levels, and many dots for each level. Although this isn’t a critical issue, I decided to replace the object properties with a function.
I thought that I could turn the hash (ex: “hash: [/WM_region_1/path_dot_5_2]” via tostring()) into a regular string and then retrieve the variables (1, 5 & 2 in that case), but it doesn’t seem possible. I used the same function in the regions & levels scripts (even though it was less necessary since there are fewer levels than path dots between levels).
Well, as you can see it’s mainly for convenience rather than a necessity. However, using this function could help me save time. Is there another way to do it?
Can’t you read those script properties using go.get()? If you have the game object id (the one you are trying to convert to a string) then use that to construct a URL and read the properties on the script:
local id = some_id -- hash: [/WM_region_1/path_dot_5_2]
local url = msg.url(nil, id, "WM_path_dot")
local region = go.get(url, "region_id")
local local_level_id = go.get(url, "local_level_id")
local path_dot_id = go.get(url, "path_dot_id")