Why project is working in Defold but after export to mobile device, some things don't work? [SOLVED]

The thing is, I exported my project to my mobile device (in debug mode) and everything works fine, except a scroll list. While it worked perfectly on my computer in Defold editor, on the mobile device, whenever I release the scroll list, it disappears. Does anybody know, why is it?
(Maybe it is a question for another topic, but is there any way to see the content from a console when I run the project on a mobile device?)

Thank you for help.


[SOLVED]: I finally found the mistake! It was in function

os.difftime(t2, t1)

I don’t understand why, but this function somehow doesn’t work on older devices, so I replaced this command with just

(t2-t1)

and everything works fine. (By the way, why function os.difftime() even exist?)
Thank you for help anyway!

I recommend you install adb for retrieving the logs from the device:

This is great thing, thank you. But there are no errors in the project, if I understand well, so nothing is printed. So I am where I was…

but is there any way to see the content from a console when I run the project on a mobile device?

You’ll find info from the device, after running your app, via the adb tool.
You’ll have to see there if there are any errors or not.

As for why it wouldn’t run for you, I wonder how do you run it on Android?
Have you bundled the app?
Or are you using the mobile target app?

Yes, I understand, they aren’t there (the errors). I bundled it for Android.

How is this implemented? Can you please share a bit more about the setup you have?

Hm, the scroll list has two functions - you can scroll with it by finger (mouse) or by scroll bar on the right side. When you use the first option, it works fine. But when you want to use the first option, the scroll list follows your finger until you release it from the screen. And in this moment all movable elements disapear from the page (buttons and movable part of scroll bar). I don’t think the mistake is in my code, because the syntax is practically the same for both functions. Here is my game.project settings:

[project]
title = Mobile game

[bootstrap]
main_collection = /main/main.collectionc

[display]
width = 375
height = 666

[osx]
bundle_identifier = com.example.todo

[android]
app_icon_36x36 = /assets/app_icons/icon_36.png
app_icon_48x48 = /assets/app_icons/icon_48.png
app_icon_72x72 = /assets/app_icons/icon_72.png
app_icon_96x96 = /assets/app_icons/icon_96.png
app_icon_144x144 = /assets/app_icons/icon_144.png
app_icon_192x192 = /assets/app_icons/icon_192.png

Everything else is default. Thank you!

The project settings doesn’t look like they would cause any difference in behavior.

This makes me curious about the particular code.
How does the code differ?
We currently have too little info to know what’s causing it.
Either post some code, or perhaps the entire project and we could have a look.

1 Like

I’ll try to select the important parts:

function on_input(self, action_id, action)
if action.released and scroll_by_bar == true then scroll_by_bar = false end
	if action_id == hash("touch") and button_picked ~= true then
		if gui.pick_node(gui.get_node("display"), action.x, action.y) then
			if action.pressed then
				scroll = true
				keep_moving = false
				start_w_pos = gui.get_position(gui.get_node("wordbuttons"..u))
				if not scroll_by_bar then start_h2_pos = gui.get_position(barhorizontal2) ; start_mouse_pos1 = action ; scroll_by_finger = true end
				tim = socket.gettime()*1000
			elseif action.released then 
				if os.difftime(socket.gettime()*1000, tim2) > 100 then sp = 0 else
					end_mouse_pos1 = action
					sp = (math.abs(start_mouse_pos1.y-end_mouse_pos1.y)*(1000/60)/(os.difftime(socket.gettime()*1000, tim)))*60
					if sp < 500 then sp = 500 end
					sp = math.pow((sp-500),1.1)
				end
				keep_moving = true 
			else
				if not stay or stay ~= action.y then stay = action.y tim2 = socket.gettime()*1000 end
			end
		end
	end	
