Jump to content

Error while compiling CaseSystem

Pending 1.0.2

FknWolf
FknWolf

Posted (edited)

On oxide, I get this error when trying to load the plugin:

 

[CSharp] Started Oxide.Compiler v successfully
Error while compiling CaseSystem: A constant value is expected | Line: 857, Pos: 18

The compile error is coming from this block:

switch (arg.Args[0])
{
    case "SELL":

arg.Args[0] is not being treated cleanly as a string by the Oxide compiler, so it complains at the first string case.

I patched it to force the console argument into a string first:

var action = arg.Args != null && arg.Args.Length > 0 ? arg.Args[0].ToString() : string.Empty;
switch (action)
{

But then upon reload I got:

[CSharp] Started Oxide.Compiler v successfully
Error while compiling CaseSystem: Argument 1: cannot convert from 'Facepunch.StringView' to 'string' | Line: 861, Pos: 61

The specific line is this pattern:

var id = arg.Args[1];
var reward = _config.RewardList.FirstOrDefault(p => p.RewardID == id);

arg.Args[1] is now a Facepunch.StringView, but RewardID is a string, so the compiler will not compare them directly.

I patched the whole console command section properly this time by converting all arg.Args values into a normal string[] first:

var args = arg.Args == null ? new string[0] : arg.Args.Select(x => x.ToString()).ToArray();

this fixed it, but thought you might want to take a look at it 🙂

CaseSystem_patched_v3.cs

Edited by FknWolf
formatting
Xacku Mapping

Posted

30 minutes ago, FknWolf said:

В Oxide при попытке загрузить плагин возникает эта ошибка:

 

[CSharp] Запустил Oxide.Компилятор успешно
Ошибка при компиляции CaseSystem: ожидается константное значение | Строка: 857, позиция: 18

Ошибка компиляции возникает в этом блоке:

switch (arg.Args[0])
{
    case "SELL":

Компилятор Oxide не распознает arg.Args[0] как строку, поэтому выдает ошибку при первом случае со строкой.

Я исправил ошибку, принудительно преобразовав аргумент консоли в строку:

var action = arg.Args != null && arg.Args.Length > 0 ? arg.Args[0].ToString() : string.Empty;
switch (action)
{

Но при перезагрузке я получил:

[CSharp] Запустил Oxide.Компилятор успешно
Ошибка при компиляции CaseSystem: Argument 1: cannot convert from 'Facepunch.StringView' to 'string' | Строка: 861, Позиция: 61

Конкретная строка выглядит так:

var id = arg.Args[1];
var reward = _config.RewardList.FirstOrDefault(p => p.RewardID == id);

arg.Args[1] теперь является объектом Facepunch.StringView, но RewardID — это строка, поэтому компилятор не будет сравнивать их напрямую.

На этот раз я исправил весь раздел консольных команд, предварительно преобразовав все значения arg.Args в обычный массив string[]:

var args = arg.Args == null ? new string[0] : arg.Args.Select(x => x.ToString()).ToArray();

это исправило проблему, но я подумал, что вам стоит взглянуть🙂

CaseSystem_patched_v3.cs 97,31 КБ · 0 загрузок

Hi, thanks. Cashr is currently away, and he will fix this error on Monday.

  • Like 1

About Us

Codefling is the largest marketplace for plugins, maps, tools, and more, making it easy for customers to discover new content and for creators to monetize their work.

Downloads
2.7m
Total downloads
Customers
11.5k
Customers served
Files Sold
164k
Total sales
Payments
3.5m
Processed total
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.