Major - Switch device functions yielding the wrong types

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?

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

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.

3 Likes

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

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

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

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.

2 Likes