Page 5 of 10

Re: How To: ZSCRIPT MENUS?

PostPosted: Wed Mar 08, 2017 5:15 pm
by Graf Zahl
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.

Re: How To: ZSCRIPT MENUS?

PostPosted: Wed Mar 08, 2017 8:17 pm
by Major Cooke
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.

Re: How To: ZSCRIPT MENUS?

PostPosted: Wed Mar 08, 2017 8:31 pm
by Nash
Thank you! Will delete all my previous examples and link to yours, because all that old stuff do not work anymore.

Re: How To: ZSCRIPT MENUS?

PostPosted: Wed Mar 08, 2017 8:33 pm
by Major Cooke
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.

Re: How To: ZSCRIPT MENUS?

PostPosted: Wed Mar 08, 2017 8:37 pm
by Nash
Of course. I don't want to run into headaches anymore. :mrgreen:

Re: How To: ZSCRIPT MENUS?

PostPosted: Sun Mar 19, 2017 8:20 pm
by Major Cooke
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.

Re: How To: ZSCRIPT MENUS?

PostPosted: Mon Mar 20, 2017 2:45 am
by ZZYZX
closemenu doesn't call OnDestroy?

Re: How To: ZSCRIPT MENUS?

PostPosted: Mon Mar 20, 2017 3:05 am
by Graf Zahl
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.

Re: How To: ZSCRIPT MENUS?

PostPosted: Mon Mar 20, 2017 7:47 am
by Major Cooke
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.

Re: How To: ZSCRIPT MENUS?

PostPosted: Mon Mar 20, 2017 8:31 am
by ZZYZX
Even GC calls OnDestroy on implicitly destroyed objects from what I know.

Re: How To: ZSCRIPT MENUS?

PostPosted: Mon Mar 20, 2017 12:41 pm
by Major Cooke
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.

Re: How To: ZSCRIPT MENUS?

PostPosted: Mon Mar 20, 2017 12:59 pm
by Graf Zahl
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.

Re: How To: ZSCRIPT MENUS?

PostPosted: Mon Mar 20, 2017 2:57 pm
by Major Cooke
...well no wonder it wasn't working, because it appears casting like this is broken.

Re: How To: ZSCRIPT MENUS?

PostPosted: Mon Mar 20, 2017 3:07 pm
by Graf Zahl
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.

Re: How To: ZSCRIPT MENUS?

PostPosted: Mon Mar 20, 2017 3:18 pm
by Major Cooke
Okay, but how am I supposed to transfer down to the child menus then? Call Menu.GetCurrentMenu() and have that casted in MenuEvent?