Last active
August 29, 2015 14:16
-
-
Save Adrianl3d/41eaf926da426fe75563 to your computer and use it in GitHub Desktop.
BubbleChat
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// bubbleChat.js | |
// Version 0.4 | |
// | |
// Created by Adrian 12 March 2015 | |
// Copyright Adrian McCarlie | |
// | |
// This script creates a menu called Bubble Chat | |
// which allows you to use the Avatar Display Name as a chat medium. | |
// And a simple display name change facility. | |
// | |
// | |
// | |
// | |
// Distributed under the Apache License, Version 2.0. | |
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html | |
var displayName = MyAvatar.displayName; | |
var changed = false; | |
function setupMenus(){ | |
if (!Menu.menuExists("Bubble Chat")) { | |
Menu.addMenu("Bubble Chat"); | |
Menu.addMenuItem({ | |
menuName: "Bubble Chat", | |
menuItemName: "Set Chat Message", | |
isCheckable: false | |
}); | |
Menu.addMenuItem({ | |
menuName: "Bubble Chat", | |
menuItemName: "Change Display Name", | |
isCheckable: false | |
}); | |
Menu.addMenuItem({ | |
menuName: "Bubble Chat", | |
menuItemName: "Remove Menu", | |
isCheckable: false | |
}); | |
} | |
} | |
function menuItemEvent(menuItem){ | |
if (menuItem == "Set Chat Message"){ | |
setGreeting(); | |
} | |
if (menuItem == "Change Display Name"){ | |
changeName(); | |
} | |
if (menuItem == "Remove Menu"){ | |
removeMenu(); | |
} | |
} | |
setupMenus(); | |
Menu.menuItemEvent.connect(menuItemEvent); | |
function setGreeting() { | |
var form = [{ label: "Message:", value: "" }]; | |
if (Window.form("Adrians Bubble Chat", form)) { | |
} | |
MyAvatar.displayName = displayName +": \n" + form[0].value; | |
} | |
function changeName() { | |
var form2 = [{ label: "Display Name:", value: MyAvatar.displayName}]; | |
if (Window.form("Adrians Bubble Chat", form2)) { | |
} | |
MyAvatar.displayName = form2[0].value; | |
displayName = MyAvatar.displayName; | |
changed = true; | |
} | |
function removeMenu(){ | |
Menu.removeMenu("Bubble Chat"); | |
if(changed) { | |
MyAvatar.displayName = displayName; | |
} | |
Script.stop(removeMenu); | |
} | |
Script.scriptEnding.connect(removeMenu); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment