Calling a global multiple times

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Bush2Tree
:warning: Old Version Published before Godot 3 was released.

At least, I think thats what the problem is. I’m not exactly sure how to describe it.

What I’m trying to do here is create a simple point and click where a cutscene plays each time you click something. I have a script called “globals” containing variables and functions to get them. These variables are: stage, progress, and animon.

“stage” and “progress” are self explanatory. “animon” is a boolean, which is there so that I can tell if an animation (cutscene) is playing or not.

Here is my script for the button:


extends Control

onready var animplayer = get_node("../../../AnimationPlayer") 

func _input_event(ev):
    if (ev.type==InputEvent.MOUSE_BUTTON and ev.button_index==BUTTON_LEFT and ev.pressed and get_node("/root/globals").getAnimon() == false):
	    if(get_node("/root/globals").getStage() == 1):
		    if(get_node("/root/globals").getProgress() == 0):
			    animplayer.connect("finished", get_node("/root/globals"), "setAnimon", [false])
			    animplayer.play("Cutscene 2")
			    get_node("/root/globals").setProgress(1)
		elif(get_node("root/globals").getProgress() == 1):
			    animplayer.connect("finished", get_node("/root/globals"), "setAnimon", [false])
                animplayer.play("Cutscene 3")
			    get_node("/root/globals").setProgress(2)

func _ready():
    pass

This throws the following error when I click the button:

Attempt to call function 'getProgress' in base 'null instance' on a null instance.

Its most likely a simple mistake. Thanks for any help that I get!

:bust_in_silhouette: Reply From: genete

Easy, you missed the “/” before root at elif(get_node("root/globals").getProgress() == 1):

Now clicking the first button plays the first cutscene. However, it gives me the same error when I click the second.

Bush2Tree | 2016-08-13 14:33

Please check the row number in the error message. Sure it is the same mistake.

genete | 2016-08-13 17:46