ZScript - Making one option menu execute another.

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!)
User avatar
Dewzanity
Posts: 96
Joined: Sat Jun 01, 2019 1:00 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Windows 11
Location: Locked up forever in history.

ZScript - Making one option menu execute another.

Post by Dewzanity »

Hello, I am here to find someone who knows even a little bit of ZScript, because I know practically nothing.

The code I have is borrowed from itsmedoggo's CH custom difficulty addon. I am trying to figure out how I can execute the OptionMenuItemCHPOptionsUpdate menu item from within OptionMenuItemCHPOptionsReset. I have executeCHPOptionsUpdate(); right above the set of 30 CVars, as well as some ChatGPT generated code right below it that is causing problems that is meant to execute OptionMenuItemCHPOptionsUpdate. Once again I will say that I have zero knowledge of Zscript myself, so I wouldn't be surprised if the solution is obvious.
Spoiler:
User avatar
Player701
 
 
Posts: 1694
Joined: Wed May 13, 2009 3:15 am
Graphics Processor: nVidia with Vulkan support

Re: ZScript - Making one option menu execute another.

Post by Player701 »

Am I correct to assume this is the ChatGPT code you're talking about?
Dewzanity wrote: Fri Jul 12, 2024 9:49 am

Code: Select all

void executeCHPOptionsUpdate() {
    OptionMenuItemCHPOptionsUpdate updateItem = OptionMenuItemCHPOptionsUpdate();
    updateItem.activate();
}
If so, the correct version would me:

Code: Select all

void executeCHPOptionsUpdate() {
    let updateItem = new('OptionMenuItemCHPOptionsUpdate');
    updateItem.activate();
}
But do note that without seeing the implementation of OptionMenuItemCHPOptionsUpdate, it's hard to say whether this is actually going to work, as you're not calling the Init method (but doing that might have its own unwanted side effects).

Instead, provided that both items are in the same option menu, you can use this code:

Code: Select all

void executeCHPOptionsUpdate()
{
    let menu = OptionMenu(Menu.GetCurrentMenu());

    if (menu != null)
    {
        foreach (item : menu.mDesc.mItems)
        {
            if (item is 'OptionMenuItemCHPOptionsUpdate')
            {
                item.Activate();
                return;
            }
        }
    }
}

Return to “Scripting”