0 votes

This keeps happening to me. I call a function from a node, and it returns null.
Here's a script, when the player does inputs (under #Input Attack) attspeed, attpower, or attdefense, it should change the color, (Via set_modulate) But it has to not be null. How can I (For lack of a better word) un-null it.

extends KinematicBody2D
export var hp = 1
export var damage = 1
#enum statuseffect {normal,damaged,cutting,poison,fire} 
#var priority = 0
export var speed = 1
export var power = 1
export var defense = 1
export var playercontroler = 0
export var vel = Vector2()
export var gravity = 0
export var agility = 1000
#Children Nodes
onready var charspr = get_node("sprite")
export var speedcolor = Color("07ff00")
export var powercolor = Color("ff0000")
export var defensecolor = Color("1300ff")
export var normalcolor = Color("ffffff")

func _ready():

func _fixed_process(delta):
    var mover = Input.is_action_pressed(str(playercontroler) + "right")
    var movel = Input.is_action_pressed(str(playercontroler) + "left")
    var attspeed = Input.is_action_pressed(str(playercontroler) + "attackspeed")
    var attpower = Input.is_action_pressed(str(playercontroler) + "attackpower")
    var attdefense = Input.is_action_pressed(str(playercontroler) + "attackdefense")
    #Input X axis
    if (mover):#mover
        vel.x = agility
    elif (movel):
        vel.x = -agility
        vel.x = 0
    #Input Y axis
    vel.y += gravity
    #Input Attack
    if (attspeed):
        if charspr != null:
            print("Modulate is working, not null instance")
#       add_to_group(priority)
    elif (attpower):
        if charspr != null:
            print("Modulate is working, not null instance")
#       add_to_group(priority)
    elif (attdefense):
        if charspr != null:
            print("Modulate is working, not null instance")
#       add_to_group(priority)
    var motion = vel * delta
#   print(vel)
    #Slide player
    if is_colliding():
        var normal = get_collision_normal()
        motion = normal.slide(motion)
        vel = normal.slide(vel)
in Engine by (273 points)
edited by

1 Answer

+1 vote
Best answer

The error probably says your variable has no value (null), you need to assign one.

In this case, maybe the node called exactly "sprite" does not exist ("sprite"!="Sprite"), look at the tree, check the remote inspector, put a breakpoint and look at charspr value in process.

by (7,922 points)
selected by

Hey your right, the node is exactly called sprite, but it's in another node.

onready var charspr = get_node("colid/sprite")


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.