Where exactly can I modify CVars? (ZScript)

Thu Oct 28, 2021 9:52 pm

I have the following custom DoomPlayer:

Code:
class CustomDoomPlayer : DoomPlayer
{
   Default
   {
      Speed 0.6;
      Health 100;
      Radius 16;
      Height 56;
      Mass 100;
      PainChance 255;
      Player.DisplayName "CustomDoomPlayer";
      Player.CrouchSprite "PLYC";
      Player.MaxHealth 300;
      Player.StartItem "Pistol";
      Player.StartItem "Shotgun";
      Player.StartItem "Fist";
      Player.StartItem "Clip", 50;
      Player.WeaponSlot 1, "Fist", "Chainsaw";
      Player.WeaponSlot 2, "Pistol";
      Player.WeaponSlot 3, "Shotgun", "SuperShotgun";
      Player.WeaponSlot 4, "Chaingun";
      Player.WeaponSlot 5, "RocketLauncher";
      Player.WeaponSlot 6, "PlasmaRifle";
      Player.WeaponSlot 7, "BFG9000";
      
      Player.ColorRange 112, 127;
      Player.Colorset 0, "$TXT_COLOR_GREEN",      0x70, 0x7F,  0x72;
      Player.Colorset 1, "$TXT_COLOR_GRAY",      0x60, 0x6F,  0x62;
      Player.Colorset 2, "$TXT_COLOR_BROWN",      0x40, 0x4F,  0x42;
      Player.Colorset 3, "$TXT_COLOR_RED",      0x20, 0x2F,  0x22;
      // Doom Legacy additions
      Player.Colorset 4, "$TXT_COLOR_LIGHTGRAY",   0x58, 0x67,  0x5A;
      Player.Colorset 5, "$TXT_COLOR_LIGHTBROWN",   0x38, 0x47,  0x3A;
      Player.Colorset 6, "$TXT_COLOR_LIGHTRED",   0xB0, 0xBF,  0xB2;
      Player.Colorset 7, "$TXT_COLOR_LIGHTBLUE",   0xC0, 0xCF,  0xC2;
   }

   override
   void BeginPlay() {
      // Setting up the chasecam
      CVar chase = CVar.FindCVar('chase');
      CVar chaseHeight = CVar.FindCVar('chase_height');
      if (chase) {
         chase.SetBool(true);
      }
      if (chaseHeight) {
         chaseHeight.SetFloat(8.2);
      }
   }

   States
   {
   Spawn:
      MAR1 ABC 14;
      Loop;
   Idle:
      MAR1 ABC 5;
      Loop;
   See:
      MAR1 DFG 6;
      Loop;
   Running:
      MAR1 HIJ 6;
      Loop;
   Missile:
      MAR1 ABC 14;
      Goto Spawn;
   Melee:
      MAR1 ABC 14;
      Goto Missile;
   Pain:
      MAR1 ABC 14;
      Goto Spawn;
   Death:
      MAR1 K -1;
   Death1:
      MAR1 K -1;
   XDeath:
      MAR1 K -1;
   XDeath1:
      MAR1 K -1;
   AltSkinDeath:
      MAR1 K -1;
   AltSkinXDeath:
      MAR1 K -1;
   }
}


As you can see, on BeginPlay, I modify 2 CVars concerning the chasecam, but then I get the following error:

Code:
VM execution aborted: Attempt to change CVAR 'chase_height' outside of menu code


Where exactly is "menu code"? Graf Zahl said here that "System CVARs are strictly off-limits to user code now.", but I'm somewhat lost on what to do. I just want that my mod starts by modifying these CVars. How can I do that? (On the Event Handler it doesn't work as well, I've tried).

Re: Where exactly can I modify CVars? (ZScript)

Thu Oct 28, 2021 10:49 pm

RederickDeathwill wrote:Where exactly is "menu code"?

Those CVARs are engine-defined, not mod-defined, so they can only be changed from menu code (when working with menus and menu classes).

Re: Where exactly can I modify CVars? (ZScript)

Fri Oct 29, 2021 6:04 am

Is there a way to achieve a similar result without using CVars then? I just want to turn chasecam on when the game starts and adjust its height. I saw some chasecam ACS scripts out there but they were quite redundant, since the GZDoom's default chasecam works nicely already. Which menu class / method should I override to make this possible?

Re: Where exactly can I modify CVars? (ZScript)

Fri Oct 29, 2021 7:13 pm

I don't know. All I can say is that messing around with user settings is not the right approach to solve the problem. You probably want to do like what others have done; create your own chasecam implementation.

Re: Where exactly can I modify CVars? (ZScript)

Fri Oct 29, 2021 7:23 pm

While I fully understand the concerns, is a bit of a shame that the built-in chasecam can't be accessed by mods in this way. I find it to be really quite well implemented and many of the home-brew alternatives are just not as good (often jerky, don't play well when backed up against a wall etc).

What you might consider doing is checking for the condition of the chase cvar in ACS and printing a message to the screen that the mod is intended to use the chasecam if the cvar is not true (which it probably won't be in most cases).

Re: Where exactly can I modify CVars? (ZScript)

Mon Nov 01, 2021 6:05 am

Enjay wrote:While I fully understand the concerns, is a bit of a shame that the built-in chasecam can't be accessed by mods in this way. I find it to be really quite well implemented and many of the home-brew alternatives are just not as good (often jerky, don't play well when backed up against a wall etc).

What you might consider doing is checking for the condition of the chase cvar in ACS and printing a message to the screen that the mod is intended to use the chasecam if the cvar is not true (which it probably won't be in most cases).


Nah, I'll probably use a separate chasecam. I was doing that, until I realized that the default one is good enough already, but now I've realized it's useless in that sense. Thank you guys!