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

Globals

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

Team

var has_ball

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

I got the error “unexpected assign” on here:

if player = has_ball(true):
			current_player

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…

has_ball(true)

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):
        current_player

… 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).