lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Tue, 2003-10-14 at 11:51, Speight.Marcus wrote:

> SubMenu1 = 
> {
> 	["New Campaign"] = ID_CAMPAIGN,
> 	["New Random Map"] = ID_RANDOMMAP,
> 	["Back"] = Menu                      <-- Problem
> };
> 
> Menu = 
> {
> 	["New"] = SubMenu1,
> 	["Load Game"] = ID_LOADGAME,
> 	["Exit"] = ID_EXIT
> };
> 
> I tried adding Menu = {}; at the beginning of the file but it did not help.
> How to I do this?

The second declaration of Menu will delete the old one.  Why not try
something like this:

Menu = {
  ["New"] = {
    ["New Campaign"] = ID_CAMPAIGN,
    ["New Random Map"] = ID_RANDOMMAP,
    ["Back"] = ID_BACK
  }
  ["Load Game"] = ID_LOADGAME,
  ["Exit"] = ID_EXIT
}

Then, whenever you come across ID_BACK, you know you've got to go up one
menu, and just keep state about what the current menu's parent is.  It's
one solution of many.  The other obvious alternative to so define your
menus top-level downwards, so you've got all the references already, but
I assume that's not an option.

I'm sure one of the Lua guys will come up with something devious,
succinct and elegant though, that'll cause me to go "oooh" - they always
do.
-- 
Rob Kendrick, Pepperfish Limited                   http://www.pepperfish.net/
PGP signed or encrypted mail welcome                         Key ID: 3651D17A