I am trying to send a message when a collision is detected, but since the collision occurs for a prolonged period of time I only want the message to be sent once. How might I go about doing that?
I have the script set up like this:
elseif message_id == hash("collision_response") and not canenter then
msg.post("printer2#printer_example2", "dialogue2")
end
Assuming it to be a local variable, a small alteration could be to store it self
elseif message_id == hash("collision_response") and not self.canenter then
msg.post("printer2#printer_example2", "dialogue2")
end
-- reset self.canenter after a specific set of conditions have been
-- fulfilled, like the printer has stopped printing the message
Another way could be to use a trigger response instead of a collision response and use message.enter, which is only sent once the player enters
if message_id == hash("trigger_response") then
if message.enter then
msg.post("printer2#printer_example2", "dialogue2")
end
end
But remember to change collision type of your door/ whatever it is that you are entering to trigger
Hmm, I really like the trigger response solution but something weird seems to be happening.
Whenever I use the arrow keys and try to move through the door, the dialogue box pops up, but goes away once I let go of the arrow keys. This leads me to believe that the message stops sending at some point. The weird thing is, if I try to do the same thing, but instead I use the mobile controls I made (which are on the screen and move the character via ‘messages_id’ rather than ‘input_id’) then the text box stays up just fine…
Do you know if I might have done something wrong?
Please let me know if I poorly explained myself.
Hey there!!!
I examined your player script and there doesn’t seem anything much off with it. Try printing message_id in the on_message function of your printer script to see what all message it is actually receiving?
Everything on that end seems to be working normal, it is receiving dialogue2 just as it should.
The trigger_response message.enter is sending just fine, and the box appears. Strangely though, message.enter is called twice. This is causing for the printer to open then close and do a bit of a dance before finally not opening at all…
This is the game file incase I poorly explained myself. (So sorry for the atrociously sloppy code!)
For context: checkpoint.script is the door the player must travers through at the end of the level. printer2.gui_script is the script that opens up the printer.
if message_id == hash("trigger_response") then
print("entering")
msg.post("printer2#printer_example2", "dialogue2")
else
print("exiting")
-- msg.post("player#player", "frozen")
--go.delete()
end
according to this script, whenever something enters the trigger region, it will keep sending the dialogue message to the printer, creating that weird effect you described.
Try changing the code to:
if message_id == hash("trigger_response") then
if message.group == hash("player") and message.enter then
print("entering")
msg.post("printer2#printer_example2", "dialogue2")
end
end