
-----------------------------------
uknowhoiam
Wed May 13, 2009 4:58 pm

File I/O getting information
-----------------------------------
What is it you are trying to achieve?
I want to show the best time


What is the problem you are having?
it shows 0 all the time and the first number is always 0 in the text file


Describe what you have tried to solve this problem
Everything

Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)



import GUI
View.Set ("graphics:300;400,offscreenonly")

var ballx, bally, xpos, xpos2, ypos, gravity : real
var best, line, Colour, face, brick_colour, brickx, bricky, brickx2, bricky2, brickx3, bricky3, brickx4, bricky4, brickx5, bricky5, brickx6, bricky6, brickx7, bricky7, brickx8, bricky8, dotx, doty,
    dotx2,
    doty2, dotx3, dotx4, doty3, doty4, doty5, doty6, doty7, doty8, score, picID, destination, speed, level : int
var keys : array char of boolean
var fail, die, safe : boolean := false
var Score : boolean := true
var fontID, height, ascent, descent, internalLeading : int
var rec : int
var recfile : string := "Happy Ball.txt"
open : rec, recfile, put, get, seek

Colour := 119
face := 255
line := 50
ballx := line + maxx - 100
bally := line
xpos := 1
xpos2 := -1
ypos := 8
gravity := .25
brickx := Rand.Int (0, 250 - 40)
bricky := Rand.Int (50, 90)
brickx2 := brickx + 40
bricky2 := bricky + 15
brickx3 := Rand.Int (0, 250 - 40)
bricky3 := Rand.Int (130, 200)
brickx4 := brickx3 + 40
bricky4 := bricky3 + 15
brickx5 := Rand.Int (0, 250 - 40)
bricky5 := Rand.Int (245, 275)
brickx6 := brickx5 + 40
bricky6 := bricky5 + 15
brickx7 := Rand.Int (0, 250 - 40)
bricky7 := Rand.Int (305, 350)
brickx8 := brickx7 + 40
bricky8 := bricky7 + 15
brick_colour := brown
dotx := maxx div 4
doty := 10
dotx2 := dotx + 3
doty2 := doty + 15
dotx3 := maxx div 2 + dotx
dotx4 := dotx3 + 3
doty3 := 110
doty4 := doty3 + 15
doty5 := 210
doty6 := doty5 + 15
doty7 := 310
doty8 := doty7 + 15
score := 0
destination := 500
speed := 17
level := 1


colourback (103)
cls



procedure Player
    drawfilloval (round (ballx), round (bally), 10, 10, Colour)     %body
    drawoval (round (ballx), round (bally), 10, 10, face)     %body outline
    drawfilloval (round (ballx) - 3, round (bally) + 2, 1, 1, face)     %left eye
    drawfilloval (round (ballx) + 3, round (bally) + 2, 1, 1, face)     %right eye
    drawfillarc (round (ballx), round (bally) - 2, 2, 4, 180, 360, face)     %smile
end Player

procedure background
    colourback (103)
    drawfillbox (dotx, doty, dotx2, doty2, black)
    drawfillbox (dotx, doty3, dotx2, doty4, black)
    drawfillbox (dotx, doty5, dotx2, doty6, black)
    drawfillbox (dotx, doty7, dotx2, doty8, black)
    drawfillbox (dotx3, doty, dotx4, doty2, black)
    drawfillbox (dotx3, doty3, dotx4, doty4, black)
    drawfillbox (dotx3, doty5, dotx4, doty6, black)
    drawfillbox (dotx3, doty7, dotx4, doty8, black)
end background

procedure game
    loop
        background
        drawfillbox (brickx, bricky, brickx2, bricky2, brick_colour)
        drawfillbox (brickx3, bricky3, brickx4, bricky4, brick_colour)
        drawfillbox (brickx5, bricky5, brickx6, bricky6, brick_colour)
        drawfillbox (brickx7, bricky7, brickx8, bricky8, brick_colour)
        Player
        View.Update
        delay (speed)
        cls

        ballx -= xpos
        bally += ypos
        ypos -= gravity

        if bally = bricky + 10 and ballx = brickx then %%i assume 10 is the size of the ball?
            ypos := 10 - gravity
        elsif bally = bricky3 + 10 and ballx = brickx3 then
            ypos := 10 - gravity
        elsif bally = bricky5 + 10 and ballx = brickx5 then
            ypos := 10 - gravity
        elsif bally = bricky7 + 10 and ballx = brickx7 then
            ypos := 10 - gravity
            fail := true
        end if



        if bally >= 230 then
            score += 2

            doty -= 2

            doty2 -= 2

            doty3 -= 2

            doty4 -= 2

            doty5 -= 2

            doty6 -= 2

            doty7 -= 2

            doty8 -= 2

            bally -= 2

            bricky -= 2

            bricky2 -= 2

            bricky3 -= 2

            bricky4 -= 2

            bricky5 -= 2

            bricky6 -= 2

            bricky7 -= 2

            bricky8 -= 2
        end if

        if bally > maxy then

            score += 10

            doty -= 2

            doty2 -= 2

            doty3 -= 2

            doty4 -= 2

            doty5 -= 2

            doty6 -= 2

            doty7 -= 2

            doty8 -= 2

            bally -= 2

            bricky -= 2

            bricky2 -= 2

            bricky3 -= 2

            bricky4 -= 2

            bricky5 -= 2

            bricky6 -= 2

            bricky7 -= 2

            bricky8 -= 2
        end if


        put : rec, score
        seek : rec, 0
        get : rec, best

        if doty2 = 3 then
            xpos := 2
        end if
        if xpos = destination then
            destination += 1200
            speed -= 1
            level += 1
        end if

        locate (3, 1)
        colour (105)
        put "LVL: ", level

        locate (3, maxcol - 11)
        put "Best: ", best

        locate (1, 1)
        colour (105)
        put "Next Level: ", destination

        locate (1, maxcol - 11)
        colour (105)
        put "Score: ", score

        Input.KeyDown (keys)
        if keys (KEY_RIGHT_ARROW) then
            xpos -= 2
        end if
        if keys (KEY_LEFT_ARROW) then
            xpos += 2
        end if
    end loop
