wiki.sine.space | sinespace

Difference between revisions of "Scripting/SDialogues"

From wiki.sine.space
Jump to: navigation, search
(Added examples for: YesNoInput, TextInput, SendLocalChat)
Line 47: Line 47:
 
hostObject.SubscribeToEvents();<br>
 
hostObject.SubscribeToEvents();<br>
 
hostObject.OnMouseDown(chatMessage);}}
 
hostObject.OnMouseDown(chatMessage);}}
 +
 +
 +
 +
 +
{{ScriptFunction|void|ColorPicker|(string title,
 +
string okbutton,
 +
Action< SColor > onChange,
 +
Action< SColor > onSelect,
 +
Action onCancel,
 +
SColor defaultColor );|Opens a color picker dialogue. Any change while the color picker is open will trigger onChange(SColor). Clicking 'ok' will trigger onSelect(SColor), and clicking cancel will trigger onCancel().
 +
 +
Parameters
 +
title The title of the color picker window, choose something brief and appropriate like 'Select a wall color'
 +
okbutton The title of the 'OK' button, should indicate the action e.g. 'Adjust Wall'
 +
onChange A callback event, will fire multiple times as the user adjusts the color
 +
onSelect A callback event, indicates the final color selected by the user
 +
onCancel A callback event, fires when the user clicks the Cancel button
 +
defaultColor The color to open the colour picker with|5=<pre>--clicking the object will open a color picker than changees object's color
 +
 +
thisGameObject = Space.Host.ExecutingObject
 +
 +
OnChange = function(SColor)
 +
thisGameObject.Renderer.Material.SetColor("_Color",SColor)
 +
end
 +
 +
OnSelect = function(SColor)
 +
thisGameObject.Renderer.Material.SetColor("_Color",SColor)
 +
end
 +
 +
OnCancel = function()
 +
Space.Log("no color was chosen")
 +
end
 +
 +
OnClick = function()
 +
Space.Dialogues.ColorPicker("title","okbutton", OnChange, OnSelect, OnCancel, Color.Red)
 +
end
 +
 +
 +
thisGameObject.AddClickable()
 +
thisGameObject.Clickable.OnClick(OnClick)</pre>}}
 +
 +
  
 
{{Scripting Navbox}}
 
{{Scripting Navbox}}

Revision as of 17:46, 9 October 2021

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);




ColorPicker

void ColorPicker (string title,

string okbutton, Action< SColor > onChange, Action< SColor > onSelect, Action onCancel,

SColor defaultColor );

Opens a color picker dialogue. Any change while the color picker is open will trigger onChange(SColor). Clicking 'ok' will trigger onSelect(SColor), and clicking cancel will trigger onCancel().

Parameters title The title of the color picker window, choose something brief and appropriate like 'Select a wall color' okbutton The title of the 'OK' button, should indicate the action e.g. 'Adjust Wall' onChange A callback event, will fire multiple times as the user adjusts the color onSelect A callback event, indicates the final color selected by the user onCancel A callback event, fires when the user clicks the Cancel button defaultColor The color to open the colour picker with

--clicking the object will open a color picker than changees object's color

thisGameObject = Space.Host.ExecutingObject

OnChange = function(SColor) 
 thisGameObject.Renderer.Material.SetColor("_Color",SColor)
end

OnSelect = function(SColor)
 thisGameObject.Renderer.Material.SetColor("_Color",SColor)
end

OnCancel = function()
Space.Log("no color was chosen")
end

OnClick = function()
Space.Dialogues.ColorPicker("title","okbutton", OnChange, OnSelect, OnCancel, Color.Red)
end


thisGameObject.AddClickable()
thisGameObject.Clickable.OnClick(OnClick)