0 votes

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?

Godot version 3.4
in Engine by (55 points)
edited by

1 Answer

0 votes

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

by (19,238 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.