How To: ZSCRIPT MENUS?

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.

Re: How To: ZSCRIPT MENUS?

Postby Graf Zahl » Wed Mar 08, 2017 5:15 pm

Major Cooke wrote:Try using Destroy() instead of Close().

I have a couple alternatives in mind in case that doesn't work, but try that first.



Don't do that! 'Close' performs some necessary bookkeeping when closing the menu.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
 
Joined: 19 Jul 2003
Location: Germany

Re: How To: ZSCRIPT MENUS?

Postby Major Cooke » Wed Mar 08, 2017 8:17 pm

Graf Zahl wrote:Don't do that! 'Close' performs some necessary bookkeeping when closing the menu.

But what if I just want to really zip out of there? Instant close it all?
Nash wrote:Major Cooke, if you have time - can you post a minimal example on how to safely manipulate the player with the recent systems and restrictions.

Perhaps just a simple menu that changes the player's health when you click on a button?

Thanks!


Let there be mocha.
You do not have the required permissions to view the files attached to this post.
User avatar
Major Cooke
QZDoom Maintenance Team
 
Joined: 28 Jan 2007

Re: How To: ZSCRIPT MENUS?

Postby Nash » Wed Mar 08, 2017 8:31 pm

Thank you! Will delete all my previous examples and link to yours, because all that old stuff do not work anymore.
User avatar
Nash
 
 
 
Joined: 27 Oct 2003
Location: Kuala Lumpur, Malaysia
Github ID: nashmuhandes

Re: How To: ZSCRIPT MENUS?

Postby Major Cooke » Wed Mar 08, 2017 8:33 pm

I'd still wait for 2.4 before getting too serious if I were you, unless Graf can officially say this is pretty sane enough to consider.
User avatar
Major Cooke
QZDoom Maintenance Team
 
Joined: 28 Jan 2007

Re: How To: ZSCRIPT MENUS?

Postby Nash » Wed Mar 08, 2017 8:37 pm

Of course. I don't want to run into headaches anymore. :mrgreen:
User avatar
Nash
 
 
 
Joined: 27 Oct 2003
Location: Kuala Lumpur, Malaysia
Github ID: nashmuhandes

Re: How To: ZSCRIPT MENUS?

Postby Major Cooke » Sun Mar 19, 2017 8:20 pm

I've been struggling to come up with a proper purchase menu. Honestly I feel like I've wasted the last two weeks of my time trying to come up with something proper.

Graf, given the current state of ZScript with 2.4, how would you do it, roughly? I ask because I've tried to come up with several ways whose cons prove to be too large to properly deal with.

  • By storing items per menu.
    Works, but there's lots of repeating code, is horrendously ugly, not to mention transferring of items from parent menu to sub menu can be a pain in the ass. Cannot rely on inheritance due to needs of inheriting from menus and items, making maintenance a complete pain in the ass.
  • By storing them in a struct.
    By attempting to make my own copy functions in the struct, proved to be absolutely futile. The struct didn't remember a thing.
  • By storing them in a UI object.
    Until I realized that such a command like 'closemenu' exists, which means the object will accumulate as a memory leak.

So what would the best way to handle this be? I'm stumped.
User avatar
Major Cooke
QZDoom Maintenance Team
 
Joined: 28 Jan 2007

Re: How To: ZSCRIPT MENUS?

Postby ZZYZX » Mon Mar 20, 2017 2:45 am

closemenu doesn't call OnDestroy?
User avatar
ZZYZX
le chat du rabbin
 
 
 
Joined: 14 Oct 2012
Location: Ukraine
Discord: ZZYZX#1394
Github ID: jewalky

Re: How To: ZSCRIPT MENUS?

Postby Graf Zahl » Mon Mar 20, 2017 3:05 am

Major Cooke wrote:Until I realized that such a command like 'closemenu' exists, which means the object will accumulate as a memory leak.


It may look that way. Menus, like all other objects are garbage collected so it may take some time before it disappears completely. For an object to actually leak there needs to be some stale reference to it in an object that cannot be GC'd.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
 
Joined: 19 Jul 2003
Location: Germany

Re: How To: ZSCRIPT MENUS?

Postby Major Cooke » Mon Mar 20, 2017 7:47 am

Does the 'closemenu' command have every menu call OnDestroy()? Because if it does, then I don't need to worry, I'll just have the very base menu destroy it.
User avatar
Major Cooke
QZDoom Maintenance Team
 
Joined: 28 Jan 2007

Re: How To: ZSCRIPT MENUS?

Postby ZZYZX » Mon Mar 20, 2017 8:31 am

Even GC calls OnDestroy on implicitly destroyed objects from what I know.
User avatar
ZZYZX
le chat du rabbin
 
 
 
Joined: 14 Oct 2012
Location: Ukraine
Discord: ZZYZX#1394
Github ID: jewalky

Re: How To: ZSCRIPT MENUS?

Postby Major Cooke » Mon Mar 20, 2017 12:41 pm

Which means I should avoid doing all the item exchanges via the object's destruction and let the menu do so instead.

But since they're not thinkers, can they be searched for by chance? If not that means I'll have to plant a big fat "Please use the official shortcut" sign over whichever menu people try to open with the console.
User avatar
Major Cooke
QZDoom Maintenance Team
 
Joined: 28 Jan 2007

Re: How To: ZSCRIPT MENUS?

Postby Graf Zahl » Mon Mar 20, 2017 12:59 pm

The engine only has one menu - the one you get by calling GetCurrentMenu. Each menu also has a link to its parent. There is no global store for menus and what cannot accessed through this chain should be considered non-existent, because if a menu gets closed it gets destroyed.
And what you try with shuffling items around sounds like stuff the menu system was never designed for. Normally each menu which doesn't use a static list of items is responsible for its own contents. You can pass pointers to items around, though but it's entirely up to you to handle the maintenance.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
 
Joined: 19 Jul 2003
Location: Germany

Re: How To: ZSCRIPT MENUS?

Postby Major Cooke » Mon Mar 20, 2017 2:57 pm

...well no wonder it wasn't working, because it appears casting like this is broken.
User avatar
Major Cooke
QZDoom Maintenance Team
 
Joined: 28 Jan 2007

Re: How To: ZSCRIPT MENUS?

Postby Graf Zahl » Mon Mar 20, 2017 3:07 pm

Apparently you try to cast a menu item into a menu. Both classes are unrelated. A menu item is not a menu, even if it will open a menu. The item is just the widget on the first menu that triggers the opening of the child menu. The child menu is not created before it is opened.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
 
Joined: 19 Jul 2003
Location: Germany

Re: How To: ZSCRIPT MENUS?

Postby Major Cooke » Mon Mar 20, 2017 3:18 pm

Okay, but how am I supposed to transfer down to the child menus then? Call Menu.GetCurrentMenu() and have that casted in MenuEvent?
User avatar
Major Cooke
QZDoom Maintenance Team
 
Joined: 28 Jan 2007

PreviousNext

Return to Scripting

Who is online

Users browsing this forum: No registered users and 0 guests