Hi!
At the moment I have the following method:
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.Code:void CreateMsgGUI(string Msg, string bannerTintColor, string textColor, bool GlobalAnnouncement, BasePlayer player) { if(GlobalAnnouncement) { LoadGlobalGUI(elements); } if(!GlobalAnnouncement) { LoadPrivateGUI(player, elements); } }
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!
Solved Adding optional BasePlayer to a method? (C#)
Discussion in 'Rust Development' started by JoeSheep, Jun 9, 2016.
-
Wulf Community Admin
Add = null to the end of it and then check if player = null in the code.
-
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 -
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); } }
-
Wulf Community Admin
-
-
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.
-
Oh god I hope not!
-
-
-
Free Developer Offers | Visual Studio
Setting up a C# workspace in Visual Studio 2015 | Oxide
You will never miss a == again -
I fucking love you.