none
Multiple Tasks in Small Basic RRS feed

  • Question

  • Is it possible to run two tasks at once in Small Basic? I want to have a timer counting down in the text window, but if the user pushes a number combination on the keypad, the program will close. How would I do this?

    Tuesday, May 21, 2013 1:24 PM

Answers

  • Try the following program and make adaptations for your wishes:

    Timer.Interval=1000
    Timer.Tick=tik
    
    
    Sub tik
      TextWindow.WriteLine(Clock.Time)
      k=TextWindow.readkey()
      TextWindow.WriteLine(">>>"+k)
      If k=5 Then
        Timer.Pause()
        TextWindow.WriteLine("STOPPED")
       Program.Delay(3000)
       Program.End()
      endif
    EndSub
        


    Jan [ WhTurner ] The Netherlands

    • Marked as answer by tomnance Tuesday, May 21, 2013 3:43 PM
    Tuesday, May 21, 2013 2:00 PM
    Answerer

All replies

  • Try the following program and make adaptations for your wishes:

    Timer.Interval=1000
    Timer.Tick=tik
    
    
    Sub tik
      TextWindow.WriteLine(Clock.Time)
      k=TextWindow.readkey()
      TextWindow.WriteLine(">>>"+k)
      If k=5 Then
        Timer.Pause()
        TextWindow.WriteLine("STOPPED")
       Program.Delay(3000)
       Program.End()
      endif
    EndSub
        


    Jan [ WhTurner ] The Netherlands

    • Marked as answer by tomnance Tuesday, May 21, 2013 3:43 PM
    Tuesday, May 21, 2013 2:00 PM
    Answerer
  • Thank you so much! It works!!!

    Tuesday, May 21, 2013 3:43 PM
  • In this post below:

    Death Valley

    I used the category Timer to overcome the lack of a inkey() method that reads a key from keyboard w/o pausing the program!

    And curiously, Timer.Tick is the only event which works in TextWindow category!

    At the game above, a little story is slowly displayed in the TextWindow.

    However, if any keys are pressed, that is skipped immediately and goes direct to game!  :D

    Once the action actually starts, the main execution thread, called the InKey Loop, is responsible to read a key from keyboard using TextWindow.ReadKey().

    And a new thread, the Sub GameLoop, is called is parallel through Timer.Tick at a specified FPS, which keeps increasing as the ship character gets near the end of the ravine!

    Well, that's it! My super trick to make action games in TextWindow mode! ^_^


    Click on "Propose As Answer" if some post solves your problem or "Vote As Helpful" if some post has been useful to you! (^_^)

    Tuesday, May 21, 2013 8:40 PM
    Answerer
  • Try the following program and make adaptations for your wishes:

    Timer.Interval=1000
    Timer.Tick=tik
    
    
    Sub tik
      TextWindow.WriteLine(Clock.Time)
      k=TextWindow.readkey()
      TextWindow.WriteLine(">>>"+k)
      If k=5 Then
        Timer.Pause()
        TextWindow.WriteLine("STOPPED")
       Program.Delay(3000)
       Program.End()
      endif
    EndSub
        


    Jan [ WhTurner ] The Netherlands


    This solution could become a TechNet Wiki article and enter the July Small Basic Guru contest: http://social.technet.microsoft.com/wiki/contents/articles/18211.technet-guru-contributions-july-2013.aspx

    It doesn't matter when the content was originally written, as long as the Wiki version was published in July.

    Great job!


    Ed Price (a.k.a User Ed), SQL Server Customer Program Manager (Blog, Small Basic, Wiki Ninjas, Wiki)

    Answer an interesting question? Create a wiki article about it!

    Tuesday, July 23, 2013 6:31 AM
    Owner