Getting a CVAR, always returns 0. Why?

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom Developers

Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
Post Reply
Tanksy
Posts: 143
Joined: Mon May 16, 2016 1:14 pm

Getting a CVAR, always returns 0. Why?

Post by Tanksy »

I've got the cvar "mmp_toaster" (Set up in CVARINFO as USER INT mmp_toaster = 0;), and in DECORATE I've set up a simple test:

Code: Select all

ACTOR MMP_CvarTest
{
	States
	{
	Spawn:
		TNT1 A 0
		TNT1 A 0 A_JumpIf(GetCvar(mmp_toaster) == 0, "Works")
		TNT1 A 0 A_Log("mmp_toaster returned 1")
		Stop
	Works:
		TNT1 A 0 A_Log("mmp_toaster returned 0")
		Stop
	}
}
So when I summon MMP_CvarTest, it logs if mmp_toaster is 1 or 0. But it always says 0, even if the cvar is 1 and I confirm it's 1 with the console.
I have tried with an ACS function to get the Cvar and it still is just returning 0.
RaveYard
Posts: 186
Joined: Fri Apr 12, 2013 10:51 am

Re: Getting a CVAR, always returns 0. Why?

Post by RaveYard »

Read on scope here:
https://zdoom.org/wiki/CVARINFO

You're using "user" cvar, so its value is individual to each player.

You have to specify from which player you read it.

Or use "server" instead.
Tanksy
Posts: 143
Joined: Mon May 16, 2016 1:14 pm

Re: Getting a CVAR, always returns 0. Why?

Post by Tanksy »

Ahh! I thought that the only time I had to specify players was with GetUserCvar.

Thanks. It's a shame I have to use SERVER, I was hoping to let separate players run with toaster modes.
User avatar
Arctangent
Posts: 1235
Joined: Thu Nov 06, 2014 1:53 pm
Contact:

Re: Getting a CVAR, always returns 0. Why?

Post by Arctangent »

Unfortunately, there's no actual client-server structure with ZDoom's multiplayer, despite the server moniker on with cvars. While it's possible to do HUD stuff for only one player and stuff like that, the playsim is always perfectly synced with the rest of the players due to the P2P network structure, so deleting an actor, even one that will have no impact on the rest of the playsim, has to be done for everyone, no matter what.
Tanksy
Posts: 143
Joined: Mon May 16, 2016 1:14 pm

Re: Getting a CVAR, always returns 0. Why?

Post by Tanksy »

Then, what's the SXF_CLIENTSIDE flag for spawning items, if there is no real "Clientside"?
Blue Shadow
Posts: 4949
Joined: Sun Nov 14, 2010 12:59 am

Re: Getting a CVAR, always returns 0. Why?

Post by Blue Shadow »

Skulltag/Zandronum compatibility.
User avatar
Arctangent
Posts: 1235
Joined: Thu Nov 06, 2014 1:53 pm
Contact:

Re: Getting a CVAR, always returns 0. Why?

Post by Arctangent »

There's a reason why it's marked with a black skull on a blue background.

I don't know if there's a reason why it isn't marked with a rusted beaten-up helmet skull instead, though.
WT44
Posts: 2
Joined: Wed Mar 30, 2022 6:50 pm

Re: Getting a CVAR, always returns 0. Why?

Post by WT44 »

Tanksy wrote:Ahh! I thought that the only time I had to specify players was with GetUserCvar.

Thanks. It's a shame I have to use SERVER, I was hoping to let separate players run with toaster modes.
I found a way to do it with user. You can specify each individual user with "consoleplayer" (no quotes). Also, since this is ZScript, you will want to use ZScript's CVar.GetCvar. So the line that gets the CVar could be:

Code: Select all

 TNT1 A 0 A_JumpIf(CVar.GetCvar(mmp_toaster) == 0, "Works") 
As Arctangent pointed out, however, deleting an actor would most likely result in a desync, so I would not recommend removing (or adding) any actors as part of your toaster mode. A more appropriate use would be using lower quality graphics if the user enables the toaster mode. I would recommend you do some serious testing to make sure that whatever you put in the toaster mode does not result in a desync.
Post Reply

Return to “Scripting”