Hi!
I have the following code triggered by a message from a third party.
The line “sprite.play_flipbook(“face#mouth”, “mouth1”)” triggers the message function- in fact, when I don’t grey out the second “sprite.play_flipbook(“face#mouth”, “mouth2”)”, the message function loops indefinitely.
Can any one say why this is?
Thanks!
function on_message(self, message_id, message, sender)
print("psych x recd")
if self.xed == false then
self.xed = true
go.set("mushrooms", "position.z", 0)
go.set("liney", "position.z", 0)
go.set("liney1", "position.z", 0)
sprite.play_flipbook("face#mouth", "mouth1")
else
--sprite.play_flipbook("face#mouth", "mouth2")
go.set("mushrooms", "position.z", -100000)
go.set("liney", "position.z", -100000)
go.set("liney1", "position.z", -100000)
end
end
I perhaps misinterpreted your comment as “the program hangs”, but I guess it doesn’t hang?
What is the actual url/name of the sprite that you want to send to?
(remember that sprite.play_flipbook() is just an alias for the message play_animation)
I somehow don’t get what you are doing .
For example, you say the line triggers the message function. How so?
Why do you put the blank code in the message function, without listening to a specific event? Your code basically reacts to every event that comes through.
I don’t know if it helps, but i would do it like so, without knowing the rest of your code :
local function set_mouth(mouth, zPos)
sprite.play_flipbook("face#mouth", mouth)
go.set("mushrooms", "position.z", zPos)
go.set("liney", "position.z", zPos)
go.set("liney1", "position.z", zPos)
end
local function on_msg_set_mouth(msg)
if not self.xed then
self.xed = true
set_mouth("mouth1", 0)
else
set_mouth("mouth2", -100000)
end
function on_message(self, message_id, message, sender)
if message_id == hash("mouth1") then
on_msg_set_mouth(message)
end
end
I send a message (from another collection) to “/everything#psychedelic” which has the following function:
function on_message(self, message_id, message, sender)
print("psych x recd")
sprite.play_flipbook("face#mouth", "mouth1")
end
The debug monitor prints “psych x recd” over and over and over again.
Removing the line “sprite.play_flipbook(“face#mouth”, “mouth1”)” solves the problem.
The sprite does correctly change. I have quickly added a boolean to check what the message_id is so the problem is an easy fix.
The message that prints when “sprite.play_flipbook(“face#mouth”, mouth)” is received by the script is
{ --[[0x120dce880]]
id = hash: [mouth1],
current_tile = 1
}
This is not surprising. You are calling sprite.play_flipbook() without a callback function. And since you don’t specify a callback function your script will receive an "animation_done"message each time the animation competes. And each time you receive the “animation_done” message your start a new animation. And this goes on forever and ever
You really should check the message_id and not run the code on any random incoming message.