Message passing and game object behaviour

In my .gui_script, specifically at function on_input(self, action_id, action),in a specific button touch event, i wrote:

if action_id == hash("touch") and action.pressed then
		local gotKlicked = gui.get_node("KlikContinuearea")
		local setText = gui.get_node("textField_vec3_touAR")
if gui.pick_node(gotKlicked, action.x, action.y) then
			msg.post("bearAnim#bearanim1st", "getrid" )

end and so forth…
contains the receiver address (using relative addressing) and a message_id “getrid” to control a game object to just disappear out of screen which in (receiver.script),at function on_message i wrote:

if message_id == hash("getrid") then
		local from_position = vmath.vector3(821, 345, 0.6)
		local to_position = vmath.vector3(1320, 345, 0.6) 
		go.animate("#Bear", "position", go.PLAYBACK_ONCE_FORWARD, to_position, go.EASING_OUTBACK, 2.0)
		print("taking down the bear")
	end
end

i touch the button and the bear didnt move out, how do i make it work? seems like i still got pretty confused with the main concept from Button touch events or perhaps it was the message passing mechanism that i wrote wrongly?
Running Defold 1.3.7

First step is to make sure you send the message. If you add a print("SENDING", msg.url()) in the sender code when you click on the buton, do you see it in the console?

Second step is to make sure you receive the message. If you add a print("RECEIVING", msg.url()) in the on_message code of the receiving script, do you see it in the console? Does the url match what you are sending to?

2 Likes
INFO:ENGINE: Engine service started on port 56272
INFO:GRAPHICS: Initialised graphics device 'opengl'
INFO:ENGINE: Defold Engine 1.3.7 (f0ad06a)
INFO:DLIB: Initialized Remotery (ws://127.0.0.1:17815/rmt)
INFO:ENGINE: Loading data from: build/default
INFO:ENGINE: Initialised sound device 'default'
DEBUG:SCRIPT: Listening for debugger on 0.0.0.0
DEBUG:SCRIPT: Debugger connected from 127.0.0.1

console shows nothing on touch events,etc…
added both the print(“SENDING”, msg.url()) and print(“RECEIVING”, msg.url()) in both scripts,nothings shows on the console after i initiates the touch events

do you have: msg.post(".", "acquire_input_focus") ?

3 Likes

yes,on the sender script. both on global init func and on_input function,on the receiver,it was on init function. as described in some of the examples of buttons and input tutorial

INFO:ENGINE: Engine service started on port 56560
INFO:GRAPHICS: Initialised graphics device 'opengl'
INFO:ENGINE: Defold Engine 1.3.7 (f0ad06a)
INFO:DLIB: Initialized Remotery (ws://127.0.0.1:17815/rmt)
INFO:ENGINE: Loading data from: build/default
INFO:ENGINE: Initialised sound device 'default'
DEBUG:SCRIPT: Listening for debugger on 0.0.0.0
DEBUG:SCRIPT: Debugger connected from 127.0.0.1

still,nothing shows on console after several touch events initiated

Silly question, but did you add the script to an active game object? If you add a print to the init() function, does it show?

2 Likes

++ also please check your input file for touch

2 Likes

yes,as you may guess i added the script to an active game object. Added the print(receive,send) on inits,now the console shows:

INFO:ENGINE: Loading data from: build/default
INFO:ENGINE: Initialised sound device 'default'
DEBUG:SCRIPT: Listening for debugger on 0.0.0.0
DEBUG:SCRIPT: Debugger connected from 127.0.0.1
DEBUG:SCRIPT: RECEIVING	url: [default:/bearAnim#bearanim1st]
DEBUG:SCRIPT: SENDING	url: [default:/gui#textInput]

pardon my inexactitude, there’s several addressing mismatches since im using some of inappropriate words for each game components,so that i cant type it down here and so forth… seems like i’ve figured out how to make the game object move out after the touch events initiations,thanks about the message passing informations and help. :clinking_glasses: :grinning:

7 Likes