Removing object when var int hits >=

Godot Version

4.3

Question

Trying to set up a system where when you reach x number of kills a barrier is removed for the player.

I have a Autoscript that is counting the kills working fine, what i cant figure out is how to write it out. the kills are also displayed and updated on a label.

ive tried
if Autoscript.kills >= 10:
if kills.int >= 10:
if kills >= 10:
if Autoscipt.text >= 10:

with remove_child(wall)

Can you paste your actual code in here? I will try to answer by what I am reading and lets see if it helps:

If you are using an Autoscript it would look like this:

Extends Node

#the script would have a name in the Autoscript like GameManager or whatever you named it

Var kills = 0

Then in other scripts you would access this and do an if statement like this:

#This would need to be in a process function or be connected to a signal that emits when the player reaches 10 kill or more.

func _process():

If autoscriptname.kills >= 10:
     remove_child(wall)

Share a screenshot of your Autoscript settings and I can tell you the name

extends Node

var kills : int = 0

thats all that is in the script i have the script named Autoscript.gd

i have had it added to func _process(delta):

and i do have the wall referenced with a @onready

the error its giving with what you provided and i did try this is Cannot find member “kills” in base “res://Autoscript.gd”.

Sometimes the name is changed by Godot when you put an autoload script into the project settings, see the Name section on the far left?

I know this is a dumb question, but is that name the same as the name of the script or is it different? For my example above mine is named the same, but that may not be the case for you. Lets check this and then I will see what other solutions I can think of.

FYI and just in case - The autoload scripts need to be put into the Project Settings to be accessible. This is in Project → Project Settings → Globals → Autoload tab


can confirm named Autoscript.

That is so baffling :thinking:
You havent moved the Autoscript.gd into a folder or anything have you? Is it still in the root of your project like the screenshot shows?

If you did move it then you will need to re-add it with the new path into the Autoload

no its never been moved its as it shows in the main dump

I would try a simple re-loading of the project. Sometimes turning it off and on works for Godot as well :laughing:
With the Autoload script it definitely should be accessible from ANY script as you know, so it sounds more like a Godot glitch at the moment if Autoscript.kills is not getting that variable.
Maybe delete it and re-autoload it as well

HA it worked!!! thats so painful. i typed in that if statement you suggested so many times before i made this post. crazy that referencing something that doesnt need it can cause such a issue.

Thanks so much for the help! (im a giant noob i need all the help i can get)

1 Like

Ohhhh. You don’t even have to reference it with @onready or as any variable.

Delete those lines and just try accessing Autoscript.kills in your code.
The autoload makes it accessible already

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.