#Need Perspective Help with Objects and Dictionaries in Godot

5 messages · Page 1 of 1 (latest)

high vale
#

I am a Unity refugee, trying to rework my game into Godot. TL;DR, what is the best method in Godot to approach custom objects in Godot?

One of the features I spent months working on for my game was a special system for Stats. I created a Stat interface that contained some events and other variables for me to monitor.

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public interface IStat
{
    
    //-----------------------------------------
    //Variables
    //-----------------------------------------
    int baseValue {get; set;}
    int bonusValue {get; set;}
    int currentValue {get; set;}
    List<IStat> statList {get; set;}
    //-----------------------------------------

    
    //Events
    //event EventHandler OnStatDamage;
    //event EventHandler OnStatHeal;
    //event EventHandler OnStatBuff;
    //event EventHandler OnStatNerf;
    
    //------------------------------------
    //Functions
    //------------------------------------
    string GetStatType();
    //------------------------------------

    
    
}

I used this interface to create different Stat objects, and store them in a dictionary in the player script. They could be added and removed as needed.

I am sure I could brute force something like this in C#, but I am really trying to embrace Godot 4 and it's different design philosophies when it comes to game development. And that includes using GDScript instead of C#!

So I wanted to know what would be the proper way to approach this concept from a Godot developer perspective, instead of a Unity developer?

silent helm
#

im coming from unity as well. i also have to tackle a similar problem as you. my solution is to use json files to store the data. you can convert google excel docs to json format. put together your characters/units in that doc and import the data to godot

dusty edge
sick cypress
#

you can do basically the same thing in godot. have your stat object inherit from Resource if you want easy serialization with the ResourceSaver, or you could inherit from RefCounted if you want to do all the saving yourself. (Resources can also be exported in the editor) (events are called signals in godot)