Message Boards Message Boards

0
|
551 Views
|
0 Replies
|
0 Total Likes
View groups...
Share
Share this post:

How to make SessionSubmit stop when other key is pressed

Posted 6 months ago

Hello,
I am trying to make snake in Wolfram Mathematica.
I got part of code:

EventHandler[
 Dynamic[Dynamic@
   ArrayPlot@plansza], {{"KeyDown", 
    "j"} :> (SessionSubmit[
     ScheduledTask[{GLOWASNAKE = Snake[[1]], 
       GLOWASNAKE1 = {GLOWASNAKE[[1]] + 1, GLOWASNAKE[[2]]}, 
       Snake = Insert[Snake, GLOWASNAKE1, 1], zerujpkt[Last[Snake]], 
       Snake = Delete[Snake, Length[Snake]], 
       dodajdoplanszy[#, 1] & /@ Snake}, {1, 3}]]), {"KeyDown", 
    "u"} :> (SessionSubmit[
     ScheduledTask[{GLOWASNAKE = Snake[[1]], 
       GLOWASNAKE1 = {GLOWASNAKE[[1]] - 1, GLOWASNAKE[[2]]}, 
       Snake = Insert[Snake, GLOWASNAKE1, 1], zerujpkt[Last[Snake]], 
       Snake = Delete[Snake, Length[Snake]], 
       dodajdoplanszy[#, 1] & /@ Snake}, {1, 3}]]), {"KeyDown", 
    "h"} :> (SessionSubmit[
     ScheduledTask[{GLOWASNAKE = Snake[[1]], 
       GLOWASNAKE1 = {GLOWASNAKE[[1]], GLOWASNAKE[[2]] - 1}, 
       Snake = Insert[Snake, GLOWASNAKE1, 1], zerujpkt[Last[Snake]], 
       Snake = Delete[Snake, Length[Snake]], 
       dodajdoplanszy[#, 1] & /@ Snake}, {1, 3}]]), {"KeyDown", 
    "k"} :> (SessionSubmit[
     ScheduledTask[{GLOWASNAKE = Snake[[1]], 
       GLOWASNAKE1 = {GLOWASNAKE[[1]], GLOWASNAKE[[2]] + 1}, 
       Snake = Insert[Snake, GLOWASNAKE1, 1], zerujpkt[Last[Snake]], 
       Snake = Delete[Snake, Length[Snake]], 
       dodajdoplanszy[#, 1] & /@ Snake}, {1, 3}]])}] 

And I'm trying to change "3" in a {1,3} part to something, that would stop the current task, when the other key is pressed on keyboard.
How to do this?

POSTED BY: Monika Mróz
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract