
-----------------------------------

Sun May 28, 2006 8:28 pm

Error quitting .exe
-----------------------------------
I remember someone posted this before but I couldn't find it using the 'search' at the top of this site. When you use quit, or Window.Close(defWinID), you get an error message. So how do you succesfully finish with a .exe file? Also, to close the run window when it's finished, you just tick off that box when compiling to a .exe right? But my program always like loops or is waiting for an input, therefore I need to know how to successfully end it.

-----------------------------------
Cervantes
Sun May 28, 2006 8:38 pm


-----------------------------------
The program finishes when there is no more code left to execute.

If you've got a loop, it needs to have an exit condition. Exit when the user enters "/exit" or clicks an exit button or something of that sort.

-----------------------------------

Sun May 28, 2006 8:50 pm


-----------------------------------
Aww damn, I have two seperate procs, and I need the exit statment in the Intro, but the Loop is in the game. Oh well, I'll just use Quit.

-----------------------------------
TheOneTrueGod
Sun May 28, 2006 9:09 pm


-----------------------------------
Whats the problem?  You can have more than one exit when statement if there is more than one loop.  Most games have multiple exits because of this.  Just exit (or return, though exit is a probably a better idea in some cases) the loop in the procedure, and it'll jump out of the procedure.  If you used a process... well... good luck.

Once your out of the procedure, have another exit when in the "menu" loop.

-----------------------------------

Sun May 28, 2006 9:32 pm


-----------------------------------

%Sun Fighters! V1.5
%"Last updated ", (theDayYouReadThis - theDatelastEdited), " days ago by Drew Martell"

%VARIABLES
var var1, var2, c1, c2, sun, back, ground, face, cnt, sx, sy, line, sunx, suny, file, score1, score2, size, x : int
score1 := 0
score2 := 0
cnt := 0
var timeElapsed, scoreS1, scoreS2, speedS, msg, bestTime : string
var ch : char
var timer := Font.New ("@Terminal:10")
var rec := "Sun Fighter's Best Time.rec"
var ballx1, bally1, ballx2, bally2, vx1, vy1, vx2, vy2, gravity, speed, subSpeed : real
var keys : array char of boolean

open : file, rec, put, mod
close : file
File.Status (rec, size, x, x)
if (size = 0) then
    open : file, rec, put, mod
    put : file, "0"
    close : file
end if

process Sound
    Music.Sound (100, 70)
    Music.SoundOff
end Sound

procedure Reset
    open : file, rec, get
    get : file, msg
    close : file
    bestTime := msg
    cnt := 0
    c1 := yellow
    c2 := 11
    sun := brightred
    back := black
    ground := back + 1
    face := black
    line := 50
    ballx1 := line + maxx - 100
    bally1 := line
    ballx2 := line + maxx - 150
    bally2 := line
    vx1 := 5
    vy1 := 10
    vx2 := 5
    vy2 := 10
    gravity := .25
    sunx := 100
    suny := 100
    sx := 1
    sy := 1
    speed := 15
    subSpeed := .01
end Reset

procedure Pause
    View.Update
    Input.Flush
    delay (500)
    Input.Flush
    Input.Pause
end Pause

procedure Intro
    Reset
    View.Set ("title:Sun Fighters, nocursor")
    var title := Font.New ("@Terminal:40")
    drawfillbox (0, 0, maxx, maxy, blue)
    Font.Draw ("Sun Fighters!!!", 160, 280, title, brightred)
    colourback (blue)
    colour (white)
    locate (12, 14)
    put "This is a 1 or 2 player game in which you must dodge the"
    locate (13, 20)
    put "red hot sun from melting your ass. Have fun!"
    locate (14, 33)
    colour (56)
    put "Press 'Q' to quit"
    colour (white)
    locate (16, 35)
    put "--------------"
    locate (17, 35)
    put "// CONTROLS //"
    locate (18, 35)
    put "--------------"
    locate (21, 10)
    colour (yellow)
    put "1P:   Left arrow key moves left    Right arrow key moves right"
    locate (22, 10)
    colour (11)
    put "2P:        'a' moves left               'd' moves right"
    drawbox (50, 30, maxx - 50, maxy - 30, white)
    locate (maxrow, 22)
    colour (brightgreen)
    put "Press 1 or 2 for the ammount of players"
    View.Update
    Input.Flush
    delay (500)
    Input.Flush
    ch := getchar
    if ~ ((ch = '1') or (ch = '2') or (ch = 'q')) then
        Intro
    end if
    if (ch = 'q') then
        quit %%%%%%%%%%%%%%%%%%need program to finish without errors%%%%%%%%%%%%%%%%%%%%%%%
    end if
