1. Hi!

    At the moment I have the following method:

    Code:
    void CreateMsgGUI(string Msg, string bannerTintColor, string textColor, bool GlobalAnnouncement, BasePlayer player)
    {
        if(GlobalAnnouncement)
        {
            LoadGlobalGUI(elements);
        }
        if(!GlobalAnnouncement)
        {
            LoadPrivateGUI(player, elements);
        }
    }
    I have other methods that will call "CreateMsgGUI" some which are not meant to call it like "CreateMsgGUI(player)" that don't have BasePlayer player declared and some which are and have BasePlayer player declared. I couldn't figure out how to make BasePlayer an option parameter in the CreateMsgGUI method so I put "BasePlayer player = null;" in the class scope other wise I would get "player does not exist in the current context" in method where it hasn't been declared.

    I would like to know if it is possible to make BasePlayer an option parameter in the CreateMsgGUI method, if not is declaring "BasePlayer player = null;" in the class scope a bad thing to do? What are the alternatives other than making to methods, one for GUI that doesn't need a player and one that does?

    Cheers!
     
    Last edited by a moderator: Jun 10, 2016
  2. Wulf

    Wulf Community Admin

    Add = null to the end of it and then check if player = null in the code.
     
  3. Oh my fucking god I can be really dim sometimes especially considering I put "BasePlayer player = null;" in the class scope... xD

    That means I can get rid of the bool GlobalAnnouncement too.

    Cheers @Wulf
     
  4. Code:
    void CreateMsgGUI(string Msg, string bannerTintColor, string textColor, BasePlayer player = null)
            {
                Puts("CreateMsgGUI Method");
                if(player = null)
                {
                    Puts("player = null, global announcement");
                    LoadGlobalGUI(elements);
                }
                if(player != null)
                {
                    Puts("player != null, private announcement");
                    LoadPrivateGUI(player, elements);
                }
            }
    Called with or without all parameters it does literally nothing. The code will only execute "Puts("CreateMsgGUI Method");" and nothing else. I get the feeling I may be being thick again, but any ideas?
     
  5. Wulf

    Wulf Community Admin

    if (player == null)
     
  6. I knew it, being a class A dim wit. I have checked = so many times before properly. Thanks dude.
     
  7. Hahaha forgetting the second = sign will follow you throughout all your programming adventures if you're anything like me. Been programming for 6 years and I still forget it and end up tearing out my hair wondering why something isn't working as it should be.
     
  8. Oh god I hope not!
     
  9. Use visual studio and it will highlight the error nearly immediately.
     
  10. I would if I had the money to pay for it.
     
  11. I fucking love you.