MenuDef: Showing different options based on CVar?

Archive of the old editing forum
Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. This forum is archived - please use this set of forums to ask new questions.
User avatar
Caligari87
Admin
Posts: 6143
Joined: Thu Feb 26, 2004 3:02 pm
Preferred Pronouns: He/Him

MenuDef: Showing different options based on CVar?

Post by Caligari87 »

Basically, I have a CVar which sets one of 4 modes (or disable).

Code: Select all

OptionMenu "Dark_Adjust" {
	Title "DarkDoomZ Settings"

	Option "Mode","ddz_mode","Nice_Modes"

	ifoption("ddz_mode" == 1) {    //line 31
		Option "Presets","ddz_levels", "Sub_Presets"
		Slider "Darken","ddz_subtract",-256,0,8,0
	}
	ifoption("ddz_mode" == 2) {
		Slider "Max Brightness","ddz_maxbright",0,256,8,0
	}
	ifoption("ddz_mode" == 3) {
		Slider "Black Level","ddz_blacklevel",0,256,8,0
	}
	ifoption("ddz_mode" == 3) {
		Slider "Darken Factor","ddz_divfactor",0,256,8,0
	}
	StaticText " "
	StaticText "Changes will be applied on menu close"
}
I want the sub-settings for each mode to be hidden unless that preset is selected, but the code above errors with

Code: Select all

Script error, ":menudef.txt" line 31:
Expected ')', got '=='.
What am I doing wrong? Is this even possible?

8-)
Gez
 
 
Posts: 17805
Joined: Fri Jul 06, 2007 3:22 pm

Re: MenuDef: Showing different options based on CVar?

Post by Gez »

As the error message says, ifoption cannot evaluate an expression. It's extremely limited. What you want to do isn't possible, at least not with pure MENUDEF -- it might be possible with ZScript, perhaps.
User avatar
Nash
 
 
Posts: 17394
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia

Re: MenuDef: Showing different options based on CVar?

Post by Nash »

There's no other way except making your own custom widget for this.
Nevander
Posts: 2254
Joined: Mon Jan 06, 2014 11:32 pm

Re: MenuDef: Showing different options based on CVar?

Post by Nevander »

I have to wonder why it can't be as simple as

Code: Select all

OptionMenu "Menu" {
	Title "Menu"

	ifcvar("cvar" == 1) {
		// stuff
	}
}
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 48881
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: MenuDef: Showing different options based on CVar?

Post by Graf Zahl »

Because MENUDEF gets compiled into a static array and 'if...' is a compile time directive.
User avatar
Caligari87
Admin
Posts: 6143
Joined: Thu Feb 26, 2004 3:02 pm
Preferred Pronouns: He/Him

Re: MenuDef: Showing different options based on CVar?

Post by Caligari87 »

So what can IfOption evaluate? Is it just the hardcoded stuff from menudef.cpp? I can't get it to recognize even a bool cvar.

If it's all hardcoded, then the wiki page really needs to be updated, because I've been fighting with this for hours now and I'm really gonna be cheesed if that was all for naught.

8-)
User avatar
Rachael
Posts: 13393
Joined: Tue Jan 13, 2004 1:31 pm
Preferred Pronouns: She/Her

Re: MenuDef: Showing different options based on CVar?

Post by Rachael »

IfOption is executed when the mod is loaded (at compile-time) - and never again. The result of the menudef compiler is immutable - in that it cannot be changed until the next restart.

You can, however, make ZScript widgets, but how that is done I have no idea.
User avatar
Caligari87
Admin
Posts: 6143
Joined: Thu Feb 26, 2004 3:02 pm
Preferred Pronouns: He/Him

Re: MenuDef: Showing different options based on CVar?

Post by Caligari87 »

Okay, thank you. Will update the wiki page accordingly.

I thought it would be possible, based on the player config menu which pops open sliders if Custom color is selected, but as far as I can tell that must have been done in ZScript.

8-)
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 48881
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: MenuDef: Showing different options based on CVar?

Post by Graf Zahl »

The point of 'ifoption' was to be able to handle all the existing in-game menus in one MENUDEF lump, not write different ones for each game. So the options are limited.

Return to “Editing (Archive)”