end Intro

procedure Save
    bestTime := msg
    open : file, rec, get
    get : file, msg
    close : file
    if (strint (timeElapsed)) > (strint (msg)) then
        open : file, rec, put, mod
        put : file, timeElapsed
        close : file
    end if
end Save

procedure Player1
    drawfilloval (round (ballx1), round (bally1), 10, 10, c1)     %body
    drawoval (round (ballx1), round (bally1), 10, 10, face)     %body outline
    drawfilloval (round (ballx1) - 3, round (bally1) + 2, 1, 1, face)     %left eye
    drawfilloval (round (ballx1) + 3, round (bally1) + 2, 1, 1, face)     %right eye
    drawfillarc (round (ballx1), round (bally1) - 2, 2, 4, 180, 360, face)     %smile
end Player1

procedure Player2
    drawfilloval (round (ballx2), round (bally2), 10, 10, c2)     %body
    drawoval (round (ballx2), round (bally2), 10, 10, face)     %body outline
    drawfilloval (round (ballx2) - 3, round (bally2) + 2, 1, 1, face)     %left eye
    drawfilloval (round (ballx2) + 3, round (bally2) + 2, 1, 1, face)     %right eye
    drawfillarc (round (ballx2), round (bally2) - 2, 2, 4, 180, 360, face)     %smile
end Player2

procedure Sun
    drawfilloval (round (sunx), round (suny), 100, 100, sun)     %sun body
    drawfilloval (round (sunx) - 40, round (suny) + 30, 10, 10, face)     %left eye
    drawfilloval (round (sunx) + 40, round (suny) + 30, 10, 10, face)     %right eye
    drawfillarc (round (sunx), round (suny) - 2, 80, 80, 180, 360, face)     %smile
    drawoval (round (sunx), round (suny), 100, 100, face)     %sun outline
end Sun

proc Main
    View.Set ("offscreenonly")
    Reset
    loop
        scoreS1 := intstr (score1)
        scoreS2 := intstr (score2)
        timeElapsed := intstr (cnt div 50)
        speedS := realstr (speed, 0)
        cnt += 1

        %Painting
        drawfillbox (0, 0, maxx, maxy, back)     %background
        drawfillbox (0, 0, maxx, line, ground)     %floor
        Font.Draw ("Player 1: " + scoreS1, 10, 20, timer, c1)
        Font.Draw ("Player 2: " + scoreS2, 110, 20, timer, c2)
        Font.Draw ("TIME:" + timeElapsed, maxx - 170, 20, timer, sun)
        Font.Draw ("BEST:" + bestTime, maxx - 100, 20, timer, black)
        Font.Draw ("SPEED:" + speedS, (maxx div 2) - 50, 20, timer, back)
        Player1
        Player2
        Sun

        %Variables changing
        ballx1 += vx1
        bally1 += vy1
        ballx2 += vx2
        bally2 += vy2
        sunx += sx
        suny += sy
        vy1 -= gravity
        vy2 -= gravity

        %Boundaries
        if vy1 = -10 then
            vy1 := 10 - gravity
            fork Sound
        end if
        if vy2 = -10 then
            vy2 := 10 - gravity
        end if

        if ballx1 + 15 >= maxx then
            fork Sound
            ballx1 -= 1
            vx1 *= -1
        end if
        if ballx2 + 15 >= maxx then
            fork Sound
            ballx2 -= 1
            vx2 *= -1
        end if

        if ballx1 