
-----------------------------------
Sauvus
Wed May 09, 2012 4:10 pm

I/O Problems
-----------------------------------
What is it you are trying to achieve?
A relevant answer to the problem of Loading up I/O's.


What is the problem you are having?
The I/O saves, but i have no idea how to load


Describe what you have tried to solve this problem
I tried using get, but for some reason every time i tried to put it in the right position, it failed.




% Dark Lance
var stream : int
open : stream, "config/player1location.txt", put, seek, get
var window : int := Window.Open ("graphics:597;637, offscreenonly")
var PLAYER1 : int := Pic.FileNew ("Sprites/Player1.bmp")
var GUI : int := Pic.FileNew ("pictures/shitgui.bmp")
var player1sprite : int
var x, y, button : int
var coordx, coordy : int := 64
var filePos : int
var player1x2 : int := 26
var player1y2 : int := 51
player1sprite := Sprite.New (PLAYER1)
var chars : array char of boolean
%I/O's%
put : stream, "Player1location"
tell : stream, filePos
put : stream, player1x2
put : stream, player1y2
seek : stream, filePos

var player1x : int := player1x2
var player1y : int := player1y2
%tell : stream, filePos2
%seek : stream, filePos2

procedure grid
    for gridcount : 1 .. 9
        drawline ((gridcount * 64) + 11, 51, (gridcount * 64) + 11, 627, black)
        drawline (12, (gridcount * 64) + 51, 586, (gridcount * 64) + 51, black)
    end for
end grid

procedure draw
    Sprite.SetPosition (player1sprite, player1x, player1y, false)
    Sprite.Show (player1sprite)
    grid
    Pic.Draw (GUI, 1, 1, picMerge)
    View.Update
end draw


draw

loop
    loop
        Input.KeyDown (chars)

        if chars (KEY_UP_ARROW) and player1y < 500 then
            player1y += coordy
            player1y2 := player1y + coordy
            seek : stream, filePos
            put : stream, player1x2
            put : stream, player1y2
            exit
        end if

        if chars (KEY_RIGHT_ARROW) and player1x < 510 then
            player1x += coordx
            exit
        end if

        if chars (KEY_LEFT_ARROW) and player1x > 75 then
            player1x -= coordx
            exit
        end if

        if chars (KEY_DOWN_ARROW) and player1y > 51 then
            player1y -= coordy
            exit
        end if
    end loop
    draw
    delay (250)
end loop





Please specify what version of Turing you are using
The Latest

-----------------------------------
Tony
Wed May 09, 2012 4:18 pm

RE:I/O Problems
-----------------------------------
- in what way does it fail?
- you're not actually using "get" in your provided code.

-----------------------------------
Sauvus
Wed May 09, 2012 4:21 pm

RE:I/O Problems
-----------------------------------
Okay, sorry. I should've explained more efficiently.
1. It overwrites due to 
var player1x2 : int := 26 
var player1y2 : int := 51 
But, if these dont have values, the code doesn't work.
I've erased get because of the fact that it wasn't probably placed correctly, and i've tried to use it.

-----------------------------------
Sauvus
Wed May 09, 2012 9:47 pm

RE:I/O Problems
-----------------------------------
I feel as though my question is valid, so if anyone could help please leave a reply.

-----------------------------------
Tony
Wed May 09, 2012 10:58 pm

RE:I/O Problems
-----------------------------------
I have trouble figuring out what your question is, and you are not using a question mark to help me guess at what you are asking.

-----------------------------------
Sauvus
Wed May 09, 2012 11:13 pm

RE:I/O Problems
-----------------------------------
Okay, when player1 moves up his y location is saved in a .txt file, but every time the program is rebooted, it is written over with the variable player1y2. The problem is that when these lines are called 
put : stream, player1x2 
put : stream, player1y2 
they require a value. 

I want it to read player1x2 and player1y2 from the text file and use it when it runs, but i'm not sure how i would use get in it.
I've tried to properly put in a get function somewhere but it just doesn't help.

-----------------------------------
Tony
Thu May 10, 2012 2:07 am

RE:I/O Problems
-----------------------------------
What would you expect to write to file if player1y could have no value? The "problem" is that files are openned at the beginning, so you overwrite content. See docs for [tdoc]get[/tdoc] on reading from file first.

-----------------------------------
evildaddy911
Thu May 10, 2012 3:47 pm

Re: I/O Problems
-----------------------------------
open : stream, "config/player1location.txt", put, seek, get
*
*
*
*
tell : stream, filePos 

do you see a problem with that?
i do

-----------------------------------
Sauvus
Thu May 10, 2012 5:35 pm

RE:I/O Problems
-----------------------------------
I fixed it! Thanks for the help Tony.
