Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ General ➜ WindowMenu - Better way to add checkmarks?

WindowMenu - Better way to add checkmarks?

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Wuggly   USA  (112 posts)  Bio
Date Mon 28 Mar 2016 10:01 PM (UTC)
Message
I was wondering if anyone has come up with a better way to put that checkmark next to menu items in the WindowMenu function.

I have different settings that can be changed and when they are changed, it puts a checkmark in the menu next to whatever you changed, however it is making the code massive.

Currently I have it so it runs through a bunch of if statements before doing the WindowMenu function so it can build the menu with the checkmarks in the right spots depending on what all they've selected.

Here's a small part of it so you can see what I mean.

 elseif GetVariable("avatar_checked") == "one" and GetVariable("castle_checked") == "two" and GetVariable("bgColour") == nil then
    menustring_settings ="! >Avatar Image | +Default | - | Browse... | < | >Background Image | Castle 1 | +Castle 2 | Castle 3 | - | Browse... | < | - | Background Color | - | List equipment stats "  
 elseif GetVariable("avatar_checked") == "one" and GetVariable("castle_checked") == "one" and GetVariable("bgColour") == nil then
    menustring_settings ="! >Avatar Image | +Default | - | Browse... | < | >Background Image | +Castle 1 | Castle 2 | Castle 3 | - | Browse... | < | - | Background Color | - | List equipment stats " 
 elseif GetVariable("avatar_checked") == "one" and GetVariable("castle_checked") == "three" and GetVariable("bgColour") == nil then
    menustring_settings ="! >Avatar Image | +Default | - | Browse... | < | >Background Image | Castle 1 | Castle 2 | +Castle 3 | - | Browse... | < | - | Background Color | - | List equipment stats "  
 elseif GetVariable("avatar_checked") == "one" and GetVariable("castle_checked") == "browse" and GetVariable("bgColour") == nil then
    menustring_settings ="! >Avatar Image | +Default | - | Browse... | < | >Background Image | Castle 1 | Castle 2 | Castle 3 | - | +Browse... | < | - | Background Color | - | List equipment stats "  


I just cannot think of an efficient way to do this with the checkmarks. I have tried a few different ways for it to know what all has a checkmark, but still ended up with a massive code.

Any ideas?
Top

Posted by Nick Gammon   Australia  (23,165 posts)  Bio   Forum Administrator
Date Reply #1 on Mon 28 Mar 2016 11:49 PM (UTC)
Message
*boggle*

No, that is very inefficient. Try:


menu = {
  [1] = "! >Avatar Image",
  [2] = "Default",
  [3] = "-",
  [4] = "Browse...",
  [5] = "<",
  [6] = ">Background Image",
  [7] = "Castle 1",
  [8] = "Castle 2",
  [9] = "Castle 3",
  [10] = "-",
  [11] = "Browse...",
  [12] = "<",
  [13] = "-",
  [14] = "Background Color",
  [15] = "-",
  [16] = "List equipment stats",
  }

function checkItem (which)
  menu [which] = "+" .. menu [which]
end -- checkItem

if GetVariable("avatar_checked") then
   checkItem (2)
end -- if

if GetVariable("castle_checked") == "one" then
  checkItem (7)
elseif GetVariable("castle_checked") == "two" then
  checkItem (8)
elseif GetVariable("castle_checked") == "three" then
  checkItem (9)
end -- if 

print (table.concat (menu, "|"))


Output:


! >Avatar Image|+Default|-|Browse...|<|>Background Image|Castle 1|+Castle 2|Castle 3|-|Browse...|<|-|Background Color|-|List equipment stats


You could improve on the above, but that shows the general idea.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Wuggly   USA  (112 posts)  Bio
Date Reply #2 on Tue 29 Mar 2016 03:55 PM (UTC)

Amended on Tue 29 Mar 2016 05:22 PM (UTC) by Wuggly

Message
Works perfectly.

Thanks for helping making this menu much more efficient and now I can add more menu items to it easily like adding more default avatars =)

Also doing it that way, putting the checkmarks after checking the variables makes it so it can remember where the checkmarks are for the next session which is perfect and made it simple for the first time run setting the defaults.

Very grateful!

Here's the beginning of the menu code now

function settings_click_menu ()
 menu = {
  [1] = "! >Avatar Image",
  [2] = "Default",
  [3] = "-",
  [4] = "Browse...",
  [5] = "<",
  [6] = ">Background Image",
  [7] = "Castle 1",
  [8] = "Castle 2",
  [9] = "Castle 3",
  [10] = "-",
  [11] = "Browse...",
  [12] = "<",
  [13] = "-",
  [14] = "Background Color",
  [15] = "-",
  [16] = "List equipment stats",
  }
  
 if GetVariable("castle_checked") == "one" or GetVariable("castle_checked") == nil then
  checkItem (7)
 elseif GetVariable("castle_checked") == "two" then
  checkItem (8)
 elseif GetVariable("castle_checked") == "three" then
  checkItem (9)
 elseif GetVariable("castle_checked") == "browse" then
  checkItem (11)
 end -- if 
 
 if GetVariable("avatar_checked") == "one" or GetVariable("avatar_checked") == nil then
   checkItem (2)
 elseif GetVariable("avatar_checked") == "browse" then
   checkItem (4)
 end -- if

 if GetVariable("bgColour") ~= nil then
  checkItem (14)
  menu [14] = menu [14] .. " [" .. RGBColourToName(bgColour) .. "]"
 end -- if
 result = WindowMenu (titlebar_window, 65, 15, table.concat (menu, "|"))


Don't know why I originally had the browse part of the avatar_checked called two but have changed it to browse like the castle_checked one. In fact naming it castle_checked seems kind of dumb too, should probably call it like background_checked or bg_checked lol.

And doing the menu that way, has allowed me to do cool things like when they select a background color instead of an image, it tells them the color they have picked in the menu. =)

Anyways, thanks again!
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


12,621 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.