Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[C# module] Meta Data doesn't support Collections #848

Open
AlekseiKrivo opened this issue Feb 27, 2024 · 0 comments
Open

[C# module] Meta Data doesn't support Collections #848

AlekseiKrivo opened this issue Feb 27, 2024 · 0 comments

Comments

@AlekseiKrivo
Copy link

Description of the problem

Can't store C# Collections via Meta Data. It works with int, string, bool, etc., but whenever I try to save a collection (e.g. List or Dictionary) I just can't retrieve the stored value. Alt.GetMetaData returns false.

Here is my server-side code:

public class Starting : AsyncResource
{
    public Starting() : base(true)
    {}
    public override void OnStart()
    {
        AltAsync.Log("STARTED!");
    }

    public override void OnStop()
    {
        throw new NotImplementedException();
    }
}
public sealed class Test : IScript
{
    public Test()
    {
        AltAsync.Log("-------------------------------------------------");

        var list = new List<string>()
        {
            "Foo",
            "Bar",
        };
        Alt.SetMetaData("TestMetaList", list);
        AltAsync.Log($"TestMetaList key is existing: {Alt.HasMetaData("TestMetaList")}");

        var listObtained = Alt.GetMetaData<List<string>>("TestMetaList", out var metaList);
        AltAsync.Log($"List obtained from meta: {listObtained}");
        AltAsync.Log($"metaList: {metaList}");

        AltAsync.Log("-------------------------------------------------");

        var dic = new Dictionary<string, string>()
        {
            { "Foo", "Bar" },
        };
        Alt.SetMetaData("TestMetaDic", dic);
        AltAsync.Log($"TestMetaDic key is existing: {Alt.HasMetaData("TestMetaDic")}");

        var dicObtained = Alt.GetMetaData<Dictionary<string, string>>("TestMetaDic", out var metaDic);
        AltAsync.Log($"Dictionary obtained from meta: {dicObtained}");
        AltAsync.Log($"metaDic: {metaDic}");

        AltAsync.Log("-------------------------------------------------");

        var number = 1337;
        Alt.SetMetaData("TestMetaNumber", number);
        AltAsync.Log($"TestMetaNumber key is existing: {Alt.HasMetaData("TestMetaNumber")}");

        var numberObtained = Alt.GetMetaData<int>("TestMetaNumber", out var metaNumber);
        AltAsync.Log($"Number obtained from meta: {numberObtained}");
        AltAsync.Log($"metaNumber: {metaNumber}");

        AltAsync.Log("-------------------------------------------------");

        var text = "Any text here...";
        Alt.SetMetaData("TestMetaString", text);
        AltAsync.Log($"TestMetaString key is existing: {Alt.HasMetaData("TestMetaString")}");

        var textObtained = Alt.GetMetaData<string>("TestMetaString", out var metaText);
        AltAsync.Log($"Number obtained from meta: {textObtained}");
        AltAsync.Log($"metaText: {metaText}");

        AltAsync.Log("-------------------------------------------------");
    }
}

And here is the output:

[14:28:53] -------------------------------------------------
[14:28:53] TestMetaList key is existing: True
[14:28:53] List obtained from meta: False
[14:28:53] metaList:
[14:28:53] -------------------------------------------------
[14:28:53] TestMetaDic key is existing: True
[14:28:53] Dictionary obtained from meta: False
[14:28:53] metaDic:
[14:28:53] -------------------------------------------------
[14:28:53] TestMetaNumber key is existing: True
[14:28:53] Number obtained from meta: True
[14:28:53] metaNumber: 1337
[14:28:53] -------------------------------------------------
[14:28:53] TestMetaString key is existing: True
[14:28:53] Number obtained from meta: True
[14:28:53] metaText: Any text here...
[14:28:53] -------------------------------------------------

As you can see, when I was trying to save a collection as Meta Data, I couldn't get the saved value, even though the key was there.

I'm not sure if it's a bug or expected behaviour, but I couldn't find anything about it in docs (https://docs.altv.mp/articles/meta_data.html?q=Meta)

Reproduction steps

  1. Just take my C# code from above and start the server.
  2. Check the console for output.

Expected behaviour

Able to store collections as Meta Data.

Operating system

Windows

Version

AltV.Net 16.0.8 | alt:V Server 16.0.127 (release)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant