This function closes the widget or sends data to the widget from the App.
Name
Description
sendMessage
Function to send data to the widget from the App
destroy
Function to close the widget
📚 API Explanation and Example
Methods at a Glance
// Sends a message to the created widgetwidget.sendMessage(object: any)// Closes widgetwidget.destroy()
sendMessage
widget.sendMessage(object: any)
This sends data to the widget from the App.
Parameter
Name
Type
Description
object
any
Data being sent to the widget from the App
E.g. { name : “test”, message : “message” }
Example
Send text and image data to the widget.
// Activates function when a player entersApp.onJoinPlayer.Add(function (player) {player.tag = { widget:null, };player.tag.widget =player.showWidget("sample.html","top",300,300);player.tag.widget.onMessage.Add(function (player, data) {if (data.type =="close") {player.showCenterLabel("The widget closed.");player.tag.widget.destroy();player.tag.widget =null; } });player.sendUpdated();});// Activates function when q is pressed// Sends blueman image and text to the widget// **[App.addOnKeyDown](https://www.notion.so/Callbacks-7ac5078bab7c4f3180ae05463713581d) Explanation [(Link)](https://www.notion.so/Callbacks-7ac5078bab7c4f3180ae05463713581d)**App.addOnKeyDown(81,function (player) {if (player.tag.widget) {player.tag.widget.sendMessage({ text:"Blueman", }); }});
sample.html: Section where the text and image data is received and displayed