String.gmatch() + HTML5 mobile = crash?

Hello everyone,

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.

Please share the exact line of code which causes a crash!

1 Like

Sorry for the late reply… I’ve been sick as hell recently. :face_with_thermometer:


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))
	return numbers

When I used game properties, the game work fine on both desktop and mobile."region_id", 0)"local_level_id", 0)

But when (for some reason) I want to use the function mentioned above instead, the game seems to crash (on mobile only).

local list_ids = extractNumbersFromString(tostring(go.get_id()))|
self.region_id, self.local_level_id = list_ids[1], list_ids[2]|

go.get_id() is hash. You can’t get name from it. This work only in debug build.
If you build release build and try it on desktop, it also will crash

1 Like

Hey @d954mas thanks for your answer!

Indeed, same result on desktop in “release” mode… :frowning_face_with_open_mouth:

I thought that using the tostring() function would turn it into a regular string, but looks like it doesn’t work that way.

Is there another way to use the object id or is it impossible?

(Note that in my case it’s not a blocking issue, I can still use the game properties but it would be less convenient since I have many objects)

“Is there another way to use the object id or is it impossible?”

The question is, what do you wish to do with it?

1 Like

I have “path dots” between my levels. These dots light up progressively as players complete levels.

In the editor, I create and position these dots one by one to ensure they align with the roads exactly as expected:

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")