OpenRA/OpenRA · error · LuaException

CVec is read-only. Use CVec.New to create a new value

Error message

CVec is read-only. Use CVec.New to create a new value

What it means

Thrown from CVec's Lua table indexer (set) when any attempt is made to assign a value to a CVec member. CVec is a readonly struct: its X and Y fields are immutable after construction. The Lua interface throws this LuaException to direct the developer to use CVec.New.

Source

Thrown at OpenRA.Game/CVec.cs:140

					$"({left.WrappedClrType().Name}, {right.WrappedClrType().Name})");

			return new LuaCustomClrObject(a / b);
		}

		public LuaValue this[LuaRuntime runtime, LuaValue key]
		{
			get
			{
				switch (key.ToString())
				{
					case "X": return X;
					case "Y": return Y;
					case "Length": return Length;
					default: throw new LuaException($"CVec does not define a member '{key}'");
				}
			}

			set => throw new LuaException("CVec is read-only. Use CVec.New to create a new value");
		}

		public LuaValue ToString(LuaRuntime runtime) => ToString();

		#endregion
	}
}

View on GitHub (pinned to a520984d91)

Solutions

  1. Create a new CVec using CVec.New(x, y) with the desired values, then reassign the variable.
  2. Use arithmetic operators (vecA + vecB, vec * n, -vec) to compute new vectors from existing ones.

Example fix

-- before
vec.X = vec.X + 1 -- error: read-only

-- after
vec = CVec.New(vec.X + 1, vec.Y) -- create a new CVec
Defensive patterns

Strategy: validation

Validate before calling

-- Never attempt to set members; always construct new values
local new_vec = CVec.New(5, vec.Y)

Prevention

When it happens

Trigger: In a Lua script, writing vec.X = 5 or vec.Y = vec.Y + 1 on an existing CVec. All setter access on CVec via Lua is forbidden.

Common situations: Script authors try to mutate vectors in place, forgetting that OpenRA coordinate types are value types designed for immutability.

Related errors


AI-assisted analysis of OpenRA/OpenRA@a520984d91 (2026-08-13). Data as JSON: /api/errors/09a5fb43313fa435. Report an issue: GitHub.