end game

procedure instruction     %instruction procedure
    cls
    colour (105)
    put repeat ("%", maxcol)
    locate (2, maxcol div 2 - 6)

    put "Instructions"
    locate (4, 1)

    put "Move Happy Ball with the Left and Right arrows"
    put repeat ("%", maxcol)
    var Play2 : int := GUI.CreateButton (maxx div 2 - 20, maxy div 2, 0, "Play",     %Creating a button called play
        game)
    View.Update     %avoiding the flicker

    loop
        exit when GUI.ProcessEvent     %exiting when pressed
    end loop

end instruction

procedure menu      %the menu procedure
    fontID := Font.New ("Ariel:25:bold")        %The font
    Font.Sizes (fontID, height, ascent, descent, internalLeading)       %font size
    Font.Draw ("Happy Ball", 43, 350, fontID, black)
    drawfilloval (round (ballx), round (bally + 130), 10, 10, Colour)     %body
    drawoval (round (ballx), round (bally + 130), 10, 10, face)     %body outline
    drawfilloval (round (ballx) - 3, round (bally + 130) + 2, 1, 1, face)     %left eye
    drawfilloval (round (ballx) + 3, round (bally + 130) + 2, 1, 1, face)     %right eye
    drawfillarc (round (ballx), round (bally + 130) - 2, 2, 4, 180, 360, face)     %smile
    drawfillbox (brickx, bricky, brickx2, bricky2, brick_colour)

    var Instruc : int := GUI.CreateButton (maxx div 2, maxy div 2, 0, "Instructions",     %Creating a button called instructions
        instruction)
    View.Update
    var Play : int := GUI.CreateButton (maxx div 2 - 70, maxy div 2, 0, "Play",     %Creating a button called play
        game)
    View.Update
    loop
        exit when GUI.ProcessEvent     %exiting when pressed
    end loop

end menu

menu




Please specify what version of Turing you are using


-----------------------------------
tjmoore1993
Wed May 13, 2009 5:46 pm

RE:File I/O getting information
-----------------------------------
Looking at your code makes my eyes hurt. I have posted a guide that should fix your problem temporarily.

http://compsci.ca/v3/viewtopic.php?t=20654

-----------------------------------
Dusk Eagle
Wed May 13, 2009 9:45 pm

Re: File I/O getting information
-----------------------------------
Every time you open an existing file to write to it, you must include a mod
open : fileNum, "filename", get, mod

This at least partially explains why you are constantly getting zeros in your file.  I don't have time to help you further but at least this is a start.

-----------------------------------
uknowhoiam
Thu May 14, 2009 5:22 pm

RE:File I/O getting information
-----------------------------------
well the score from the start is set to 0, and when i do 
seek : rec, 0
it only looks at the first line, but if i do
seek: rec, 1
it give an error of eof
i know why that is but i dont know how to solve it
the reason that it gives me the error is because there is nothing on the second line, unless i start the game then there is score on the second line

and when i do mod,rec i get 0 on the first line and another 0 on the second

Can anyone HELP ME!!?!?

-----------------------------------
BigBear
Thu May 14, 2009 5:34 pm

RE:File I/O getting information
-----------------------------------
it is seeking to the third spot in the file 

seek :fn, 0 is the first character 

so 

seek :fn, 2 is the third

-----------------------------------
uknowhoiam
Mon May 18, 2009 7:04 pm

Re: File I/O getting information
-----------------------------------
i still dont know how to fix it

For those whose eyes hurt while looking at my code here is a zip file

-----------------------------------
zero-impact
Mon May 18, 2009 7:08 pm

Re: File I/O getting information
-----------------------------------
This doesn't have anything to do with your problem, but, from a quick glance at your code I can tell that [url=http://compsci.ca/v3/viewtopic.php?t=14333]arrays will make your life quite a bit easier.

-----------------------------------
uknowhoiam
Tue May 19, 2009 5:36 pm

Re: File I/O getting information
-----------------------------------
if i do this
 
 seek : rec, 1
 get : rec, best
 locate (3, maxcol - 11)
 put "Best: ", best


then the score is save on the third line of the text file, i just want it to be saved on the first line, but if i do
 
 seek : rec, 0
 get : rec, best
 locate (3, maxcol - 11)
 put "Best: ", best

the score is save on the second line
[/code]
