Understanding Godot input

Godot Version

DUMBv4.1.3.stable.official [f06b6836a]

Question

What is the difference between Left and Right in this script?

func _physics_process(delta):

We create a local variable to store the input direction.

We check for each move input and update the direction accordingly.

if Input.is_action_pressed(“ui_right”):
cage_r()
$ColorRect.show()
else:
$ColorRect.hide()
if Input.is_action_pressed(“ui_left”):
cage_l()
$ColorRect.show()
else:
$ColorRect.hide()

Because when I press the left button, it works. And, the square shows up on screen. But, nothing happens when I press the right button.

Nevermind! I figured it out. It uses the useless Notation! for CSharp.
New code as follows. For each button.

func _physics_process(delta):

We create a local variable to store the input direction.

We check for each move input and update the direction accordingly.

if Input.is_action_pressed(“ui_right”):
cage_r()
$ColorRect2.show()
else:
$ColorRect2.hide()
if Input.is_action_pressed(“ui_left”):
cage_l()
$ColorRect.show()
else:
$ColorRect.hide()

Do like this:

if Input.is_action_pressed(“ui_right”):
    if $ColorRect2.visible == false:
        cage_r()
        $ColorRect2.show()
    else:
        $ColorRect2.hide()
elif Input.is_action_pressed(“ui_left”):
    if $ColorRect2.visible == false:
        cage_l()
        $ColorRect.show()
    else:
        $ColorRect.hide()

Your if block is not correct.
Lets walk through it.
You press the right key and…

if Input.is_action_pressed(“ui_right”): # yes this is true because the right key is pressed
    cage_r()    # so all of this happens
   $ColorRect.show()
else:    # this else does not run 
    $ColorRect.hide()
  
if Input.is_action_pressed(“ui_left”):   # this is false 
    cage_l()    # so this block of code does not run 
    $ColorRect.show()
else:   # this block of code runs 
    $ColorRect.hide()

As you can see the last thing that happens is the ColorRect is hidden.
You can change it to one if else block:

if Input.is_action_pressed(“ui_right”): 
    cage_r() 
   $ColorRect.show()
elif Input.is_action_pressed(“ui_left”):  
    cage_l()
    $ColorRect.show()
else:   
    $ColorRect.hide()

Its super hard to read code that isn’t formatted and most especially code that requires formatting.
When posting code use the </> button to maintain the codes formatting.

It’s not for that. It’s used to control the roll in 3D actually. I need to change some things. It was a failed Godot physics test.
it’s used as, simplified.

> extends RigidBody3D
> 
> const gss_27 = PI/180
> var direct = 0.0
> var punctual = 0.0
> var cage = 0.0
> 
> func _ready():
> 	print(punctual)
> 	print(punctual * gss_27)
> 	print(self.rotation_degrees)
> 
> func _physics_process(_delta):
> 
> 	directed()
> 
> 	if Input.is_action_pressed("ui_right"):
> 		cage_r()
> 		$golde.start()
> 	if Input.is_action_pressed("ui_left"):
> 		cage_l()
> 		$goldf.start()
> 	if Input.is_action_pressed("ui_down"):
> 		
> 		direct += 0.1
> 	if Input.is_action_pressed("ui_up"):
> 		direct += -0.1
> 	if Input.is_action_just_pressed("ui_accept"):
> 		print(direct)
> 		print(self.rotation_degrees)
> 	$Label.text = str(cage)
> 
> func directed():
> 	if direct > 0:
> 		$test.rotate_z(direct * -gss_27)
> 
> func cage_r(): # This is negative value
> 	if cage > -30:
> 		self.rotate_z(-1 * gss_27)
> 		cage -= 1
> 
> func cage_l(): # This is positive value
> 	if cage < 30:
> 		self.rotate_z(1 * gss_27)
> 		cage += 1
> 
> func roll_cage_r():
> 	if cage > 0.5:
> 		cage_r()
> 	elif cage == 0:
> 		$goldf.stop()
> 
> func roll_cage_l():
> 	if cage < -0.5:
> 		cage_l()
> 	elif cage == 0:
> 		$golde.stop()
> 
> func _on_golde_timeout():
> 	roll_cage_l()
> 
> func _on_goldf_timeout():
> 	roll_cage_r()

It’s got a 2 timers, label for degree and the PI syllable. Trying to get so much done on one page.

So what is wrong? Your this codes looking correct

oh yes. I edited that question. I understand it completely now.
in the case:

if Input.is_action_pressed(“ui_right”):
cage_r()
$ColorRect.show()
else:
$ColorRect.hide()
if Input.is_action_pressed(“ui_left”):
cage_l()
$ColorRect.show()
else:
$ColorRect.hide()

When I pressed the RIGHT button the square is still hidden because it’s ELSE in the left.
Or, if I pressed the LEFT button the square is still hidden because it’s ELSE in the right now. But, it wasn’t the case anyway. It actually only worked on the RIGHT button while the LEFT never showed up. That’s why I asked. I see my problem. And I can’t let godot.*$%#& get away.