Advice on script

Godot Version

Godot 4

Question

Can someone point me in the right direction why this doesn’t work?

var newY = startY + sin(Timer.time_since_start() * bounceSpeed) * bounceHeight
position.y = newY

I have a variable startY: float but it is producing an error for position.
Thanks

What is the error? You probably have to extend the script from Node2D or Node3D and also actually put it on a node that inherits one of those two.

1 Like

What is the error saying?

Timer.time_since_start() is not an existing function. What is it returning?

1 Like

The error is… expected closing “)” after call arguments.

It wants a closing parenthesis on that line, but you have many more script errors to address.

  1. looks like there is two lines in one, split it to create newY then set position.y
  2. sin is supposed to be all lowercase
  3. timer isn’t defined, I am assuming you mean to get a Time node from the scene tree with $Timer, if this isn’t true please post a screenshot of your scene tree.
  4. TIME_SINCE_START does not exist on the timer, maybe you mean time_left?
  5. func_process is missing a space, supposed to be a new function, overriding the _process function that happens every frame.

I think this is the end result what you want for your script.

func _ready() -> void:
    startY = position.y

func _process(delta: float) -> void:
    var newY = startY + sin($Timer.time_left * bounceSpeed) * bounceHeight
    position.y = newY

Thanks so much for the help, I’m new to gdscript and just trying to find my way around it.

You need to add a “)” to close the expression.

For every “(” there needs to be a “)”

# ; end of line
();# valid
(());#valid
(
); # valid because it was closed on the next line
Etc.

(();#invalid
());# invalid
(;# invalid 
);# invalid

# Parentheses control order of execution 
(1.0+5.0) /3.0 # equals 2.0
1.0+(5.0/3.0) # equals  2.666

# parentheses are also used for function syntax
My_func(parameters, and expressions)

Look at the line indicating the error and make sure there are equal numbers of “(” and “)”