1
$\begingroup$

When the messages change the window inactivates, and when I try to host an interactive CDF on my site it turns red and says something about numbers having to be scaled or offset. Any help?

I'm specifically trying to figure out why the window deactivates when the variable message is changed dynamically.

$\hspace{3cm}$enter image description here

bound = {{2, -1}, {2, 5}, {1, 0}, {3, 0}, {0, 1}, {4, 1}, {0, 2}, {4, 
   2}, {-1, 3}, {5, 3}, {-1, 4}, {5, 4}, {-1, 5}, {5, 5}, {0, 6}, {1, 
   6}, {3, 6}, {4, 6}}

DynamicModule[
 {
  pos1 = {x1, y1} = {2, 2}, pos2 = {x2, y2} = {2, 4}, 
  pos3 = {x3, y3} = {2, 0},
  message = "Start",
  DotT = {a2, b2} = {x2, (y2 - 0.51)}, 
  DotL = {a1, b1} = {x1, (y1 + 0.51)}, 
  DotB = {a3, b3} = {x3, (y3 + 0.51)},
  Switch = True, Stick = False
  },
 EventHandler[
  Dynamic[
   Magnify[
    Graphics[
     {
      Opacity[0.9],
      Blue, {Arrowheads[Large], Arrow[{pos2, DotT}]},
      Green, {Arrowheads[Large], Arrow[{pos1, DotL}]},
      Blue, {Arrowheads[Large], Arrow[{pos3, DotB}]},
      Style[Text[message, {2, 5}], FontFamily -> "Helvetica", Small, 
       Gray, FontSize -> 15],
      Gray, Disk[{0, 5}, .1],
      Gray, Disk[{0, 4}, .1],
      Gray, Disk[{0, 3}, .1],
      Gray, Disk[{1, 5}, .1],
      Black, Disk[{1, 4}, .1],
      Gray, Disk[{1, 3}, .1],
      Gray, Disk[{3, 5}, .1],
      Black, Disk[{3, 4}, .1],
      Gray, Disk[{3, 3}, .1],
      Gray, Disk[{4, 5}, .1],
      Gray, Disk[{4, 4}, .1],
      Gray, Disk[{4, 3}, .1],
      Gray, Disk[{1, 1}, .1],
      Gray, Disk[{2, 1}, .1],
      Gray, Disk[{3, 1}, .1],
      Gray, Disk[{1, 2}, .1],
      Gray, Disk[{2, 2}, .1],
      Gray, Disk[{3, 2}, .1],
      Gray, Disk[{2, 0}, .1],
      Gray, Disk[{2, 3}, .1],
      Gray, Disk[{2, 4}, .1],
      Green, Disk[pos1, .25],
      Style[Text[L, pos1], FontFamily -> "Helvetica", Large, White],
      Blue, Disk[pos2, .25],
      Style[Text[T, pos2], FontFamily -> "Helvetica", Large, White],
      Blue, Disk[pos3, .25],
      Style[Text[B, pos3], FontFamily -> "Helvetica", Large, White]
      }
     ]
    ]
   ],
  {
   "UpArrowKeyDown" :> {
     message = "", Switch = True, Stick = False,
     If[(**)
      {x1, y1 + 1} == {x2, y2 - 1} || {x1, y1 + 1} == {x2, y2} || {x1,
          y1 + 1} == {x3, y3} || {x3, y3 + 1} == {x2, y2 - 1} || {x3, 
         y3 + 1} == {x2, y2},
      {
       Which[
        {x3, y3 + 1} == {x2, y2 - 1},
        {pos1 = pos1 /. {{x1, y1} -> {x1 = x1, y1 = y1 + 1}}, 
         pos2 = pos2, pos3 = pos3},
        {x3, y3 + 1} == {x2, y2},
        {pos1 = pos1 /. {{x1, y1} -> {x1 = x1, y1 = y1 + 1}}, 
         pos2 = pos2, pos3 = pos3},
        {x1, y1 + 1} == {x2, y2 - 1},
        {
         pos1 = pos1 /. {{x1, y1} -> {x1 = 2, y1 = 2}},
         pos2 = pos2 /. {{x2, y2} -> {x2 = 2, y2 = 4}},
         pos3 = pos3 /. {{x3, y3} -> {x3 = 2, y3 = 0}},
         message = "Gameover",
         DotT = {2, (4 - .51)}, DotL = {2, (2 + .51)}, 
         DotB = {2, (0 + .51)},
         Switch = False
         },
        {x1, y1 + 1} == {x2, y2},
        {
         pos1 = pos1 /. {{x1, y1} -> {x1 = x1, y1 = y1}},
         pos2 = pos2 /. {{x2, y2} -> {x2 = x2, y2 = y2}},
         pos3 = pos3 /. {{x3, y3} -> {x3 = x3, y3 = y3}}
         },
        {x1, y1 + 1} == {x3, y3},
        {
         Which[
          Intersection[bound, {{x3, y3 + 1}}] == {{x3, y3 + 1}},
          {
           pos1 = pos1 /. {{x1, y1} -> {x1 = x1, y1 = y1}},
           pos2 = pos2 /. {{x2, y2} -> {x2 = x2, y2 = y2}},
           pos3 = pos3 /. {{x3, y3} -> {x3 = x3, y3 = y3}}
           },
          {x3, y3 + 1} == {x2, y2 - 1},
          {
           pos1 = pos1 /. {{x1, y1} -> {x1 = 2, y1 = 2}},
           pos2 = pos2 /. {{x2, y2} -> {x2 = 2, y2 = 4}},
           pos3 = pos3 /. {{x3, y3} -> {x3 = 2, y3 = 0}},
           message = "Gameover",
           DotT = {2, (4 - .51)}, DotL = {2, (2 + .51)}, 
           DotB = {2, (0 + .51)},
           Switch = False
           },
          Intersection[bound, {{x3, y3 + 1}}] != {{x3, y3 + 1}},
          {
           pos1 = pos1 /. {{x1, y1} -> {x1 = x1, y1 = y1 + 1}},
           pos2 = pos2 /. {{x2, y2} -> {x2 = x2, y2 = y2 - 1}},
           pos3 = pos3 /. {{x3, y3} -> {x3 = x3, y3 = y3 + 1}}
           }
          ]
         }
        ]
       },
      {
       If[(*Test if next move out of bound.*)
        Intersection[bound, {{x1, y1 + 1}}] == {{x1, y1 + 1}},
        {
         pos1 = pos1 /. {{x1, y1} -> {x1 = x1, y1 = y1}}, Stick = True
         },
        pos1 = pos1 /. {{x1, y1} -> {x1 = x1, y1 = y1 + 1}}
        ],
       If[(*Test if next move out of bound.*)
        Intersection[bound, {{x2, y2 - 1}}] == {{x2, y2 - 1}},
        pos2 = pos2 /. {{x2, y2} -> {x2 = x2, y2 = y2}},
        If[
         Stick == True,
         pos2 = pos2 /. {{x2, y2} -> {x2 = x2, y2 = y2}},
         pos2 = pos2 /. {{x2, y2} -> {x2 = x2, y2 = y2 - 1}}
         ]
        ],
       If[(*Test if next move out of bound.*)
        Intersection[bound, {{x3, y3 + 1}}] == {{x3, y3 + 1}},
        pos3 = pos3 /. {{x3, y3} -> {x3 = x3, y3 = y3}},
        If[
         Stick == True,
         pos3 = pos3 /. {{x3, y3} -> {x3 = x3, y3 = y3}},
         pos3 = pos3 /. {{x3, y3} -> {x3 = x3, y3 = y3 + 1}}
         ]
        ]
       }
      ],
     If[
      Switch == True,
      {
       DotT = {a2 = x2, b2 = y2 - .51}, 
       DotL = {a1 = x1, b1 = y1 + .51}, DotB = {a3 = x3, b3 = y3 + .51}
       }
      ],
     Switch = True,
     If[
      {x2, y2} == {1, 4} && {x3, y3} == {3, 4} || {x3, y3} == {1, 
          4} && {x2, y2} == {3, 4},
      message = "Win"
      ]
     },
   "DownArrowKeyDown" :> {
     message = "", Switch = True, Stick = False,
     If[(**)
      {x1, y1 - 1} == {x2, y2 + 1} || {x1, y1 - 1} == {x2, y2} || {x1,
          y1 - 1} == {x3, y3} || {x3, y3 - 1} == {x2, y2 + 1} || {x3, 
         y3 - 1} == {x2, y2},
      {
       Which[
        {x3, y3 - 1} == {x2, y2 + 1},
        {pos1 = pos1 /. {{x1, y1} -> {x1 = x1, y1 = y1 - 1}}, 
         pos2 = pos2, pos3 = pos3},
        {x3, y3 - 1} == {x2, y2},
        {pos1 = pos1 /. {{x1, y1} -> {x1 = x1, y1 = y1 - 1}}, 
         pos2 = pos2, pos3 = pos3},
        {x1, y1 - 1} == {x2, y2 + 1},
        {
         pos1 = pos1 /. {{x1, y1} -> {x1 = 2, y1 = 2}},
         pos2 = pos2 /. {{x2, y2} -> {x2 = 2, y2 = 4}},
         pos3 = pos3 /. {{x3, y3} -> {x3 = 2, y3 = 0}},
         message = "Gameover",
         DotT = {2, (4 - .51)}, DotL = {2, (2 + .51)}, 
         DotB = {2, (0 + .51)},
         Switch = False
         },
        {x1, y1 - 1} == {x2, y2},
        {
         pos1 = pos1 /. {{x1, y1} -> {x1 = x1, y1 = y1}},
         pos2 = pos2 /. {{x2, y2} -> {x2 = x2, y2 = y2}},
         pos3 = pos3 /. {{x3, y3} -> {x3 = x3, y3 = y3}}
         },
        {x1, y1 - 1} == {x3, y3},
        {
         Which[
          Intersection[bound, {{x3, y3 - 1}}] == {{x3, y3 - 1}},
          {
           pos1 = pos1 /. {{x1, y1} -> {x1 = x1, y1 = y1}},
           pos2 = pos2 /. {{x2, y2} -> {x2 = x2, y2 = y2}},
           pos3 = pos3 /. {{x3, y3} -> {x3 = x3, y3 = y3}}
           },
          {x3, y3 - 1} == {x2, y2 + 1},
          {
           pos1 = pos1 /. {{x1, y1} -> {x1 = 2, y1 = 2}},
           pos2 = pos2 /. {{x2, y2} -> {x2 = 2, y2 = 4}},
           pos3 = pos3 /. {{x3, y3} -> {x3 = 2, y3 = 0}},
           message = "Gameover",
           DotT = {2, (4 - .51)}, DotL = {2, (2 + .51)}, 
           DotB = {2, (0 + .51)},
           Switch = False
           },
          Intersection[bound, {{x3, y3 - 1}}] != {{x3, y3 - 1}},
          {
           pos1 = pos1 /. {{x1, y1} -> {x1 = x1, y1 = y1 - 1}},
           pos2 = pos2 /. {{x2, y2} -> {x2 = x2, y2 = y2 + 1}},
           pos3 = pos3 /. {{x3, y3} -> {x3 = x3, y3 = y3 - 1}}
           }
          ]
         }
        ]
       },
      {
       If[(*Test if next move out of bound.*)
        Intersection[bound, {{x1, y1 - 1}}] == {{x1, y1 - 1}},
        {
         pos1 = pos1 /. {{x1, y1} -> {x1 = x1, y1 = y1}}, Stick = True
         },
        pos1 = pos1 /. {{x1, y1} -> {x1 = x1, y1 = y1 - 1}}
        ],
       If[(*Test if next move out of bound.*)
        Intersection[bound, {{x2, y2 + 1}}] == {{x2, y2 + 1}},
        pos2 = pos2 /. {{x2, y2} -> {x2 = x2, y2 = y2}},
        If[
         Stick == True,
         pos2 = pos2 /. {{x2, y2} -> {x2 = x2, y2 = y2}},
         pos2 = pos2 /. {{x2, y2} -> {x2 = x2, y2 = y2 + 1}}
         ]
        ],
       If[(*Test if next move out of bound.*)
        Intersection[bound, {{x3, y3 - 1}}] == {{x3, y3 - 1}},
        pos3 = pos3 /. {{x3, y3} -> {x3 = x3, y3 = y3}},
        If[
         Stick == True,
         pos3 = pos3 /. {{x3, y3} -> {x3 = x3, y3 = y3}},
         pos3 = pos3 /. {{x3, y3} -> {x3 = x3, y3 = y3 - 1}}
         ]
        ]
       }
      ],
     If[
      Switch == True,
      {
       DotT = {a2 = x2, b2 = y2 + .51}, 
       DotL = {a1 = x1, b1 = y1 - .51}, DotB = {a3 = x3, b3 = y3 - .51}
       }
      ],
     Switch = True,
     If[
      {x2, y2} == {1, 4} && {x3, y3} == {3, 4} || {x3, y3} == {1, 
          4} && {x2, y2} == {3, 4},
      message = "Win"
      ]
     },
   "LeftArrowKeyDown" :> {
     message = "", Switch = True, Stick = False,
     If[(**)
      {x1 - 1, y1} == {x2 + 1, y2} || {x1 - 1, y1} == {x2, 
         y2} || {x1 - 1, y1} == {x3, y3} || {x3 - 1, y3} == {x2 + 1, 
         y2} || {x3 - 1, y3} == {x2, y2},
      {
       Which[
        {x3 - 1, y3} == {x2 + 1, y2},
        {pos1 = pos1 /. {{x1, y1} -> {x1 = x1 - 1, y1 = y1}}, 
         pos2 = pos2, pos3 = pos3},
        {x3 - 1, y3} == {x2, y2}, {pos1 = 
          pos1 /. {{x1, y1} -> {x1 = x1 - 1, y1 = y1}}, pos2 = pos2, 
         pos3 = pos3},
        {x1 - 1, y1} == {x2 + 1, y2},
        {
         pos1 = pos1 /. {{x1, y1} -> {x1 = 2, y1 = 2}},
         pos2 = pos2 /. {{x2, y2} -> {x2 = 2, y2 = 4}},
         pos3 = pos3 /. {{x3, y3} -> {x3 = 2, y3 = 0}},
         message = "Gameover",
         DotT = {2, (4 - .51)}, DotL = {2, (2 + .51)}, 
         DotB = {2, (0 + .51)},
         Switch = False
         },
        {x1 - 1, y1} == {x2, y2},
        {
         pos1 = pos1 /. {{x1, y1} -> {x1 = x1, y1 = y1}},
         pos2 = pos2 /. {{x2, y2} -> {x2 = x2, y2 = y2}},
         pos3 = pos3 /. {{x3, y3} -> {x3 = x3, y3 = y3}}
         },
        {x1 - 1, y1} == {x3, y3},
        {
         Which[
          Intersection[bound, {{x3 - 1, y3}}] == {{x3 - 1, y3}},
          {
           pos1 = pos1 /. {{x1, y1} -> {x1 = x1, y1 = y1}},
           pos2 = pos2 /. {{x2, y2} -> {x2 = x2, y2 = y2}},
           pos3 = pos3 /. {{x3, y3} -> {x3 = x3, y3 = y3}}
           },
          {x3 - 1, y3} == {x2 + 1, y2},
          {
           pos1 = pos1 /. {{x1, y1} -> {x1 = 2, y1 = 2}},
           pos2 = pos2 /. {{x2, y2} -> {x2 = 2, y2 = 4}},
           pos3 = pos3 /. {{x3, y3} -> {x3 = 2, y3 = 0}},
           message = "Gameover",
           DotT = {2, (4 - .51)}, DotL = {2, (2 + .51)}, 
           DotB = {2, (0 + .51)},
           Switch = False
           },
          Intersection[bound, {{x3 - 1, y3}}] != {{x3 - 1, y3}},
          {
           pos1 = pos1 /. {{x1, y1} -> {x1 = x1 - 1, y1 = y1}},
           pos2 = pos2 /. {{x2, y2} -> {x2 = x2 + 1, y2 = y2}},
           pos3 = pos3 /. {{x3, y3} -> {x3 = x3 - 1, y3 = y3}}
           }
          ]
         }
        ]
       },
      {
       If[(*Test if next move out of bound.*)
        Intersection[bound, {{x1 - 1, y1}}] == {{x1 - 1, y1}},
        {
         pos1 = pos1 /. {{x1, y1} -> {x1 = x1, y1 = y1}},
         Stick = True
         },
        pos1 = pos1 /. {{x1, y1} -> {x1 = x1 - 1, y1 = y1}}
        ],
       If[(*Test if next move out of bound.*)
        Intersection[bound, {{x2 + 1, y2}}] == {{x2 + 1, y2}},
        pos2 = pos2 /. {{x2, y2} -> {x2 = x2, y2 = y2}},
        If[
         Stick == True,
         pos2 = pos2 /. {{x2, y2} -> {x2 = x2, y2 = y2}},
         pos2 = pos2 /. {{x2, y2} -> {x2 = x2 + 1, y2 = y2}}
         ]
        ],
       If[(*Test if next move out of bound.*)
        Intersection[bound, {{x3 - 1, y3}}] == {{x3 - 1, y3}},
        pos3 = pos3 /. {{x3, y3} -> {x3 = x3, y3 = y3}},
        If[
         Stick == True,
         pos3 = pos3 /. {{x3, y3} -> {x3 = x3, y3 = y3}},
         pos3 = pos3 /. {{x3, y3} -> {x3 = x3 - 1, y3 = y3}}
         ]
        ]
       }
      ],
     If[
      Switch == True,
      {
       DotT = {a2 = x2 + .51, b2 = y2}, 
       DotL = {a1 = x1 - .51, b1 = y1}, DotB = {a3 = x3 - .51, b3 = y3}
       }
      ],
     Switch = True,
     If[
      {x2, y2} == {1, 4} && {x3, y3} == {3, 4} || {x3, y3} == {1, 
          4} && {x2, y2} == {3, 4},
      message = "Win"
      ]
     },
   "RightArrowKeyDown" :> {
     message = "", Switch = True, Stick = False,
     If[(**)
      {x1 + 1, y1} == {x2 - 1, y2} || {x1 + 1, y1} == {x2, 
         y2} || {x1 + 1, y1} == {x3, y3} || {x3 + 1, y3} == {x2 - 1, 
         y2} || {x3 + 1, y3} == {x2, y2},
      {
       Which[
        {x3 + 1, y3} == {x2 - 1, y2},
        {pos1 = pos1 /. {{x1, y1} -> {x1 = x1 + 1, y1 = y1}}, 
         pos2 = pos2, pos3 = pos3},
        {x3 + 1, y3} == {x2, y2},
        {pos1 = pos1 /. {{x1, y1} -> {x1 = x1 + 1, y1 = y1}}, 
         pos2 = pos2, pos3 = pos3},
        {x1 + 1, y1} == {x2 - 1, y2},
        {
         pos1 = pos1 /. {{x1, y1} -> {x1 = 2, y1 = 2}},
         pos2 = pos2 /. {{x2, y2} -> {x2 = 2, y2 = 4}},
         pos3 = pos3 /. {{x3, y3} -> {x3 = 2, y3 = 0}},
         message = "Gameover",
         DotT = {2, (4 - .51)}, DotL = {2, (2 + .51)}, 
         DotB = {2, (0 + .51)},
         Switch = False
         },
        {x1 + 1, y1} == {x2, y2},
        {
         pos1 = pos1 /. {{x1, y1} -> {x1 = x1, y1 = y1}},
         pos2 = pos2 /. {{x2, y2} -> {x2 = x2, y2 = y2}},
         pos3 = pos3 /. {{x3, y3} -> {x3 = x3, y3 = y3}}
         },
        {x1 + 1, y1} == {x3, y3},
        {
         Which[
          Intersection[bound, {{x3 + 1, y3}}] == {{x3 + 1, y3}},
          {
           pos1 = pos1 /. {{x1, y1} -> {x1 = x1, y1 = y1}},
           pos2 = pos2 /. {{x2, y2} -> {x2 = x2, y2 = y2}},
           pos3 = pos3 /. {{x3, y3} -> {x3 = x3, y3 = y3}}
           },
          {x3 + 1, y3} == {x2 - 1, y2},
          {
           pos1 = pos1 /. {{x1, y1} -> {x1 = 2, y1 = 2}},
           pos2 = pos2 /. {{x2, y2} -> {x2 = 2, y2 = 4}},
           pos3 = pos3 /. {{x3, y3} -> {x3 = 2, y3 = 0}},
           message = "Gameover",
           DotT = {2, (4 - .51)}, DotL = {2, (2 + .51)}, 
           DotB = {2, (0 + .51)},
           Switch = False
           },
          Intersection[bound, {{x3 + 1, y3}}] != {{x3 + 1, y3}},
          {
           pos1 = pos1 /. {{x1, y1} -> {x1 = x1 + 1, y1 = y1}},
           pos2 = pos2 /. {{x2, y2} -> {x2 = x2 - 1, y2 = y2}},
           pos3 = pos3 /. {{x3, y3} -> {x3 = x3 + 1, y3 = y3}}
           }
          ]
         }
        ]
       },
      {
       If[(*Test if next move out of bound.*)
        Intersection[bound, {{x1 + 1, y1}}] == {{x1 + 1, y1}},
        {
         pos1 = pos1 /. {{x1, y1} -> {x1 = x1, y1 = y1}},
         Stick = True
         },
        pos1 = pos1 /. {{x1, y1} -> {x1 = x1 + 1, y1 = y1}}
        ],
       If[(*Test if next move out of bound.*)
        Intersection[bound, {{x2 - 1, y2}}] == {{x2 - 1, y2}},
        pos2 = pos2 /. {{x2, y2} -> {x2 = x2, y2 = y2}},
        If[
         Stick == True,
         pos2 = pos2 /. {{x2, y2} -> {x2 = x2, y2 = y2}},
         pos2 = pos2 /. {{x2, y2} -> {x2 = x2 - 1, y2 = y2}}
         ]
        ],
       If[(*Test if next move out of bound.*)
        Intersection[bound, {{x3 + 1, y3}}] == {{x3 + 1, y3}},
        pos3 = pos3 /. {{x3, y3} -> {x3 = x3, y3 = y3}},
        If[
         Stick == True,
         pos3 = pos3 /. {{x3, y3} -> {x3 = x3, y3 = y3}},
         pos3 = pos3 /. {{x3, y3} -> {x3 = x3 + 1, y3 = y3}}
         ]
        ]
       }
      ],
     If[
      Switch == True,
      {
       DotT = {a2 = x2 - .51, b2 = y2}, 
       DotL = {a1 = x1 + .51, b1 = y1}, 
       DotB = {a3 = x3 + .51, b3 = y3}}
      ],
     Switch = True,
     If[
      {x2, y2} == {1, 4} && {x3, y3} == {3, 4} || {x3, y3} == {1, 
          4} && {x2, y2} == {3, 4},
      message = "Win"
      ]
     }
   }
  ]
 ]

