As described in the comment, this line connects on_pressed()
to the pressed
signal.
When the button is considered pressed, the button will emit this pressed
signal. By connecting our function to this signal, we can create code that is only executed when the button is pressed.
If you don’t know what signals are and how they can be useful, I suggest you read through the documentation:
I am assuming $Hallway
is supposed to be a reference to a camera in your scene? You should not be using a constant path (like $Hallway
) to reference your camera. Doing this would require you to create one script for every camera-button pair you create – that’s not smart.
The script I proposed uses the @export
variable, target_camera
, as a reference to the camera that should be activated (via make_current()
). Using an @export
variable lets you have multiple instances of your script with different configurations. For example:
Node Hierarchy
- HallwayButton:
target_camera
= HallwayCamera
- LoungeButton:
target_camera
= LoungeCamera
- GardenButton:
target_camera
= GardenCamera
As for your error Attempting to call function 'make_current” in base ‘null instance’ on a null instance
, a null instance is present when a reference to an object is invalid. For the code you’ve shown, that likely means that $Hallway
is not a path that points to any node – it is thus a null instance.
I will be blunt. You don’t seem to be familiar with coding at all. While I am perfectly capable of teaching you the basics, I believe we are both better off if you go through some of the tutorials available online. Godot has its own tutorials in the documentation (see Your first 2D game and Your first 3d game).
That said, I commend you for asking questions and for attempting to modify a simple piece of code – even if it doesn’t work.
The example script I provided does solve your issue so I have nothing more to add. If you have any questions about other things, feel free to send me a message on the forum by clicking on my profile and clicking ‘Message’.
Good luck with your Observation Duty game.