File I/O getting information
Author |
Message |
uknowhoiam
|
Posted: Wed May 13, 2009 4:58 pm Post subject: 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)
Turing: |
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 <= bricky2 + 10 and bally >= bricky + 10 and ballx <= brickx2 and ballx + 10 >= brickx then %%i assume 10 is the size of the ball?
ypos := 10 - gravity
elsif bally <= bricky4 + 10 and bally >= bricky3 + 10 and ballx <= brickx4 and ballx + 10 >= brickx3 then
ypos := 10 - gravity
elsif bally <= bricky6 + 10 and bally >= bricky5 + 10 and ballx <= brickx6 and ballx + 10 >= brickx5 then
ypos := 10 - gravity
elsif bally <= bricky8 + 10 and bally >= bricky7 + 10 and ballx <= brickx8 and ballx + 10 >= 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 <= 0 then
doty := maxy
doty2 := doty + 15
end if
if doty4 <= 0 then
doty3 := maxy
doty4 := doty3 + 15
end if
if doty6 <= 0 then
doty5 := maxy
doty6 := doty5 + 15
end if
if doty8 <= 0 then
doty7 := maxy
doty8 := doty7 + 15
end if
if bricky2 <= 0 then
brickx := Rand.Int (0, 250 - 40)
bricky := Rand.Int (maxy, maxy + 10)
brickx2 := brickx + 40
bricky2 := bricky + 15
Score := true
end if
if bricky4 <= 0 then
brickx3 := Rand.Int (0, 250 - 40)
bricky3 := Rand.Int (maxy, maxy + 10)
brickx4 := brickx3 + 40
bricky4 := bricky3 + 15
Score := true
end if
if bricky6 <= 0 then
brickx5 := Rand.Int (0, 250 - 40)
bricky5 := Rand.Int (maxy, maxy + 10)
brickx6 := brickx5 + 40
bricky6 := bricky5 + 15
Score := true
end if
if bricky8 <= 0 then
brickx7 := Rand.Int (0, 250 - 40)
bricky7 := Rand.Int (maxy, maxy + 10)
brickx8 := brickx7 + 40
bricky8 := bricky7 + 15
Score := true
end if
if bally <= 15 and fail = true then
die := true
doty + = 4
doty2 + = 4
doty3 + = 4
doty4 + = 4
doty5 + = 4
doty6 + = 4
doty7 + = 4
doty8 + = 4
bricky + = 4
bricky2 + = 4
bricky3 + = 4
bricky4 + = 4
bricky5 + = 4
bricky6 + = 4
bricky7 + = 4
bricky8 + = 4
end if
if doty2 >= maxy and die = true then
doty := 0
doty2 := doty + 15
end if
if doty4 >= maxy and die = true then
doty3 := 0
doty4 := doty3 + 15
end if
if doty6 >= maxy and die = true then
doty5 := 0
doty6 := doty5 + 15
end if
if doty8 >= maxy and die = true then
doty7 := 0
doty8 := doty7 + 15
end if
if bricky2 >= maxy and die = true then
brickx := Rand.Int (0, 250 - 40)
bricky := 0
brickx2 := brickx + 40
bricky2 := bricky + 15
end if
if bricky4 >= maxy and die = true then
brickx3 := Rand.Int (0, 250 - 40)
bricky3 := 0
brickx4 := brickx3 + 40
bricky4 := bricky3 + 15
end if
if bricky6 >= maxy and die = true then
brickx6 := Rand.Int (0, 250 - 40)
bricky5 := 0
brickx6 := brickx5 + 40
bricky6 := bricky5 + 15
end if
if bricky8 >= maxy and die = true then
brickx7 := Rand.Int (0, 250 - 40)
bricky7 := 0
brickx8 := brickx7 + 40
bricky8 := bricky7 + 15
end if
if bally <= 15 and die = false then
ypos := 10 - gravity
end if
if ballx > maxx + 10 then
ballx := - 10
end if
if ballx < - 10 then
ballx := maxx + 10
end if
if xpos >= 3 then
xpos := 2
end if
if xpos <= - 3 then
xpos := - 2
end if
if score >= 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
<Answer Here>
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
tjmoore1993
|
Posted: Wed May 13, 2009 5:46 pm Post subject: 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
|
Posted: Wed May 13, 2009 9:45 pm Post subject: Re: File I/O getting information |
|
|
Dusk Eagle @ Tue May 12, 2009 11:40 pm wrote: Every time you open an existing file to write to it, you must include a mod[ify] statement to tell the computer to modify the file, and not to overwrite it. Like this:
Turing: |
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
|
Posted: Thu May 14, 2009 5:22 pm Post subject: 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
|
Posted: Thu May 14, 2009 5:34 pm Post subject: 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
|
Posted: Mon May 18, 2009 7:04 pm Post subject: 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
Description: |
|
Download |
Filename: |
HappyBall.zip |
Filesize: |
2.54 KB |
Downloaded: |
53 Time(s) |
|
|
|
|
|
|
zero-impact
|
Posted: Mon May 18, 2009 7:08 pm Post subject: 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 arrays will make your life quite a bit easier.
|
|
|
|
|
|
uknowhoiam
|
Posted: Tue May 19, 2009 5:36 pm Post subject: Re: File I/O getting information |
|
|
if i do this
Turing: |
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
Turing: |
seek : rec, 0
get : rec, best
locate (3, maxcol - 11)
put "Best: ", best
|
the score is save on the second line
[/code]
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
|
|