locked
Why is this program crashing? RRS feed

  • Question

  •  The following code seems to lock up after a few passes.
    Doesn't look like it is a coding problem - it just locks up.  When it locks up the Esc key doesn't work, so it's not that the lines just stop drawing.

    Also, seemed to work on my (slower) work computer, but when I got it home the window heigth is larger than 600 - looks like almost double.

    Anyone got any ideas?

    'Setup graphics window.     
    GraphicsWindow.Height=600    
    GraphicsWindow.Width=600   
    GraphicsWindow.Height=600   
    GraphicsWindow.Show()     
        
    'Show instructions     
    GraphicsWindow.Title="Random Spoke instructions"    
    GraphicsWindow.BrushColor = "Black"    
    GraphicsWindow.DrawText(10,20,"Simple instructions...")     
    GraphicsWindow.DrawText(30,40,"Down arrow to decrease speed.")     
    GraphicsWindow.DrawText(30,60,"Up arrow to increase speed.")     
    GraphicsWindow.DrawText(30,75,"(Spoke starts at fastest speed.)")     
    GraphicsWindow.DrawText(30,95,"Escape to end program.")     
    GraphicsWindow.DrawText(10,120,"Press Space Bar to start.")     
    While (GraphicsWindow.LastKey <> "Space")     
    EndWhile     
        
    'Init     
    GraphicsWindow.BackgroundColor=0    
    GraphicsWindow.Title="What does up, must come down.  Spinning wheel, got to go round..."    
        
        
    'Run game until     
    While (EndProgram<>"yes")     
        Start()     
    EndWhile     
    Program.End()     
        
    Sub Start     
        
    ' spoke turn left/right     
        GraphicsWindowGraphicsWindow.PenColor = GraphicsWindow.GetRandomColor()     
        S = Math.GetRandomNumber(100)     
        
        For X = 0 To 600 Step S     
            GraphicsWindow.DrawLine(X,0,600-X,600)     
            Program.Delay(delay)     
        '   check keypress     
            If (GraphicsWindow.LastKey = "Escape") Then     
                EndProgram = "yes"    
            EndIf     
            If (GraphicsWindow.LastKey = "Down") Then     
                delaydelay = delay + 1     
            EndIf     
            If (GraphicsWindow.LastKey = "Up") Then     
                delaydelay = delay - 1     
                If (delay < 0) Then     
                    delay = 0    
                EndIf     
            EndIf     
        EndFor     
        
        
    ' spoke turn up/down     
        GraphicsWindowGraphicsWindow.PenColor = GraphicsWindow.GetRandomColor()     
        S = Math.GetRandomNumber(100)     
        
        For Y = 0 To 600 Step S     
            GraphicsWindow.DrawLine(600,Y,0,600-y)     
            Program.Delay(delay)     
                 
        '   check keypress     
            If (GraphicsWindow.LastKey = "Escape") Then     
                EndProgram = "yes"    
            EndIf     
            If (GraphicsWindow.LastKey = "Down") Then     
                delaydelay = delay + 1     
            EndIf     
            If (GraphicsWindow.LastKey = "Up") Then     
                delaydelay = delay - 1     
                If (delay < 0) Then     
                    delay = 0    
                EndIf     
            EndIf     
        EndFor     
        
    EndSub    
     
    Thursday, November 27, 2008 2:28 PM

Answers

  • This looks like it might cause problems at some point.

        S = Math.GetRandomNumber(100)

    If Step S is 0 then your For loop will never finish executing

        For X = 0 To 600 Step S

        For Y = 0 To 600 Step S

    a simple fix
        S = Math.GetRandomNumber(100) + 1   


    Otherwise the program runs fine for me.
    • Marked as answer by Path_drc Thursday, November 27, 2008 9:37 PM
    Thursday, November 27, 2008 8:42 PM

All replies

  • It crashed as soon as I tried to launch it. 
    Thursday, November 27, 2008 3:31 PM
  • There are typos in the code, DRC.  I'm guessing it's a result of the forum formatting issues.  Can you post this without the formatting?

    Thursday, November 27, 2008 6:10 PM
  • I'll paste without using the Format Code Block:

    -----------------------------------------------------------

    'Setup graphics window.
    GraphicsWindow.Height=600
    GraphicsWindow.Width=600
    GraphicsWindow.Show()

    'Show instructions
    GraphicsWindow.Title="Random Spoke instructions"
    GraphicsWindow.BrushColor = "Black"
    GraphicsWindow.DrawText(10,20,"Simple instructions...")
    GraphicsWindow.DrawText(30,40,"Down arrow to decrease speed.")
    GraphicsWindow.DrawText(30,60,"Up arrow to increase speed.")
    GraphicsWindow.DrawText(30,75,"(Spoke starts at fastest speed.)")
    GraphicsWindow.DrawText(30,95,"Escape to end program.")
    GraphicsWindow.DrawText(10,120,"Press Space Bar to start.")
    While (GraphicsWindow.LastKey <> "Space")
    EndWhile

    'Init
    GraphicsWindow.BackgroundColor=0
    GraphicsWindow.Title="What does up, must come down.  Spinning wheel, got to go round..."


    'Run game until
    While (EndProgram<>"yes")
        Start()
    EndWhile
    Program.End()

    Sub Start

    ' spoke turn left/right
        GraphicsWindow.PenColor = GraphicsWindow.GetRandomColor()
        S = Math.GetRandomNumber(100)

        For X = 0 To 600 Step S
            GraphicsWindow.DrawLine(X,0,600-X,600)
            Program.Delay(delay)
        '   check keypress
            If (GraphicsWindow.LastKey = "Escape") Then
                EndProgram = "yes"
            EndIf
            If (GraphicsWindow.LastKey = "Down") Then
                delay = delay + 1
            EndIf
            If (GraphicsWindow.LastKey = "Up") Then
                delay = delay - 1
                If (delay < 0) Then
                    delay = 0
                EndIf
            EndIf
        EndFor


    ' spoke turn up/down
        GraphicsWindow.PenColor = GraphicsWindow.GetRandomColor()
        S = Math.GetRandomNumber(100)

        For Y = 0 To 600 Step S
            GraphicsWindow.DrawLine(600,Y,0,600-y)
            Program.Delay(delay)
           
        '   check keypress
            If (GraphicsWindow.LastKey = "Escape") Then
                EndProgram = "yes"
            EndIf
            If (GraphicsWindow.LastKey = "Down") Then
                delay = delay + 1
            EndIf
            If (GraphicsWindow.LastKey = "Up") Then
                delay = delay - 1
                If (delay < 0) Then
                    delay = 0
                EndIf
            EndIf
        EndFor

    EndSub


    -----------------------------------------------------------

    Thursday, November 27, 2008 6:37 PM
  • This looks like it might cause problems at some point.

        S = Math.GetRandomNumber(100)

    If Step S is 0 then your For loop will never finish executing

        For X = 0 To 600 Step S

        For Y = 0 To 600 Step S

    a simple fix
        S = Math.GetRandomNumber(100) + 1   


    Otherwise the program runs fine for me.
    • Marked as answer by Path_drc Thursday, November 27, 2008 9:37 PM
    Thursday, November 27, 2008 8:42 PM
  • Ohhhh...
    So Step 0 won't work.
    Didn't even think of that.

    THNX Rushworks!
    Thursday, November 27, 2008 9:36 PM