0

Using some python in the past, I decided to learn some godot and do some basic stuff like creating a main menu of a game. But,

I'm trying to create a main menu in which if the Controller is detected, the bottom two images will show "DPAD to select" and "A to select" whereas there are no controllers, no image will be shown.

I used two TextureRects and this is my code,

extends TextureRect

onready var TextureSprite = $"/root/DPAD"

func _process(delta):
    if Input.get_connected_joypads() != []:
        print("Joypad Connected")
    elif Input.get_connected_joypads() == []:
        print("Keyboard Gameplay")

The texturerect's name is DPAD and the scene tree's name is root. The scripts print correctly but I'm unable to change the image. The onready var line of code says that the node was not found although I'm sure it should.

My line of code with the scene tree as a screenshot

Theraot
  • 31,890
  • 5
  • 57
  • 86
  • 1
    Try changing `$"/root/DPAD"` to `get_parent().get_node("DPAD")`. However, from your screenshot, it looks like the script you have is attached to the DPAD TextureRect. If this is this case, then you seem to be trying to call it from itself? Are you sure you want to do that, and not call it from the root node or a sibling node? – Christopher Bennett Mar 21 '20 at 00:38
  • Also, it doesn't seem like you call on the TextureSprite anywhere in your code aside from the path declaration. Shouldn't you put something like `if Input.get_connected_joypads() != []: print ("Joypad Connected") TextureSprite.show()`? – Christopher Bennett Mar 21 '20 at 00:43
  • Hey, @ChristopherBennett Thanks for your reply. It really did work! Well, I did not call the TextureSprite because I wanted to show the previous script I had. I had forgotten to save the one that had the error. Thanks a lot! – simonknowsstuff Mar 22 '20 at 07:01
  • Removed Python tag and added GDScript tag. – Theraot Apr 24 '21 at 11:50

0 Answers0