wiki.sine.space | sinespace

Difference between revisions of "Scripting/SDialogues"

From wiki.sine.space
Jump to: navigation, search
(Added the code example for OpenURL)
(Added examples for: YesNoInput, TextInput, SendLocalChat)
Line 2: Line 2:
  
 
==Members==
 
==Members==
{{ScriptFunction|void|YesNoInput|(string title, string okbutton, string cancelButton, Action<bool> result);|Shows a yes/no dialogue box to the user, and returns the result via the result callback}}
+
{{ScriptFunction|void|YesNoInput|(string title, string okbutton, string cancelButton, Action<bool> result);|Shows a yes/no dialogue box to the user, and returns the result via the result callback|5=
{{ScriptFunction|void|TextInput|(string title, string okbutton, Action<string> result);|Shows a text input dialogue box to the user, and returns the result via the result callback}}
+
''-- There is a known bug that has been fixed in the live viewer, but not in the Editor Pack (v. 10.5)''<br><br>
 +
hostObject = Space.Host.ExecutingObject;<br>
 +
local deltaPos = Vector.New(0,100,0);<br>
 +
local teleportTo = hostObject.WorldPosition + deltaPos;<br><br>
 +
function teleportMeUp (b)<br>
 +
:if b then<br>
 +
::Space.Scene.PlayerAvatar.Teleport(teleportTo);<br>
 +
:end<br>
 +
end<br><br>
 +
function openDialogue ()<br>
 +
:Space.Dialogues.YesNoInput ("Ready for a teleport?", "Yes", "No", teleportMeUp);<br>
 +
end<br><br>
 +
hostObject.SubscribeToEvents();<br>
 +
hostObject.OnMouseDown(openDialogue);<br>
 +
}}
 +
 
 +
{{ScriptFunction|void|TextInput|(string title, string okbutton, Action<string> result);|Shows a text input dialogue box to the user, and returns the result via the result callback|5=
 +
''-- There is a known bug that has been fixed in the live viewer, but not in the Editor Pack (v. 10.5)''<br><br>
 +
hostObject = Space.Host.ExecutingObject;<br><br>
 +
printToLog = function (s)<br>
 +
:Space.Log(s);<br>
 +
end<br><br>
 +
function openDialogue ()<br>
 +
:Space.Dialogues.TextInput ("Write anything.", "Done", printToLog);<br>
 +
end<br><br>
 +
hostObject.SubscribeToEvents();<br>
 +
hostObject.OnMouseDown(openDialogue);}}
 +
 
 
{{ScriptFunction|void|OpenURL|(string url);|Opens a URL in a web browser|5=  
 
{{ScriptFunction|void|OpenURL|(string url);|Opens a URL in a web browser|5=  
 
hostObject = Space.Host.ExecutingObject;<br><br>
 
hostObject = Space.Host.ExecutingObject;<br><br>
Line 12: Line 39:
 
hostObject.OnMouseDown(openTheWebsite);<br>
 
hostObject.OnMouseDown(openTheWebsite);<br>
 
''-- when the object is clicked, the "sine.space" website is opened''}}
 
''-- when the object is clicked, the "sine.space" website is opened''}}
{{ScriptFunction|void|SendLocalChat|(string text, string from);|Sends local chat to the client window}}
+
 
 +
{{ScriptFunction|void|SendLocalChat|(string text, string from);|Sends local chat to the client window|5=
 +
hostObject = Space.Host.ExecutingObject;<br><br>
 +
function chatMessage ()<br>
 +
:Space.Dialogues.SendLocalChat ("I've been clicked", "Clickable Object");<br>
 +
end<br><br>
 +
hostObject.SubscribeToEvents();<br>
 +
hostObject.OnMouseDown(chatMessage);}}
  
 
{{Scripting Navbox}}
 
{{Scripting Navbox}}

Revision as of 12:26, 19 July 2017

The SDialogue class allows you to issue dialogue messages to the player to confirm various actions.

Members

YesNoInput

void YesNoInput (string title, string okbutton, string cancelButton, Action<bool> result);

Shows a yes/no dialogue box to the user, and returns the result via the result callback

-- There is a known bug that has been fixed in the live viewer, but not in the Editor Pack (v. 10.5)

hostObject = Space.Host.ExecutingObject;
local deltaPos = Vector.New(0,100,0);
local teleportTo = hostObject.WorldPosition + deltaPos;

function teleportMeUp (b)

if b then
Space.Scene.PlayerAvatar.Teleport(teleportTo);
end

end

function openDialogue ()

Space.Dialogues.YesNoInput ("Ready for a teleport?", "Yes", "No", teleportMeUp);

end

hostObject.SubscribeToEvents();

hostObject.OnMouseDown(openDialogue);


TextInput

void TextInput (string title, string okbutton, Action<string> result);

Shows a text input dialogue box to the user, and returns the result via the result callback

-- There is a known bug that has been fixed in the live viewer, but not in the Editor Pack (v. 10.5)

hostObject = Space.Host.ExecutingObject;

printToLog = function (s)

Space.Log(s);

end

function openDialogue ()

Space.Dialogues.TextInput ("Write anything.", "Done", printToLog);

end

hostObject.SubscribeToEvents();

hostObject.OnMouseDown(openDialogue);


OpenURL

void OpenURL (string url);

Opens a URL in a web browser

hostObject = Space.Host.ExecutingObject;

function openTheWebsite ()

Space.Dialogues.OpenURL ("http://sine.space/");

end

hostObject.SubscribeToEvents();
hostObject.OnMouseDown(openTheWebsite);

-- when the object is clicked, the "sine.space" website is opened


SendLocalChat

void SendLocalChat (string text, string from);

Sends local chat to the client window

hostObject = Space.Host.ExecutingObject;

function chatMessage ()

Space.Dialogues.SendLocalChat ("I've been clicked", "Clickable Object");

end

hostObject.SubscribeToEvents();

hostObject.OnMouseDown(chatMessage);