problems calling a func

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

Hi! I am very new to godot and am attempting to play around with functions.
and my dilemma is this:

func _text(delta):
$conTEXT.percent_visible += 1
pass

func _on_Timer_timeout():
_text()
pass

it says for this code, “too few arguments to for _text() call” and when I throw in like this

func _on_Timer_timeout():
_text(delta)
pass

it says that the function doesn’t exist in that class…

so now i have input the delta next to timer_timeout() and have thrown it in as it’s own variable… please help me fix this

Hi not sure what you are trying to do, however is some feedback

  • you need to ensure you match the name used in the function definition and call exactly. It looks like you are defining the function with name “text” and calling it with “_text”

  • I recommend not using text as a function name since Godot often uses that as a property name, so it might get a bit confusing.

  • I can not see how you defined the timer, however I assume that will keep running and you want it to keep calling your onTimer_timeout function, right?

  • Note, that percentvisible is a float number between 0 and 1, not a percentage (that’s a bit confusing). By default this is 1.0, so unless you set that to 0.0 somewhere else, it will already be at maximum - your code adds 1 to it, so if you set it to 0.0 somewhere, it will go to fully visible after one call. If your objective is just to switch visibilty fully on after a timer, maybe you can use the visible property instead of percentvisible - that is either on or off. If you want it to fade in slowly, you can use percentvisible call it repeatedly on a timer, increasing by a small amount (for example 0.1) each time. Or you can read up on Animations and use that to fade in. That will reduce the amount of coding you need.

  • You probably do not need those “pass” commands. It just means “do nothing” and you usually use that when you working on defining functions but did not write the code yet. It’s a placeholder.

  • delta is a special variable which contains the time since the last frame. Godot will call code which you define in process or physics_process with this variable so your code can know how long it was since the last frame. If you do not need that, you do not need to pass it to your function. In your case I assume you are using a timer to measure time, so you probably do not need to care about the time since the last frame, and you can ignore delta.

Try this

func increase_visible():
    $conTEXT.percentvisible += 1
   
func onTimer_timeout():
    increase_visible()

(Of course, since increase_visible only contains 1 line of code, you could simplify by just putting that directly inside the onTimer_timeout function, but I think you wanted to know how to call another function )

AndyCampbell | 2020-12-14 11:32