Changing visibility of object via python?

How to do that?
I want to make an object disappear after pressing a button and appear after pressing another one. Already made a working script for button press events.

property “Flip” Boolean
property “Time” float

key press X --------------------------and--------------Toggle property “Flip”
if time =0------------------------------/ ---------------time=1
if “Flip” = TRUE ----------------------and---------------visibility off
if “Flip” = FALSE ----------------------and---------------visibility off

if time interval min:1 max:5------and---------------add 1 to time

if time = 6---------------------------and---------------time = 0

so you don’t get TRUE FALSE TRUE in 1 frame, you want"timer" this as well


VisLogic.blend (424 KB)
Use the: “setVisible” or the “visible

Sorry english :smiley:

with .visible you can check and set the visibility

if button = justpressed: 
     if obj.visible == 0:
            obj.visible = 1
            obj.visible = 0

Already checked that and tried to make the code but failed hard.

I just want to change the visibility of the object by pressing specific buttons. I already did that in logic bricks without timer and it worked pretty well. The problem is that I want to convert the whole thing into one python script. I have a plane equiped with a keyboard all key sensor and a pulse always sensor connected to a script and nothing else. I want to change the objects’ visibility that way but have problems with it. I need a concrete code.

Thats the same as in the site and after modifying it it didn’t work.(replaced obj with variable)

With python you can’t just say something does or doesn’t work. You need to understand and debug the code.

Go to Window -> Toggle System Console and see what happens there when you play the game. You will have some error printing or there could be something wrong with your setup.

As a programmer, I can see what you mean, but this isn’t valid Python code…
The forum really should have some kind of [pseudocode] tag.

Failed? its your code :stuck_out_tongue: see the console, what say the console? sorry english.

Fade= own[“DEL”]
Fade.visible = 0

Fade= scene.objects[own[“DEL”]
Fade.visible = 0]

not working,

Learning to code is worth a million lines of pre made code.

you need to look at the api

you are just using logic + python, I am pretty sure that the code in my example is fast? (logic bricks)


but if you want python why not learn some?

open the text editor, do new gamelogic simple,

Name a actuator and a sensor

Do X ?

What is wrong with the visibility actuator?

I already made the whole thing in actuators but it was extremely complicated and unable to see it through. In code I can track back which function does which thing and that why I want to convert the whole thing to script.

Like I said a thousand times before I want to make it in python. I already checked tutorials, I checked the goddamn function names and how to use them but as I said before, ITS NOT WORKING.

try with python?

lay off on the freaking out and take your time??


LikeThis.blend (409 KB)

Sorry to say but the solution to your problem was mentioned already.

I do not know what you are doing, but obviously what you do does not work. Maybe you should check the API again.

Establishing such a simple logic takes 30 seconds (regardless of logic bricks or Python).

Imagine a situation where you just want to order a hamburger but the cashier wont give it to you, instead she will just recommend other things. Now do this for 2 days. How would that make you feel? I think I expressed myself pretty well on what I want yet nobody understood it. No wonder I’m not the calmest guy atm…

And yes. Like this but on an other object. I have a plane that controls everything. When I try to modify it like this it fails.

import bge
cont = bge.logic.getCurrentController()
own = cont.owner
current = own[“OO”]


OO is a string variable on the cube with the text of “Plane”. What I wanted to do with this is to control the visibility of the Plane named object I added.

Please. Let me find you the keywords and sentences.

If you still don’t understand my problem with logic bricks then take a look at this:

can you understand my pain now?

Om my good…take your script:

import bge
cont = bge.logic.getCurrentController()
own = cont.owner
own.visible = False

if you say it did not work…then i eat my computer.

I think I’m going to suicide omg…

not see the meaning to that script, this work:

import bge
cont = bge.logic.getCurrentController()
scene = bge.logic.getCurrentScene()
own = cont.owner
current = own[“OO”]

scene.objects[own[“OO”]].visible = False

This script, make invisible the object listed in the variable. Sorry english.

Whats make the variable “Vis”? (in your last script)