0 votes

""
So this is my code.. im i writing it right? i want to put it in the empty dictionary.. But when i print it out on SelectSkillGrab it return as StreamTexture.. i guess it's because the skill_icon is Load up (an Object).. how do i turn it into just a string for my dictionary ? so i can put it in the as new dictionary. because i can't use it in LoadShortcut and SelectSkillGrab if its StreamTexture

extends CanvasLayer

onready var skillBar_path = "SkillBar/BG/HBoxContainer/"
onready var skillGrab ="UI_SkillGrab/BG/MarginContainer/VBoxContainer/HBoxContainer/VBoxContainer/HBoxContainer2/TextureRect/SkillGrab_Bar/"

onready var SelectedSkill_Texture = 
"GUI/SkillBar/BG/HBoxContainer/SelectedSkill/TextureRect"

onready var assetSkill = "res://Assets/GUI/Skills/UI_Skill_Grab/"

var loaded_skills = {
}


var skill_grab_icon = { 
"Skill_Icon1":"Button_Skill_1",
"Skill_Icon2":"Button_Skill_2",
"Skill_Icon3":"Button_Skill_3",
"Skill_Icon4":"Button_Skill_4",
"Skill_Icon5":"Button_Skill_5",
"Skill_Icon6":"Button_Skill_6",
}


onready var skill_number = 0

func _ready() -> void:
    #_on_Start_Button_pressed()


for shortcut in get_tree().get_nodes_in_group("SkillBar_Group"):
    shortcut.connect("pressed", self, "SelectShortcut", [shortcut.get_parent().get_name()])


for button_use in get_tree().get_nodes_in_group("USE"):
    button_use.connect("pressed", self, "SelectSkillGrab", [button_use.get_parent().get_name()])



func LoadShortcuts(): #SkillBar
    for shortcut in loaded_skills.key():
        var skill_icon = load ( assetSkill + loaded_skills [shortcut] + ".png")
        get_node(str(skillBar_path) + shortcut + "/TextureButton").set_normal_texture (skill_icon)


func SelectShortcut(shortcut): #the choosen skill, # this is the problem
    var skill_icon = load ( assetSkill + str(loaded_skills[shortcut]) + ".png") 
    get_node(SelectedSkill_Texture).set_texture(skill_icon)

    get_parent().get_node("Kinematic_Player").selected_skill = loaded_skills[shortcut]
pass                    


func SelectSkillGrab(button_use): 
    if get_tree().get_nodes_in_group("USE"): #SkillGrab_Bar
        var skill_icon = load (assetSkill + skill_grab_icon[button_use]+".png")
        skill_number += 1
        get_node(skillGrab + "SkillGrab" + 
str(skill_number)).set_normal_texture(skill_icon)
    #LoadShorcuts
    get_node(skillBar_path + "Skill_Icon" + str(skill_number) + "/TextureButton").set_normal_texture(skill_icon)

    #untuk masuk ke dictionary
    var name = "Skill_Icon" + str(skill_number)
    loaded_skills[name] =  skill_icon


    if skill_number == 5:
        skill_number = 0
Godot version 3.2.1
in Engine by (68 points)
reshown by

when i pressed the LoadShortcut it always "Attempt to call function "set_texture" in base "null instance" on a null instance"

1 Answer

0 votes

As from what I can see, you would instead want to make a variable that loads in the texture so it can recognize what is is. you do that by putting someti=hing like this at the top:onready var texture = preload("res://resources/texture.png")
fit that to whatever texture you need. Hope this helps you out! :)

by (30 points)

as for the putting a variable into a string for a dictionary, I'd have to look into that more.

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.