I wrote a function name as functionTest and also mentioned default Options.
BeginPackage["OptionTesting`"]
(*Options*)
Options[functionTest] := {checks -> True, bColor -> Automatic};
(*defination*)
functionTest[buttonName_, OptionsPattern[]] :=
(If[
(OptionValue[checks] == True),
(Button[buttonName, Null,Background -> OptionValue[bColor]]),
(SetOptions[OptionTesting`functionTest,bColor -> Green];
Button[buttonName, Null, Background -> OptionValue[bColor]]
)
](*if is closed*)
)
EndPackage[]
calling the above function in different cases
case1:
OptionTesting`functionTest["Ok", checks -> True]
in case1 OptionValue[checks]=True so we get Button with Backgroung color is default color.
case2:
OptionTesting`functionTest["Ok", checks -> False]
in case2 OptionValue[checks]=False so we get Button with Backgroung color is Green color.
Problems:
if you are evaluate case1 before case2,we are getting button with default color.
if you are evaluate case1 after case2,we are getting button with Green color.
but I want,
If OptionValue[check]==True,button with default color.
If OptionValue[check]==False,button with Green color
I guess because Of setOptions,it's not working.
can anybody help me?
SetOptionsis persistent--this is as it should be! If you don't want the option to persist, then don't useSetOptions--just pass the option normally. (Or at least set the option back to how it was afterwards.) I am going to vote to close this as too localized. Try this:BeginPackage["OptionTesting`"]; Options[functionTest]={checks->True,bColor->Automatic}; functionTest[buttonName_,OptionsPattern[]]:= Button[buttonName,Null,Background->If[TrueQ@OptionValue[checks],OptionValue[bColor],Green]]; EndPackage[];– Oleksandr R. Feb 1 at 11:33