# SClickable

## Index

### Functions Index

| Function Name                                                                       |
| ----------------------------------------------------------------------------------- |
| void [**AddExtraAction** ](#addextraaction)(string name, string tooltip, Closure e) |
| void [**ClearActions** ](#clearactions)()                                           |
| void [**OnClick** ](#onclick)(Closure e)                                            |

### Properties Index

| Property Name                              |
| ------------------------------------------ |
| bool [**Enabled** ](#enabled)`get` `set`   |
| string [**Tooltip** ](#tooltip)`get` `set` |
| SGameObject **GameObject** `get`           |

## Functions

### AddExtraAction

void **AddExtraAction** (string name, string tooltip, Closure e)

*Add a new action for the object to perform when clicked. Can be useful for providing miltuple choice of an action on click.*

| Parameter | Type | Description |
| --------- | ---- | ----------- |
|           |      |             |

{% tabs %}
{% tab title="Lua" %}

```lua
Space.Host.ExecutingObject.Clickable.AddExtraAction ("ButtonName", "Tooltip Text Here", AFunction)
```

{% endtab %}
{% endtabs %}

### ClearActions

void **ClearActions** ()

*Removes all actions from the clickable GameObject.*

{% tabs %}
{% tab title="Lua" %}

```lua
Space.Host.ExecutingObject.Clickable.ClearActions()
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Lua" %}

```lua
hostObject = Space.Host.ExecutingObject
hostObject.AddClickable()

function ClickMe ()
Space.Log("I was clicked!")
end
function ClickAndClear ()
Space.Log("No more actions!")
hostObject.Clickable.ClearActions ()
end

hostObject.Clickable.AddExtraAction ("LogButton", "Prints I was clicked! to the console", ClickMe)
hostObject.Clickable.AddExtraAction ("ClearButton", "Clears all actions", ClickAndClear)
-- Now, when the latter option is chosen, the script clears the Clickable component of all actions.
```

{% endtab %}
{% endtabs %}

### OnClick

void **OnClick** (Closure e)

*When clicked, the GameObject performs the required action.*

| Parameter | Type | Description |
| --------- | ---- | ----------- |
|           |      |             |

{% tabs %}
{% tab title="Lua" %}

```lua
Space.Host.ExecutingObject.Clickable.OnClick(AFunction)
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Lua" %}

```lua
hostObject = Space.Host.ExecutingObject
hostObject.AddClickable()
deltaPos = Vector.New(0,0,1)

function MakeMeMove ()
hostObject.WorldPosition = hostObject.WorldPosition + deltaPos
end

hostObject.Clickable.OnClick (MakeMeMove);
-- Now, every time an object is clicked, it moves by 1 in the positive Z direction.
```

{% endtab %}
{% endtabs %}

## Properties

### Enabled

bool **Enabled** `get` `set`

*Enable or disable the clickable component from a GameObject.*

{% tabs %}
{% tab title="Lua" %}

```lua
Space.Host.ExecutingObject.Clickable.Enabled = false
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Lua" %}

```lua
--Clicking the object will disable the component, making it only clickable once
thisGameObject = Space.Host.ExecutingObject


OnClick = function()
 thisGameObject.Clickable.Enabled = false
end


thisGameObject.AddClickable()
thisGameObject.Clickable.Tooltip = "Click to activate"
thisGameObject.Clickable.OnClick(OnClick)
```

{% endtab %}
{% endtabs %}

### Tooltip

string **Tooltip** `get` `set`

*A hint that pops up when the mouse is hovering over the GameObject.*

{% tabs %}
{% tab title="Lua" %}

```lua
Space.Host.ExecutingObject.Clickable.Tooltip = "test"
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Lua" %}

```lua
--Clicking the object will toggle between two different tooltips
thisGameObject = Space.Host.ExecutingObject


OnClick = function()
  if thisGameObject.Clickable.Tooltip == "Turn On" then
    thisGameObject.Clickable.Tooltip = "Turn Off"
  else
    thisGameObject.Clickable.Tooltip = "Turn On"
  end
end


thisGameObject.AddClickable()
thisGameObject.Clickable.Tooltip = "Turn On"
thisGameObject.Clickable.OnClick(OnClick)
```

{% endtab %}
{% endtabs %}

### GameObject

SGameObject **GameObject** `get`

*Returns a reference to the GameObject of this component.*

{% tabs %}
{% tab title="Lua" %}

```lua
theGameObject = Space.Host.ExecutingObject.Clickable.GameObject
```

{% endtab %}
{% endtabs %}
