Creating a static array of Vector3Int?

The problem is pretty simple, but I can’t figure it out. I am good with Delphi and Lua, but C# is pretty new to me.

I want to create a single array of Vector3Int, which will hold 256 RGB colour values. This array will be read from repeatedly, but never modified after it has been initialized and filled.

From what I’ve read, it should be initialized this way:

namespace FiftyTifty.Tilemaps
{

    public class Palette
    {

        public static Vector3Int[] Colours = new Vector3Int[1]
        {

            {0,0,0}

        };

   }

}

But that throws the following error: Error CS0623 Array initializers can only be used in a variable or field initializer. Try using a new expression instead.

What is the proper approach here?

You’re still thinking C / C++ land. :slight_smile:

C# doesn’t assume what {0,0,0} might mean.

C# requires an object for each slot of the array, so replace the above with

new Vector3Int(0,0,0),

or just remove the initializers and keep the array size count.

You don’t really need the array size count btw if you are supplying initializers.

2 Likes

That was what I needed, thank you. I’m too used to Delphi’s antiquated ways of doing things, and Lua is Lua. Here’s what it now looks like:

namespace FiftyTifty.Tilemaps
{

    public class Palette
    {

        public static Vector3Int[] Colours = new Vector3Int[]
        {

            new Vector3Int(0,0,0)

        };

   }
}
2 Likes

:smile: Another Delphi / Pascal decendent. Haven’t use Delphi in years and I can’t really remember exactly how you would initialize an array of “records”. (Now that I see it I can remember it, though only very vague ^^).
Old story

The scary thing is I’ve written a delphi 5 application 14 years ago that is still in use by a good old friend of mine. We first met when we had our training as electromechanics over 20 years ago. He continued working at the german postal service as a service technician. The software I wrote read in error report messages from a serial port that was originally meant to be connected to a dot matrix printer. The technicians uses radios to communicate. The application had also access to a radio (also controlled through a serial port).

The application read in an parsed the error messages and based on a rule-set (that could be adjusted by the technician) the software showed a list of all active issues and announced them over the radio via text-to-speech. The rules allowed all sorts ot things, for example to say something different than the actual error message. It has grown over the years. The radios they used also supported sending out 5 tone sequences that the radio could detect. So they could even remote control some features like acknowledging that they are working on the issue and making it repeat the last message.

Originally written for a Win98 machine, it still runs under a newer windows version (don’t know which they use nowadays). The last minor change was in 2019 because they replaced the radio with a newer one and something had changed (I think the line busy detection was different). I’m always baffled that some ancient software is still working on a daily basis without any issues. I used to love pascal and delphi back then. With it I learned a lot about the windows API and also started messing around with OpenGL. It was just great :). Though when I now see some delphi code, like you said, it’s really “antiquated” and I don’t want to use it for any kind of larger project. C# is my new favourite language. After that comes lua :slight_smile:

Are you actually still using Delphi? Professionally?

2 Likes

I actually learned Delphi to make mods for the Elder Scrolls and Fallout games. The game content is almost all records (structs?), and the modding software xEdit allows you to modify/remove/create data by using Delphi scripts. One of my favourite projects was making a script that duplicates enemy spawns for Fallout New Vegas.

Delphi scripts are used in every major modding project for Elder Scrolls and Fallout, such as SkyWind and Tale of Two Wastelands. So it’s alive and well in that scene.

1 Like