Player cycling error

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

I’m making a cycling system to make the player holding the ball the current player


var player = preload("res://TestPlayer.tscn") 


var has_ball

# Called when the node enters the scene tree for the first time.
func _ready():
	if offense:
		if player = has_ball(true):
	Globals.players = 
	var frontcourt,
	var backcourt,
	var center

I got the error “unexpected assign” on here:

if player = has_ball(true):

What causes this error?

:bust_in_silhouette: Reply From: jgodfrey

There are a few things wrong there.

First, to compare one thing to another, you need to use==. The (single) = is to assign a value to something.

Next, I see that you have a variable named has_ball. I guess that gets set to true or false somewhere else. Anyway, this code…


is treating has_ball like it’s a function instead of a variable - which won’t work either.

Also, that lone current_player won’t work. I assume that’s a boolean variable that also needs to be set to true or false.

Based on the limited code you posted, my best guess is that instead of this:

if offense:
    if player = has_ball(true):

… you want something like this:

if offense:
    current_player = has_ball

That will set current_player to the value of has_ball (true or false).