I need the python code for this i have tried everything
Hi @MrB! And I’m back to the forum everyone
The code you need is
gui.hud.scene_navigation_visible = False
If you need to toggle scene navigation on / off, you can use the code below
gui.hud.scene_navigation_visible = not gui.hud.scene_navigation_visible
Hope this helps.
Regards,
CoRichardLi
Hi CoRicharLi
Thank you so much!
Hi CoRichard,
I need some help please with the following code:
What I need it to do is when both keys are clicked and door is clicked, I go to the next scene. However, I’m confused on the code logic for that on python. I also want to incorporate sound logic. For example when a key is clicked, a sound play, when the door is clicked, a sound effect word “Victory” plays
This what I have already:
my code is: from cospaces import*
Retrieve scene items
twig = scene.get_item(“BBzbSPnu”)
info_panel = scene.get_item(“ZiMJpf1q”)
twig_message = scene.get_item(“aHmCHzIz”)
key = scene.get_item(“WlrqC5iG”)
key_message = scene.get_item(“IbYpk0zW”)
vent = scene.get_item(“pq4Cxg5T”)
info_message = scene.get_item(“pFBSg51i”)
camera = scene.get_item(“2ga0RXGg”)
character = scene.get_item(“Z2O57Dq5”)
pan = scene.get_item(“SiNOYOkg”)
pan_message = scene.get_item(“fflMISlI”)
door = scene.get_item(“EQidbZN4”)
sound = scene.get_item(“r3/3wf72AJ8E7kho9XBKkTW5sbnpita77C7FVN0cUShRXQ”)
volcano = scene.get_item(“n3hHZOHg”)
lava_message = scene.get_item(“yDXglkE6”)
lever1 = scene.get_item(“kpmaSOGE”)
lever1_text = scene.get_item(“BztZOjF9”)
lever2 = scene.get_item(“H2fZirDr”)
lever2_text = scene.get_item(“EvedMSH6”)
power = scene.get_item(“1RhGKBRl”)
key_1 = scene.get_item(“qNqPVSKI”)
key_2 = scene.get_item(“oqxTsymN”)
door_1 = scene.get_item(“aBHCVazv”)
keypad = scene.get_item(“haCQUXId”)
Laser IDs
laser_ids = [
“gYldaKMV”, “pxNV6Ywo”, “l2yywyoR”, “eDqhxoUL”, “1rEOk1aH”,
“eF5lQSWj”, “a6Jrwb8g”, “StmRBt3d”, “Ew2V6HCY”, “T5eFybu3”,
“bahiiDLl”, “JNjUYfbC”, “yAD11dFX”, “GPQOuTX4”
]
lasers = [scene.get_item(laser_id) for laser_id in laser_ids]
Flags to check if the twig, key, pan, and lava have been clicked
twig_clicked = False
key_clicked = False
pan_clicked = False
lava_clicked = False
power_interactable = False
vent_clicked_once = False # Track if the vent has been clicked once
vent_clicked_twice = False # Track if the vent has been clicked twice
Flags to track if both keys have been clicked
key1_clicked = False
key2_clicked = False
def show_info_panel():
info_panel.text = “Level 1: Mission\nRescue your friend and escape the jail!”
info_panel.visible = True
time.schedule(hide_info_panel, 2)
def hide_info_panel():
info_panel.visible = False
def show_pan_message():
pan_message.text = “Pan now in inventory!”
pan_message.visible = True
time.schedule(hide_pan_message, 2)
def hide_pan_message():
pan_message.visible = False
pan_message.opacity = 0.0
def on_twig_click():
global twig_clicked
twig.opacity = 0.0
twig_message.text = “Twig now in inventory”
twig_message.visible = True
twig_clicked = True
time.schedule(hide_twig_message, 3)
def hide_twig_message():
twig_message.visible = False
lever1_text.visible = False
lever2_text.visible = False
def open():
if keyFound is True:
door.animation.play(“Open”)
global doorOpened
doorOpened = True
def find():
global keyFound
keyFound = True
key.opacity = 0.0
def check_door_unlock():
global doorOpened
if key1_clicked and key2_clicked and not doorOpened:
door.animation.play(“Open”)
doorOpened = True
def teleport_player():
# Teleport the player (camera) 1000 meters away
camera.transform.position = Vector3(1000, 0, 0) # Adjust the coordinates as needed
def on_key1_click():
global key1_clicked
key1_clicked = True
key_1.opacity = 0.0 # Make key1 disappear after clicking
check_door_unlock() # Check if the door should unlock
def on_key2_click():
global key2_clicked
key2_clicked = True
key_2.opacity = 0.0 # Make key2 disappear after clicking
check_door_unlock() # Check if the door should unlock
def on_key_click():
global key_clicked
if twig_clicked:
key_message.opacity = 1.0
key_message.text = “Unlocked the lock! Received a screw!”
key_message.visible = True
key_clicked = True
time.schedule(hide_key_message, 5)
def hide_key_message():
key_message.visible = False
key_message.opacity = 0.0
keypad.opacity = 0.0
def on_vent_click():
global vent_clicked_once
global vent_clicked_twice
if key_clicked:
if not vent_clicked_once:
info_message.text = "Unscrewed the vent."
info_message.visible = True
time.schedule(hide_info_message, 5)
vent_clicked_once = True # Mark vent as clicked once
elif vent_clicked_once and not vent_clicked_twice:
vent_clicked_twice = True # Mark vent as clicked twice
keypad.opacity = 1.0 # Make the keypad visible on the second click
# Perform the teleport action
camera.transform.position = Vector3(0, 0, 0)
def hide_info_message():
info_message.visible = False
def on_character_click():
if hasattr(character, ‘animation’):
character.animation.play(“cheer”)
if hasattr(character, ‘text’):
character.text = “Thank you!”
if hasattr(character.text, ‘visible’):
character.text.visible = True
time.schedule(hide_thank_you_message, 3)
def hide_thank_you_message():
if hasattr(character, ‘text’) and hasattr(character.text, ‘visible’):
character.text.visible = False
def on_pan_click():
global pan_clicked
if vent_clicked_twice: # Only allow interaction with the pan after the vent is clicked twice
pan_message.text = “Pan now in inventory!”
pan_message.visible = True
pan_clicked = True
pan.opacity = 0.0 # Make the pan disappear after clicking
time.schedule(hide_pan_message, 5)
def on_volcano_click():
global lava_clicked
if pan_clicked:
lava_message.text = “You now have a cup of lava!”
lava_message.opacity = 1.0
lava_clicked = True
time.schedule(hide_lava_message, 5)
def hide_lava_message():
lava_message.opacity = 0.0
def delete_lasers():
for laser in lasers:
if laser:
scene.remove_item(laser) # Remove the laser item from the scene
def on_lever1_click():
lever1_text.text = “2594”
lever1_text.visible = True
time.schedule(hide_lever1_message, 5)
def hide_lever1_message():
lever1_text.visible = False
def on_lever2_click():
lever2_text.text = “8226”
lever2_text.visible = True
time.schedule(hide_lever2_message, 5)
def hide_lever2_message():
lever2_text.visible = False
def on_power_click():
if lava_clicked and power_interactable:
delete_lasers() # Delete all lasers from the scene
def on_door_1_click():
if key1_clicked and key2_clicked:
door_1.animation.play(“Open”)
time.schedule(teleport_player, 3) # Delay the teleportation by 3 seconds after the door opens
Event listeners
if hasattr(twig, ‘input’):
twig.input.on_click(on_twig_click)
if hasattr(key, ‘input’):
key.input.on_click(on_key_click)
if hasattr(vent, ‘input’):
vent.input.on_click(on_vent_click)
if hasattr(character, ‘input’):
character.input.on_click(on_character_click)
if hasattr(pan, ‘input’):
pan.input.on_click(on_pan_click)
if hasattr(volcano, ‘input’):
volcano.input.on_click(on_volcano_click)
if hasattr(power, ‘input’):
power.input.on_click(on_power_click)
if hasattr(lever1, ‘input’):
lever1.input.on_click(on_lever1_click)
if hasattr(lever2, ‘input’):
lever2.input.on_click(on_lever2_click)
Event listeners for key1 and key2
if hasattr(key_1, ‘input’):
key_1.input.on_click(on_key1_click)
if hasattr(key_2, ‘input’):
key_2.input.on_click(on_key2_click)
Event listener for door_1
if hasattr(door_1, ‘input’):
door_1.input.on_click(on_door_1_click)
Initial setup
show_info_panel()
key_message.opacity = 0.0
twig_message.visible = False
info_message.visible = False
pan_message.visible = False
Hi @MrB!
Here’s how I find you would want your code to be like:
from cospaces import *
import math
import random
key_audio = Sound.load("r3/WrMtsxCyIsFjNzFOm6gJZLfXFEYVR3CH9WoIKXbu70M")
door_audio = Sound.load("r3/9qbTPuFnZGmOJ74EP77OwjvJfD8jgm9MuiIcqgDHixz")
key_1 = scene.get_item("OXgabO7x")
key1_clicked = False
key_2 = scene.get_item("5GZ1pZJ6")
key2_clicked = False
door_1 = scene.get_item("YJoVTuyB")
door1_clicked = False
def check_if_switch_scene():
key_1.speech = "" #Test
key_2.speech = "" #Test
door_1.speech = "" #Test
if key1_clicked and key2_clicked and door1_clicked:
space.go_to_next_scene()
def on_key1_click():
global key1_clicked
key1_clicked = True
key_1.speech = "playing sound" #Test
Sound.play(key_audio, on_finish = check_if_switch_scene)
#YourOtherCodes
def on_key2_click():
global key2_clicked
key2_clicked = True
key_2.speech = "playing sound" #Test
Sound.play(key_audio, on_finish = check_if_switch_scene)
#YourOtherCodes
def on_door_1_click():
global door1_clicked
door1_clicked = True
door_1.speech = "playing sound" #Test
Sound.play(door_audio, on_finish = check_if_switch_scene)
#YourOtherCodes
if hasattr(key_1, 'input'):
key_1.input.on_click(on_key1_click)
if hasattr(key_2, 'input'):
key_2.input.on_click(on_key2_click)
if hasattr(door_1, 'input'):
door_1.input.on_click(on_door_1_click)
Here is the sample CoSpace that I used for test:
If this is not what you expected, please directly send the link of your CoSpace so that I can take a look on what is really going on.
Hope this helps!
Regards,
CoRichardLi
Hi CoRichard,
Thank you that is what I am looking for!
Much appreciated!