# Major - Switch device functions yielding the wrong types

**URL:** <https://forums.unrealengine.com/t/major-switch-device-functions-yielding-the-wrong-types/791175>\
**Category:** Verse\
**Tags:** unreal-editor-for-fortnite, fortnite\
**Created:** [March 15, 2023, 9:10am UTC](https://forums.unrealengine.com/t/major-switch-device-functions-yielding-the-wrong-types/791175 "2023-03-15T09:10:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![FinestCreative](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/finestcreative/32/1034971_2.png) [@FinestCreative](https://forums.unrealengine.com/u/FinestCreative)\
**Post date:** [March 15, 2023, 9:10am UTC](https://forums.unrealengine.com/t/major-switch-device-functions-yielding-the-wrong-types/791175/1 "2023-03-15T09:10:35Z")

</div>

GetCurrentState function from switch\_device returns a void instead of a logic. This got me confused when I made an if, else if, else in the 2nd screenshot. I expect either true or false as stated in the commented line above the function.

Same issue with IfOnWhenCheckedEvent, it uses a tuple()? why?

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/3/7/73787e53b537c25f16056226f602e11b479c2bf1.png)

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/4/7/a47189116036616c267299377b8f3c9c4f324086.png)

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/7/d/67de5bcdd0ee20dea63ebcc20e1bc96a445c3d9a.png)

---

<div class="post-metadata">

**Author:** ![UltimateLambda](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/ultimatelambda/32/916183_2.png) [@UltimateLambda](https://forums.unrealengine.com/u/UltimateLambda)\
**Post date:** [March 15, 2023, 5:58pm UTC](https://forums.unrealengine.com/t/major-switch-device-functions-yielding-the-wrong-types/791175/2 "2023-03-15T17:58:57Z")

</div>

In the case of `GetCurrentState`, the `decides` effect is used, rather than returning `logic`. To have your code work, you would need to update it to

```auto
if (not Switch.GetCurrentState[Agent]):
    Print("meow")
else if (Switch.GetCurrentState[Agent]):
    Print("meow")

```

`GetCurrentState` will `fail` (rather than return `false`) or succeed (rather than return `true`).

Related to use of `tuple()` with `listenable`: this is to indicate `Await` (a method of the superinterface `awaitable`) produces value `()` - note `()` is a value with type `tuple()` - and to indicate `Subscribe` of superinterface `subscribable` must be passed a function matching `type{_():void}` (a callback with a `()` passed as argument). For its use on `IfOnWhenCheckedEvent` and `IfOffWhenCheckedEvent`: this means these events, when signaled, provide no information short of the fact they were signaled.

---

<div class="post-metadata">

**Author:** ![FinestCreative](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/finestcreative/32/1034971_2.png) [@FinestCreative](https://forums.unrealengine.com/u/FinestCreative)\
**Post date:** [March 15, 2023, 6:51pm UTC](https://forums.unrealengine.com/t/major-switch-device-functions-yielding-the-wrong-types/791175/3 "2023-03-15T18:51:03Z")

</div>

Ah thanks, I understand it better now I think. So `GetCurrentState(Agent)` cannot be used to check the state of the switch (on/off), rather it is used to check if the `Agent` has a state registered for the switch or if the Agent does not have any state registered for this device.

If I do need to check if the state is on/off I would need to use a combination of

```auto
CheckState(Agent)
MySwitch.IfOnWhenCheckedEvent.Subscribe(someFunc)
MySwitch.IfOnWhenCheckedEvent.Subscribe(someFunc)

```

---

<div class="post-metadata">

**Author:** ![UltimateLambda](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/ultimatelambda/32/916183_2.png) [@UltimateLambda](https://forums.unrealengine.com/u/UltimateLambda)\
**Post date:** [March 15, 2023, 7:25pm UTC](https://forums.unrealengine.com/t/major-switch-device-functions-yielding-the-wrong-types/791175/4 "2023-03-15T19:25:58Z")

</div>

For that I’m less certain. I’ve asked others to take a look.

---

<div class="post-metadata">

**Author:** ![Mr\_Alch3mist](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Mr\_Alch3mist](https://forums.unrealengine.com/u/Mr_Alch3mist)\
**Post date:** [March 23, 2023, 2:46am UTC](https://forums.unrealengine.com/t/major-switch-device-functions-yielding-the-wrong-types/791175/5 "2023-03-23T02:46:49Z")

</div>

You can check the state of the switch using `GetCurrentState[Agent]` or `GetCurrentState[]`. As mentioned in the comment above, Verse uses the `<decides>` effect rather than just returning a `logic` value. This is a bit different than what is common in most languages, but is consistent with how Verse is designed to work. The example code above shows how to test the return `fail` or `succeed` when using `GetCurrentState`.

Regarding `GetCurrentState[Agent]`, if your switch device parameter `Store State Per Player` is set to `Yes`, then you can check the switch state per `Agent`. If that parameter is set to `No` then the state is tracked globally and not per `Agent`. In both cases, it still checks the `on`/`off` state of the switch and not whether there is a state associated with a given `Agent`.
