I have been working on my senior project that involves the creation of a CDF with multiple Manipulateexpressions. I need to protect my code so I have been trying to create/encode a package that will run the program. I have gotten the program to work flawlessly as a notebook in MMA, but as a CDF I get shadowing errors. I have 54 functions in the code and many of my functions use the same variables which are changed by the user input. I have tried to put all of the code in a single package then set the initialization of each Manipulate to the same package, but I get errors. It seems like I need to have a package for each Manipulate, then have a function at the beginning of the program to call each package. I am not sure. Here is a scaled-down version.

  Initialization :> (SuccessfulShotsFor = {};)]


  Initialization :> (
    iSSF[] := 
          Button[Style[SomeStyle], , Background -> SomeBackground], 
            (ptevent0 := 
              (If[Extract[#, {1}] < 575, {1150, 740} - #, #]) &;
              Show[Image, ImageSize -> {1150, 740}]), 
            AppendTo[SuccessfulShotsFor, ptevent0[MousePosition["Graphics"]]], 
            Appearance -> Frameless], 
        WindowTitle -> "Successful Shots For", WindowFrame -> "Normal", 
        Background -> RGBColor[51/240, 163/240, 220/240], 
        Editable -> False, TextAlignment -> Center , 
        WindowSize -> {1200, 825}, WindowFloating -> False, 
        WindowMargins -> {{0, Automatic}, {Automatic, 0}}]))]


 Initialization :> (
     SuccessfulShotsFor_] := 
              AspectRatio -> Full, PlotRange -> {{0, 1150}, {0, 740}}, 
              ColorFunction -> "GreenPinkTones", Frame -> False, 
              PlotRangePadding -> 0, ImageSize -> {1150, 740}], 
          "ERROR: no user input"]
             AspectRatio -> Full, PlotRange -> {{0, 1150}, {0, 740}}, 
             PlotMarkers -> {SomePlotMarker}, Frame -> False, 
             PlotRangePadding -> 0, ImageSize -> {1150, 740}, 
             Background -> RGBColor[0, 62/240, 5/240], Axes -> False], 
         "ERROR: no user input"]))]


SuccessfulShotsFor has been giving me a ton of trouble. Once in a package, the value (which gets changed by the user input on the second Manipulate) takes on a different name which does not get passed on to the third Manipulate, which displays the images for the user to copy.

I am running these CDFs in Mathematica. I read about the $ContextPath, and I think that is the where the problem lies, but I am not experienced enough to implement the fix.

  • $\begingroup$ Thank you for the links, but I am using a package so that I can protect my code. I do not want anyone to be able to mess with the 20 pages or so of code I have. In addition, I cannot use one Manipulate, because I have nearly 30 different manipulate objects with different functions. Any ideas? $\endgroup$ – user8736 Jul 30 '13 at 20:54
  • 1
    $\begingroup$ Have you tried the TrackedSymbols option in Manipulate? This specifies which variables will initiate changes in the Manipulate. Depending on how you have coded things, you may be able to specify only those that are needed within the given manipulate. $\endgroup$ – bill s Jul 31 '13 at 0:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.