Skip to content

Conversation

@MalzSmith
Copy link

Currently there is no LangVersion specified on the project. This results in the C# version defaulting in 7.3. There are some features that are supported in C# 7.3, but not in 7.0, for example default literal expressions

@Casimir255
Copy link
Collaborator

The plugin which loads and compiles scripts is set to lastest.

I will merge if you update the commit to at least C# 8

@MalzSmith
Copy link
Author

MalzSmith commented Feb 1, 2026

When trying to run the following script on our server

using NGPlugin.Config;
using Sandbox.Game.Entities;
using System.Collections.Generic;
using System.Linq;
using Sandbox.Game;
using Sandbox.Game.GameSystems.BankingAndCurrency;
using Sandbox.ModAPI;
using VRage.Game.ModAPI;
using VRageMath;

namespace NGPlugin.Scripts.ExampleScripts
{
    public class MoneyTaker : ScriptAPI
    {
        private readonly List<IMyPlayer> _playersCache = new List<IMyPlayer>(1);
        private readonly Dictionary<long, IMyPlayer> _playersById = new Dictionary<long, IMyPlayer>();

        public override bool InboundGate(MyCubeGrid BiggestGrid, List<MyCubeGrid> AllGrids, GateAPI Gate, List<long> allPlayers, ref Vector3D gridSpawnPos, ref byte targetServer)
        {
            foreach (var grid in AllGrids)
            {
                var owner = GetOwner(grid);
                if (owner == null)
                {
                    continue;
                }

                MyBankingSystem.ChangeBalance(owner.IdentityId, -1);
            }


            return true;
        }

        private IMyPlayer GetOwner(MyCubeGrid grid)
        {
            var ownerId = grid.BigOwners.FirstOrDefault();
            if (ownerId == default)
            {
                return null;
            }
            
            var found = _playersById.TryGetValue(ownerId, out IMyPlayer player);

            if (found)
            {
                return player;
            }
            
            _playersCache.Clear();
            MyAPIGateway.Multiplayer.Players.GetPlayers(_playersCache, p => p.IdentityId == ownerId);
            if (!_playersCache.Any())
            {
                return null;
            }
            
            player = _playersCache.First();
            _playersById.Add(ownerId, player);

            _playersCache.Clear();
            
            return player;
        }
        
        
        
        public override void OutboundGate(IEnumerable<MyCubeGrid> grids, GateAPI fromGate)
        {
            

        }
    }
}

We received this error:

06:22:10.0283 [ERROR]  CompiledScriptAPI: CS8107: Feature 'default literal' is not available in C# 7.0. Please use language version 7.1 or greater. 37,27
06:22:10.0283 [FATAL]  CompiledScriptAPI: Couldnt compile script MoneyTaker!
06:22:10.0283 [INFO]   ScriptCompiler: Compiled 13 out of 14 received scripts!

Are you sure that these C# features are available?

(This was on the 27th of January)

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

Successfully merging this pull request may close these issues.

2 participants