# How to swap the “visible” box option in the visibility actuator?

I have this script.

import bge
from initialization import initialization

initialization(__name__)
scene = bge.logic.getCurrentScene()
cont = bge.logic.getCurrentController()
obj = cont.owner
act = cont.actuators["Aura"]
status = act.visibility

if Flashlight["targetName"] == str(obj).replace(" ","_"):
status = True
cont.activate(Aura)
print ("TRRRRUUUUUUUUUUUUUUEEEEEEEEEE")
else:
#   status = False
cont.deactivate(Aura)
print ("FAAAALLSEEEEEEEEEEEEEEEEEEEEE")


Logic bricks are like this:

It works, but I wondered why setting the status = False (at line 17-comment) and then swapping the line with cont.activate(Aura) would not work.

So my question: Doesn't "act.visibility" toggle the "Visible" box option to ticked if True and unticked if False? If yes what does it do and how can I swap the status of the "Visible" box option. *searching for a python solution

p.s. My script checks a string value, if it is equal to the object's name it makes a mesh that acts as an aura visible for as long as the value remains equal.

Variable assignment

status has no relationship to act.visibility. You can't expect to change the variable and the actuator takes over this change. You need to change the actuator, not a variable that contains an earlier copy of the attributes value:

actuator.visibility = False


Know the API: Due to the dynamic nature of the requested behavior I recommend to toggle visibility with KX_GameObject.visible

owner.visible = True


Remarks:

I wonder how your code can work without errors

• Flashlight is not defined
• Aura is not defined

I strongly suggest to use complete words for naming. "cont", "obj", "act" are unnecessary abbreviations leading to confusion. e.g. is act an actor, action, actuator, or an act? Is cont an contact or continuation? Is object an objective?

If we already have words why invent new one? :)

Your code can look like that:

import bge
from initialization import initialization

initialization(__name__)
scene = bge.logic.getCurrentScene()
controller = bge.logic.getCurrentController()
owner = controller.owner
aura = controller.actuators["Aura"]

if Flashlight["targetName"] == owner.name.replace(" ","_"):
aura.visibility = True
cont.activate(Aura)
else:
aura.visibility = False
controller.activate(aura)

• I failed, should have thought that about the "status", thanks. Thanks also for the tip about the full names, and for your elaborated answer again. Initialization defines all the elements I need (like the flashlight here that is an object). Later on I might swap initialization if I find it to be problematic, it saves me time for now. I just did not add it to the question cause my point was on the "status" issue. This is the script : blendswap.com/blends/view/79833 – Lev Oct 12 '15 at 5:38