I’m stuck with passing message data.
Here is the console log:
INFO:DLIB: Log server started on port 50236
INFO:ENGINE: Engine service started on port 50237
INFO:ENGINE: Defold Engine 1.2.118 (0faa10d)
INFO:ENGINE: Loading data from: build/default
INFO:ENGINE: Initialised sound device 'default'
DEBUG:SCRIPT: ambient sound stoped
DEBUG:SCRIPT: hash: [stop_sound]
INFO:DLIB: SSDP: Started on address 192.168.0.101
INFO:DLIB: SSDP: Started on address 192.168.0.200
DEBUG:SCRIPT:
{
sound_name = boat_station_day_sound,
}
DEBUG:SCRIPT: dim_slavya
DEBUG:SCRIPT: hash: [play_sound]
DEBUG:SCRIPT:
{
gain = 1,
delay = 0,
}
ERROR:SCRIPT: /main/scripts/sound/ambient_sound.script:10: attempt to concatenate field 'sound_name' (a nil value)
stack traceback:
/main/scripts/sound/ambient_sound.script:10: in function 'play_sound'
/main/scripts/sound/ambient_sound.script:27: in function </main/scripts/sound/ambient_sound.script:17>
INFO:DLIB: SSDP: Done on address 192.168.0.101
INFO:DLIB: SSDP: Done on address 192.168.0.200
Code is pretty simple.
caller:
function play_ambient_sound(ambient_sound_name)
local msg_data = { sound_name = ambient_sound_name }
pprint(msg_data)
msg.post("ambient#script", "play_sound", msg_data)
end
callee:
go.property("gain", 1.0)
function init(self)
self.sound_name = "ext_road_day_sound"
play_sound(self)
end
function play_sound(self)
msg.post( "#"..self.sound_name, "play_sound", {gain = self.gain})
end
function stop_sound(self)
msg.post("#"..self.sound_name, "stop_sound" )
end
function on_message(self, message_id, message, sender)
print(message_id)
if( message_id == hash("stop_sound"))then
stop_sound(self)
end
if( message_id == hash("play_sound"))then
pprint(message)
self.sound_name = message.sound_name
play_sound(self)
end
end
I do not understand why it does not pass string as param. Sending “gain” is works, as sending message itself.
Thank you in advance.