I made a cute one here.

$\hspace{3cm}$enter image description here

$\endgroup$
11
  • $\begingroup$ I want to publish the game on Wolfram Demonstrations. $\endgroup$
    – Sam
    May 17, 2015 at 21:36
  • $\begingroup$ To play, you have to click the window, then use only the arrow keys to move the green (L) around so that the two blue dots simultaneously land on the two black dots separately. You have to reclick the window if the message changes to continue playing. $\endgroup$
    – Sam
    May 17, 2015 at 21:37
  • $\begingroup$ An example of a win is the following move series: RDUUULLDDDRU Where (R)ight, (U)p, (L)eft, and (D)own. $\endgroup$
    – Sam
    May 17, 2015 at 21:43
  • 1
    $\begingroup$ 1) You need to narrow down your problem a lot more before we can start helping. Unfortunately I don't have the time to wade through a few pages of code without even knowing what exactly is wrong. 2) I tried copying your of code and executing it, but all I get is a static grid. No amount of R, U, L, D gets me anywhere. $\endgroup$
    – MarcoB
    May 17, 2015 at 21:45
  • 3
    $\begingroup$ I'm voting to close this question as this is not a debugging service. Please reduce your code to the minimal example in which your issue can be reproduced. $\endgroup$
    – Kuba
    May 18, 2015 at 5:44

0