Get mouse coordinate everytime mouse is hovering

hello, can i know how to get mouse coordinate everytime mouse is hovering in game screen
my code is like this but it’s doesn’t work

function init(self)	
	msg.post(".", "acquire_input_focus")
	msg.post("@render:", "use_fixed_projection", { near = -1, far = 1 })
end

function on_input(self, action_id, action)
	if action_id == nil and action.x and action.y then
		local pos_x = action.x
		local pos_y = action.y
		label.set_text("/board#label", pos_x + ", "+pos_y)
end
end

I trying many ways in same topic in defold forum but none of this work

What happens? Do you get an error?

For a start, that’s not how you concatenate in Lua:

pos_x + ", "+pos_y

This is correct:

pos_x .. ", " .. pos_y
2 Likes

Omg, sorry my habit from doing pascal script is carry over and I still learning how lua works. ok i will try then

2 Likes

No. it’s doesn’t work my label still blank

You haven’t said one way or another - are you getting an error? If yes, what does it say?

A few other things to check:

  • Have you added the script? If you add a print() in init(), does it show?
  • Are you actually getting any input? Add print(action_id) in on_input() to check.
  • Is the URL of the label correct?

yes it detected in print() funnction
DEBUG:SCRIPT: game on
DEBUG:SCRIPT: mouse detected pos x,228.5 pos y1080.9349365234
INFO:DLIB: SSDP: Started on address 192.168.100.30
DEBUG:SCRIPT: mouse detected pos x,230.5 pos y1077.9176025391
DEBUG:SCRIPT: mouse detected pos x,242.5 pos y1061.3227539063
DEBUG:SCRIPT: mouse detected pos x,303.5 pos y1008.5205688477
DEBUG:SCRIPT: mouse detected pos x,382.5 pos y948.17529296875
DEBUG:SCRIPT: mouse detected pos x,529.5 pos y830.501953125
DEBUG:SCRIPT: mouse detected pos x,551.5 pos y794.29479980469

and the url is corrrect
label text

Can you see the actual label? I note you’ve set the rotation to be 146, when trying that myself it looks very squished. If you set a value in the label using the editor and stop using this script, do you see the label in your build?

I try to release script from my game object and delete the sprite but strangely the label not show

Can you zip up the project and share it?

the file is big 23mb in average, which one you want me to upload?

Looks like this issue is just in main.collection, so perhaps you can delete things like images just to share a minimal version of the project. Also delete the build folder.

still big in 11mb around and can’t be uploaded

well actually when i am create gui component and create template using that gui the engine is not responding. and I force close it using windows task manager.

maybe i start the project from beginning sorry to bothering you