Need help with colon-at-end-of-line error when there is already one there?

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

Back again with another newbie question:

I am quite new at all this but am learning and finding my way around, and getting used to some of the GDScript coding. Albeit, some things still take me days to figure out. To prevent the following from doing so, here we go…

In my 1976 Atari PONG simulation, I have re-combined the paddles from their own scenes back to the main scene, thinking this was causing problems in the separate scripts. This didn’t work. No sooner did I discover a missing character, I ran into another problem…

I got an error in a conditional line stating ‘:’ expected at end of line. Well, I already have a colon there. I am assuming I’m most likely trying to use dated coding. 3.1 features a lot of changes to the GDScript language itself, which has been causing a lot of frustration for me. The following is the script in-progress and the error is occurring in the If statements. As you can see there are already colons at the end of these lines…

func _process(delta):

var ballPosition = get_node("/root/Node2D/Sprite/Ball").get_position()
var p1Posit = get_node("/root/Node2D/CanvasLayer/p1").get_position()
var p2Posit = get_node("/root/Node2D/CanvasLayer/p2").get_position()
var velocity = Vector2()
if p1Posit.y Input.is_action_pressed("ui_a"):
	position += delta * Vector2(0, -500)
if p1Posit.y Input.is_action_pressed("ui_z"):
	position += delta * Vector2(0, 500)
if p2Posit.y Input.is_action_pressed("ui_up"):
	position += delta * Vector2(0, -500)
if p2Posit.y Input.is_action_pressed("ui_down"):
	position += delta * Vector2(0, 500)

position += velocity * delta
position.y = clamp(position.y, 20, 960)

I suspect the problem is with the p1Posit and p2Posit calls, as I read that the colon error sometimes occurs if there is a problem somewhere in the line of code.

Would greatly appreciate some input, and ask for patience - I’m still learning how to do this. Need suggestions as to how to code these lines if what I have is out-of-date.


The Put Code Here function stripped the first level of indents from the example - sorry.

Euergetes | 2019-03-24 18:01

if p1Posit.y Input.is_action_pressed("ui_a"):
These are weird lines.
Is there something missing? An and or something.

omggomb | 2019-03-24 19:00

Okay, I added the conjunction as:

If p1Posit.y and Input.is_action_pressed("ui_a"):

did get rid of the error however, got most unusual results…

The background and ball together, slides down out of the scene with the down input (and back up with the up input) using the keyboard inputs, instead of the paddles. Both paddle inputs result in the same behaviour. Hmmm.

The ball is now going very super slowly, like a pixel every two or three minutes or so.

Before this, I was getting the “Node not found” error that I spun two days out trying to figure out. I finally got rid of those errors by adding the path to the statement according to instructions I found for this error. There are other instructions and ways to fix this problem but none of them worked for me. (including the



This worked fine until I added the if statements. Not out of the woods yet!

Thanks for the idea however! It gives me something more to play with.

Euergetes | 2019-03-24 19:59

:bust_in_silhouette: Reply From: grendahl06

I’m not sure if this is a comment or an answer, but “and” and “&&” are not the same.

Your code compiled for me when I copied your original code and then put && into each IF statement.

I have archived this answer. It is a good lesson on the conjunction and the &&.

I had given up on it yesterday morning and started from scratch using bodies instead of sprites only. This created a whole new ball of wax of problems. After trying to figure these out and I get stumped, I will come back on here.

Apparently you don’t code a body-based game as you would sprites.

Thank you very much for your answer!

Euergetes | 2019-03-31 23:54