end
function update(self, dt)
	if scroll == true and dont_scroll ~= true then
		local scrolllist_length = 1500050--(10000*gui.get_size(gui.get_node("wordbutton1")).y*0.5+(10000-1)*(140-gui.get_size(gui.get_node("wordbutton1")).y*0.5))+2*(333-240-gui.get_size(gui.get_node("wordbutton1")).y/4)
		if not keep_moving then
			if scroll_by_finger then direction = (self.mouse.y-start_mouse_pos1.y)/math.abs(self.mouse.y-start_mouse_pos1.y) end
			if scroll_by_bar then direction = 1 if q and self.mouse.y > q then direction = -1 end q = self.mouse.y end
			if scroll_by_finger then cont = true ; gui.set_position(barhorizontal2, vmath.vector3(gui.get_position(barhorizontal2).x, start_h2_pos.y-((self.mouse.y-start_mouse_pos1.y)*(480-25))/scrolllist_length, 0)) end
			if scroll_by_bar then 
				if math.abs(self.mouse.y-333) < 227.5 then gui.animate(barhorizontal2, "position", vmath.vector3(gui.get_position(barhorizontal2).x, self.mouse.y-333+12.5,0), gui.EASING_LINEAR, 0.035) 
				elseif self.mouse.y-333 >= 227.5 then gui.animate(barhorizontal2, "position", vmath.vector3(gui.get_position(barhorizontal2).x, 240+0.2,0), gui.EASING_LINEAR, 0.035)
				elseif self.mouse.y-333 <= -227.5 then gui.animate(barhorizontal2, "position", vmath.vector3(gui.get_position(barhorizontal2).x, -215-0.2, 0), gui.EASING_LINEAR, 0.035) end
			end
		end
		whereIam_bar = -(gui.get_position(barhorizontal2).y-240)*(1/455)
		if whereIam_bar <= 0 then 
			gui.set_position(barhorizontal2, vmath.vector3(175, 240, 0)) 
			gui.set_position(gui.get_node("wordbuttons1"), vmath.vector3(0,318,0))
			gui.set_position(gui.get_node("wordbuttons-1"), vmath.vector3(0,-1082,0)) 
			set_buttons_end(-1)
			whereIam_bar = 0 
		end
		if whereIam_bar >= 1 then 
			gui.set_position(barhorizontal2, vmath.vector3(175, -215, 0)) 
			gui.set_position(gui.get_node("wordbuttons1"), vmath.vector3(0,2500,0)) 
			gui.set_position(gui.get_node("wordbuttons-1"), vmath.vector3(0,1100,0))
			set_buttons_end(1)
			whereIam_bar = 1 
		end
		if whereIam_bar > 0 and whereIam_bar < 1 and whereIam_bar + direction > -1 and whereIam_bar + direction < 2 then
			if not keep_moving then
				if scroll_by_finger then
					gui.set_position(gui.get_node("wordbuttons"..u), vmath.vector3(0, start_w_pos.y+(self.mouse.y-start_mouse_pos1.y), 0))
					gui.set_position(gui.get_node("wordbuttons"..-u), vmath.vector3(0, start_w_pos.y+(self.mouse.y-start_mouse_pos1.y)-1400, 0))
				elseif scroll_by_bar then
					gui.set_position(gui.get_node("wordbuttons"..u), vmath.vector3(0, ((scrolllist_length-1400)*whereIam_bar)%724+346,0))
					gui.set_position(gui.get_node("wordbuttons"..-u), vmath.vector3(0, ((scrolllist_length-1400)*whereIam_bar)%724+346-1400,0))
					if u == 1 then c = 0 else c = 1 end
					local num = (10000*whereIam_bar)-(10000*whereIam_bar)%20
					for y = 1,2 do 
						for i = 1,10 do
							if english[num+i] then
								gui.set_text(gui.get_node("word"..(i+c*10)..1), english[num+i])
								gui.set_text(gui.get_node("word"..(i+c*10)..2), pronunciation[num+i])
								gui.set_text(gui.get_node("levelnumberbutton"..(i+c*10)), num+i)
								dots("dot", (i+c*10), num+i)
							end 
						end
						if u == 1 then c = 1 num = num+10 else c = 0 num = num - 10 end
					end
				end
			end	
			
			for i = -1,1,2 do 
				if gui.get_position(gui.get_node("wordbuttons"..i)).y < -1112 then 
					gui.set_position(gui.get_node("wordbuttons"..i), vmath.vector3(0, gui.get_position(gui.get_node("wordbuttons"..-i)).y+1400, 0))
					start_w_pos.y = start_w_pos.y + 1400
					if i == 1 then c = 0 else c = 1 end
					set_buttons(-1, c)
				elseif gui.get_position(gui.get_node("wordbuttons"..i)).y > 2480 and whereIam_bar < 0.99 then 
					gui.set_position(gui.get_node("wordbuttons"..i), vmath.vector3(0, gui.get_position(gui.get_node("wordbuttons"..-i)).y-1400, 0))
					start_w_pos.y = start_w_pos.y - 1400
					if i == 1 then c = 0 else c = 1 end
					set_buttons(1, c)
				end
			end
			
			if keep_moving and scroll_by_finger then --momentum
				gui.set_position(gui.get_node("wordbuttons"..u), gui.get_position(gui.get_node("wordbuttons"..u))+vmath.vector3(0,sp*dt*direction,0))
				gui.set_position(gui.get_node("wordbuttons"..-u), vmath.vector3(0,gui.get_position(gui.get_node("wordbuttons"..u)).y-1400,0))
				gui.set_position(barhorizontal2, vmath.vector3(gui.get_position(barhorizontal2).x, gui.get_position(barhorizontal2).y-((sp*dt*direction)*(480-gui.get_size(barhorizontal2).y/8))/scrolllist_length, 0)) 
				sp = sp/1.02 if math.abs(sp) < 20 then sp = 0 scroll_by_finger = false keep_moving =  false scroll = false end
			end
		end
	end
end
function set_buttons(direction, c)
	if scroll_by_finger then u = -u end
	for i = 1,10 do
		local num = gui.get_text(gui.get_node("levelnumberbutton"..(i+10*c)))+20*direction
		if english[num] then
			gui.set_text(gui.get_node("word"..(i+10*c)..1), english[num])
		end
	end
end

function set_buttons_end(direction)
	for i = 1,20 do
		if direction == -1 then num = i else num = 9980+i end
		gui.set_text(gui.get_node("word"..i..1), english[num])
	end
end

If necessary, I can add comments to it.

I think you in update() should print the gui.get_world_position() of the list that disappears. What kind of position does it have when it goes missing? Does it end up off screen somewhere?

I tried it, the position is as it should be.

Have you checked that you get the same inputs as before?
And are you producing the same outputs?
I.e. when handling the inputs.
Add some printouts of your values and compare.

I let the code print the position since I started the app. The position before and after the buttons disapeared, didn’t change.

Is your menu/list gui nodes parented by a node that goes off screen? I wonder if this issue might be related to frustum culling in the render script.

Hm, it could be the problem. Is there some chance to fix it?

You can try if it is the frustum culling in the GUI that is the problem by removing frustum culling in your render script. Modify these two lines:

    -- remove the frustum culling option table
    render.draw(self.gui_pred)
    render.draw(self.text_pred)

If you are not already setup using a custom render script, then you would first need to copy the default render script from the built-ins and place in your project then set it in project settings and make the changes to the gui portion as @britzl stated above.

We don’t have frustum culling for GUI yet?

If the position is the same, then you should check the other variables and events.

So, if you build to the mobile target from the editor it works fine, but if you bundle mobile debug version - then scroll disappear? (I just wanna make sure I fully understand when it’s fine, and when it’s broken)