Forum rules - please read before posting.

Character turning a TV on and off

Hi everyone. I need some help with having a player character turn a TV on and off an infinite number of times. I am able to have the TV turned on by using two different sprites - one with the TV turned off and one with it turned on, and setting the sprite with the TV turned off to become invisible upon interaction. However, I am unable to figure out how to make another click turn the TV off. If I could figure out how to make the "Tv Off" sprite visible again with another click, this would solve my issue. How would I do this, and is there perhaps an easier way to make my character turn his TV on and off?

Comments

  • You'd need to create a Variable that you can use to record the state of the TV - i.e. a Boolean (True/False) named "TV is on".

    Variables can be stored globally (per-game), locally (per-scene), or as components (per-object). In the case of a TV, I'd suggest using a Component variable, which you can create by using the Scene Manager to create a new "Variables" object, and parenting it to your TV.

    From there, create a new Boolean Variable, name is "TV is on", and set it's Default Value to False (if the TV is off by default).

    Then, inside your TV Hotspot's Interaction ActionList, you can read the state of this variable to alter your sprites accordingly. This can be done with the "Variable: Check" Action. Use this to check if "TV is on" is True or False.

    If it's False, re-route your ActionList to run Actions that show/hide the correct sprites, and end with a "Variable: Set" Action to update your Variable's value to True.

    Otherwise if it's True, re-route your ActionList to run Actions that show/hide the correct sprites, and end with a "Variable: Set" Action to update your Variable's value to False.

    A tutorial on using Variables to create game logic can be found here.

  • ^ I believe you can also check against the sprite's visibility instead of creating a variable for each sprite. The advantage of this is that you can abstract the logic and create an actionlist asset to toggle any object you want (tvs, lights, etc) without having to create one variable for each individual instance of them.

  • Thank you both for the help!

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.