
Hey Everyone,
in the past I've used gamemakerstudio 1 which I got from a humblebundle back then, but since I wanna make more text based games with good GUI support, I've decided I wanna learn Godot. I've learned python to understand GDScript, read a lot in the GDScript Documentation and watched tutorials. I really wanna get into the godot Node-Tree System, but in my TestProject I kinda failed in everyway and don't know what to do.
I hope it's not too much, I got 5 short scripts and a photo of my scene tree.
Also there are two nodes, that appear in their parents tree but not in the complete fern. how can I change that?
So the idea is, the player has ships, these ships are nodes, stored in an array "shiplist", which is a property of the node "shipcollection".
There's another Node "obj_ship_creator" that stores a dictionary with empty basestats for new ships and has a function that creates a new ship from the child node "obj_new_ship", applies a dictionary with basestats to it and returns the node with a new ship when called.
Now there's a Tree of GUI-Nodes, within that Tree there's a scroll container Node "GUI-Shiplist" that is supposed to manage the displaying of the ships in shiplist. The Node "GUI-Shiplist" should also have a function update(), that is supposed to update its content (but doesnt work)
Also in the GUI-Nodes. there's a Button called "Button_AddShip" with a signal to "shipcollection". Upon signal the node should call "obj_ship_creator._create_Ship("default")" and store the returned ship in shiplist. then "GUI-Shiplist"s .update(); function should be called to show the updated fleet.
The Nodes "GUI-Shiplist" and "obj_new_ship" don't appear on the complete root fern, only in their parents trees, idk why
Here's my code:
first skript: gui_game_control.gd
extends Control
# Called when the node enters the scene tree for the first time.
func _ready():
# add_child($"obj_ship_creator");
add_child($"ship_collection")
pass # Replace with function body.
second script: GUI-Shiplist.gd
extends ScrollContainer
# The GUI Scroll Container & Display Manager for Ships
# Called when the node enters the scene tree for the first time.
func _ready():
for n in self.get_children():
self.remove_child(n)
self.queue_free()
for item in get_node("/root/gui_control/ship_collection").shiplist :
add_child($Ship_Button);
pass;
pass # Replace with function body.
func update():
for n in self.get_children():
self.remove_child(n)
self.queue_free()
for item in get_node("/root/gui_control/ship_collection").shiplist :
add_child($Ship_Button);
pass;
~~~
**third script**: obj_new_ship.gd
extends Node
# This Node is supposed to be duplicated to create new Ships with these functions / (which don't work)
var basestats = {};
var small_overdeck_slots = [];
var small_underdeck_slots = [];
func _sellShip():
pass
func _addToFleet():
var addPos = get_node("ship_collection").shiplist.size();
get_node("ship_collection").shiplist[addPos] = self;
pass
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
**fourth script**: obj_ship_creator.gd
extends Node
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
# ----- the following dict is used to create new ships base stats ---
var ship_empty_stats = {
"Name": "none",
"Size": 0,
"Small Overdeck Slots" : 0,
"Small Underdeck Slots" : 0,
"Medium Overdeck Slots" : 0,
"Medium Underdeck Slots" : 0,
# abilities
"Can Move": false,
"Can Recover": false,
"Can Locate": false,
"Has Engine" : false,
"Has Steering" : false,
"Has Tank" : false,
"Has Battery" : false,
"Engine Type" : 0,
"Fuel Efficiency" : 0,
# UHF Location
"Has UHF Location" : false,
"Has UHF Loc Creation" : false,
"Has UHF Loc Projection" : false,
"Has UHF Loc Reception" : false,
# recovery
"Has Lift Net" : false,
"Lift Net Level" : 0
};
# this script is supposed to be called and return a new ship node, that can be saved in an array
func _create_Ship(type):
var ship = get_node("obj_new_ship");
ship.basestats = ship_empty_stats.duplicate();
if (type == "default"):
ship.basestats["Name"] = "Small Crow";
ship.basestats["Size"] = 1;
ship.basestats["Small Overdeck Slots"] = 3;
ship.basestats["Small Underdeck Slots"] = 5;
pass
#add arrays
# the following loops are supposed the arrays for equipment ---- don't work
#for i in ship.basestats["Small Overdeck Slots"]-1:
# ship.small_overdeck_slots[i] = 0;
#for i in ship.basestats["Small Underdeck Slots"]-1:
# ship.small_underdeck_slots[i] = 0;
#add mehtods for ship
return ship
pass
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
**fifth script**: ship_collection.gd
extends Node
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
#this array shall store the players fleet from now on
var shiplist = [];
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
# pass
func _on_Button_AddShip_button_up():
var shipmaker = get_node("/root/gui_control/obj_ship_creator");
var addShip = shipmaker._create_Ship("default");
#----- probably doesn't work
shiplist.push_back(addShip)
# update GUI Shiplist / ---- doesn't work
var gui_list = get_node("/root/gui_control/PanelContainer/VSplitContainer/HSplitContainer/PanelContainer2/GUI_Shiplist");
gui_list.update();
pass # Replace with function body.
Yeah, I kinda know nothing about correct referrencing and making a good node system in godot, also about object creation