0 votes

I have a Boss in my game who is supposed to bounce up and down the screen, activate after a specific score, and shoot a fireball after a timeout. Everything but the attack works. The attack works partially. This is because when I autostart the attack timer, it works no problem. But when I try and activate it in the code, it refuses to work. All of my signals are connected and don't know why it is not working.

Here's my code:

Note: any things that relate to the instance node is a signal connected to the game's code.

Edit: I found that when I have the timer (known as $Attack.start() ) in the code and have autostart on, the timer disables itself. I also thought maybe changing the name to just timer, as my attack had a similar name. But this had made no difference

Boss code

extends KinematicBody2D

var attack1 = preload("res://Characters/Enemies/Units/Blastboss.tscn")
var complete = preload("res://Misc/stage cleaner.tscn")
export (int) var speed = 30
var healthvar = 20
var point
value = 100
var direction = 1
var velocity = Vector2()
var fire = false

signal instance_node(node, location)

func physicsprocess(delta):
if Global.score >= 3:
$Attack.start() <----- does not work
velocity.y = speed * direction
if is
direction = direction * -1
if health
var <= 0:
Global.score += pointvalue
signal("instancenode", complete, globalposition)

func onhurt_timeout():

func onhitboxareaentered(area):
if area.isingroup("EnemyDamager"):
var -= 1
if area.isingroup("Secret"):
healthvar -= 2
if area.isingroup("Flash"):
healthvar -= 5
if area.isingroup("Power"):
healthvar -= 3

func onAttack_timeout():

emitsignal("instancenode", attack1, $Position2D.global_position)

Game's code

extends Node2D

func _ready():
Global.game = self

func exittree():
Global.game = null

func oncreateparticlesenemy(particles, location):
var particlesinstance = particles.instance()
instance.global_position = location

func instancenode(node, location):
var node
instance = node.instance()
nodeinstance.globalposition = location

in Engine by (12 points)
edited by

1 Answer

+1 vote

In your code, you declare the variable Attack :

var Attack = preload("res://Characters/Enemies/Units/Blastboss.tscn")

But then when you call the start() function, you don't call it from this variable :


which is the equivalent of get_node(Attack).start()
This means you don't use the variable Attack, but instead try to get the node Attack, which I guess doesn't exist in your project.
So try to replace $Attack.start() with Attack.start()

Also, if you have the motivation, you should look into the style guide, to learn about the naming conventions. When naming a variable use the snake_case, and when naming a node use the PascalCase. Using these conventions, you could have seen that you didn't use the variable, but called a node (so in your example, you should name your variable attack)

by (188 points)

Sorry for late response but Attack was the name of the timer. It was a little confusing considering the variable was also named Attack. I changed the variable name now to attack1.

And is it working?
If not, send me your project so I can have a better understanding of it.

Do not worry I have figured it out. The problem was that it wasn't being protected from the physics process delta which happens every frame if I'm not mistaken. This means the timer was being reset every frame and therefore, would never time out. I was told to do if $Attack.is_stopped():
$Attack.start(). This fixed the issue and protected it from the physics process

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.