Hello there! Like many I'm thankfull that Unity finally gave me a real reason to try out Godot!

Currently I would prefer to stick to C#, but I'm more a jack of all trades and not the perfect programmer.
The most basic stuff is fine for me, but I'm currently trying to get Lists in Godot... if I got it right: There are none?

But instead the arrays act like lists? ... kinda confusing to me. Anyway, I tried something like this:
`using Godot;
using System;
using System.Collections.Generic;
using Godot.Collections.Array;

public enum cardNames {Fireball, Potion, Kick};

public partial class CardDataBase : Node
{

CardStats[] CardLibrary;

Cardlibrary.add(12,"g");

Console.WriteLine(Cardlibrary[0]);

}`

Basically I created a class to define the stats of my game cards and want a librabry to store these. The approach above might be total nonsense, a mix of Array and List syntax. I tried different approaches, but none worked for me so far.

Sadly google wont help me to much as common C# seems to me different to "godot c#" ...(right?)...appreciate any hint

p.s. the console already fails at the "(" after the add...some variants got further, but failed with the value...

  • xyz replied to this.

    xyz In other words: Yes, there is no list and Arrays fill that place...(?)

    I stumbled upon that api before... is append ( Variant value ) basically what I know as add?

    Guess I will try to get it done with that 😐

    • xyz replied to this.

      BlueNomiki There's no distinction between lists and arrays. Godot's Array can serve as both. It's similar to lists in Python in that respect. Should you use it or not really depends on your needs. If you need to transfer that data to other Godot objects that expect Godot Arrays then you'll have to use them. Otherwise you can use any generic C# container. Godot also has associative arrays i.e. Dictionaries. Maybe they can serve your needs better.

      There are actual fast arrays in Godot (called packed arrays), that pack data into continuous memory (like proper arrays) but they can only hold some of the atomic types like bytes, floats or vectors.

      I don’t know about differences in the C# API but append() and push_back() (they do the same) would be the functions to use in GDScript.

        I did it like this now...

        `using Godot;
        using System;
        using System.Collections.Generic;

        public enum cardNames {Fireball, Potion, Kick};

        public partial class CardDataBase : Node
        {

        Godot.Collections.Array Cardlibrary = new Godot.Collections.Array{new CardStats("h",2)};

        public override void _Process(double delta)
        {
        	GD.Print("Message");
        
        }

        }`

        Seems to work? At least it doesn't throw errors. On the other hand I also don't get the console message... guess swatching to Godots C# version will be harder then expected...

        Toxe might be my bad, still trying to find my way through the api

        • xyz replied to this.

          xyz makes sense and works...

          GD.Print(Cardlibrary[0]); returns <Node#27195868336> now, but this was a big help already.