0

I've looked through a bunch of solutions for my code, but none of them apply to what I've been trying to add. Since I'm modding a game, I've been coding through dnSpy, and I'm constantly coming up with a read-only error with my issue.

Like I said, I've looked through so many other threads about the "Property or indexer cannot be assigned to -- it is read only" error, but none of them actually help towards my code, from what I can tell.

        // Token: 0x06000B48 RID: 2888 RVA: 0x00045EA0 File Offset: 0x000440A0
        public static bool ConsoleCommandModifier(string command_arguments)
        {
            if (!string.IsNullOrEmpty(command_arguments))
            {
                string[] array = command_arguments.Split(new char[]
                {
                    ' '
                });
                if (array.Length > 0 && State.LocalPlayer != null && State.LocalPlayer != null)
                {
                    string text = array[0].ToLower();
                    if (text != null)
                    {
                        if (text == "rocketjump")
                        {
                            State.LocalPlayer.Modifier = (PlayerControllerModifier)ScriptableObject.CreateInstance(typeof(RocketJumpModifier));
                            State.LocalPlayer.Modifier.AddModifier(State.LocalPlayer);
                            return true;
                        }
                    }
                }
            }
            return false;
        }

The expected results is, I type in the chat of the game "/modifier [modifier] and it applies that modifier to my character. This code was in the game back in early 2018, and I wanted to re-add the code.

The actual results is nothing but an error, describing "Property or indexer 'PlayerController.Modifier' cannot be assigned to -- it is read only. Usually there's more than just 1 modifier, but for this example, I'm using "rocketjump". When there's more modifiers, each of the

State.LocalPlayer.Modifier = (PlayerControllerModifier)ScriptableObject.CreateInstance(typeof(RocketJumpModifier));

lines do the same error, so I suspect that the error has something to do with this line.

Finally, how do I fix the "Property or indexer 'PlayerController.Modifier' cannot be assigned to -- it is read only" error?

Anima-t3d
  • 3,431
  • 6
  • 38
  • 56
ZeeEhm
  • 1
  • 2
  • What is your question? – Shakti Prakash Singh May 02 '19 at 01:43
  • My question is how to solve the "Property or Indexer cannot be assigned to -- it is read only" issue. – ZeeEhm May 02 '19 at 01:45
  • Don't assign to it. It's read only. – mason May 02 '19 at 02:10
  • Sure looks like `State.LocalPlayer.Modifier` doesn't have a property setter defined but you are trying to call one anyway. Go check the source of `Modified`, it'll probably look something like `public property T Modifier { get { ...} }` and you need it to look like `public property T Modifier { get {...} ; set {...}; }` before you can set it-- only you get to write the appropriate code in `set { ... }` and that requires knowledge of how that object is supposed to work. – Tim May 02 '19 at 02:24
  • It's a read-only property, you cannot assign a value to it. You can only read a value from it. – Shakti Prakash Singh May 02 '19 at 02:25
  • @Tim Where would I find the source of Modified? – ZeeEhm May 02 '19 at 02:29
  • @ShaktiPrakashSingh How would I make it so that I can assign a value to it? – ZeeEhm May 02 '19 at 02:29

0 Answers0