Invalid Call To Function in CanvasLayer(HUD.gd).

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Alone Developer

So guys i need a little help in the game “Dodge The Creeps” so i just finished the game and i was fixing some problems and most of them i could but then i came to this that i just cant fix cause i dont have idea whats the problem,but it says “Invalid call to function ‘game over’ in base ‘CanvasLayer’(HUD.gd)'. Expected 1 arguments”.

Here is the code from HUD.

extends CanvasLayer

signal start_game

func show_message(text):
$MessageLabel.text = text
$MessageLabel.show()
$MessageTimer.start()

func game_over(text):
show_message(“Game Over”)
yield($MessageTimer, “timeout”)
$StartButton.show()
$MessageLabel.text = “Dodge The\nCreeps”
$MessageLabel.show()

func update_score(score):
$ScoreLabel.text = str(score)

func _on_MessageTimer_timeout():
$MessageLabel.hide()

func _on_StartButton_pressed():
$StartButton.hide()
emit_signal(“start_game”)

PROBLEM SOLVED!

Alone Developer | 2018-09-11 09:12

:bust_in_silhouette: Reply From: vspin

The error is saying that the function ‘game over’ is not getting 1 argument when it’s being called. For example, calling do_something() (note the missing argument) for the following function will produce the same error:

func do_something(arg):
    print(arg)

Thank you,i am begginer so still i dont know what to do.

Alone Developer | 2018-09-10 22:53

When you run your game the debugger will tell you the script by name and the line which is throwing the error. Look beneath the "“Invalid call to function” error message and you’ll see “Stack Frames”. The script listed at the top is the script and line to repair. Next, find the gameover function on that line. It’s missing a text argument. So, for example, it may read gameover() but it needs to be gameover(“game is over”), or better yet gameover(my_text). Arguments are what’s inside the parentheses which you provide to a function (or method) that you are calling.

vspin | 2018-09-11 01:26