Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Loading a File in one program created by another program.
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
poww10s




PostPosted: Sun Mar 23, 2014 2:29 pm   Post subject: Loading a File in one program created by another program.

What is it you are trying to achieve?
Loading a File into a program that I created with another program.


What is the problem you are having?
I'm not sure how to make sure it locates certain parts and read them.


Describe what you have tried to solve this problem
using for loops, and also the basic File I/O tutorials. not to sure how to do it really.


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
(Those tutorial's are coming in handy for learning how file i/o works.

Turing:


procedure LoadFile                           % Start of LoadFile
    loop                                     % Infinite Loop.
        put "What is your Filename?"             % Asks the End-User what their name is.
        get FileName                         % Gets FileName instead of Name to save memory.
        Extension := ".lvl"                   % This variable has been defined.
        FileDir := ".\\Level Editor\\Levels\\" % This variable has been defined.
        FileName += Extension                % "FileName += Extension" Puts FileName and Extension together as 1 word.
        FileDir += FileName                  % "FileDir += FileName" Puts directory before FileName.
        if File.Exists (FileDir) then        % Checks if file exists.
            open : stream, FileDir, get      %
            loop                             % Infinite Loop.
                exit when eof (stream)       % Exits loop when end-of-file.
                get : stream, limit
                for i : 1 .. upper (platform, 1)
                    get : stream, platform (i, 1) % Sets the variable platform.
                    get : stream, platform (i, 2) % Sets the variable platform.
                    get : stream, platform (i, 3) % Sets the variable platform.
                    get : stream, platform (i, 4) % Sets the variable platform.
                end for
            end loop                         % End Loop.
            close : stream                   % When finished saving it closes file. (Required for a stable application)
            exit                             % Exits loop if load was successful.
        else                                 % If error then it will run;
            put "The file does not exist."   % Bullet-Proofing.
            delay (600)                      % Warns End-User of their error.
        end if                               % Ends the IF-Statement.
    end loop                                 % End Loop.
end LoadFile



Please specify what version of Turing you are using
4.1

If anyone wants me to elaborate more, I can.
Sponsor
Sponsor
Sponsor
sponsor
Insectoid




PostPosted: Sun Mar 23, 2014 2:54 pm   Post subject: RE:Loading a File in one program created by another program.

If you wrote the program the created the file, then you should know exactly how the file is formatted. In this case, assuming the file is not corrupt and that the program reading it reads things in the correct order, it should never fail. You don't ever need to locate anything. Just read it all in the order of the file. If it's difficult to do that with your format, then design a better format.

For a platformer, the format can be really easy. The first part of the file should say "I am a map file for this game" in a way your program will understand. That way, if the user supplies a random file, the program won't crash. Then the start coordinates for the character, the goal, and platforms in whatever order makes sense to you. To read the file, all you've got to do is verify that it is an actual map file, get the character's coordinates, the goal's coordinates, and then the list of platforms/objects/whatever. Of course, this simplifies it a little, but it's really no different than reading input files for DWITE or other online programming contests.
poww10s




PostPosted: Sun Mar 23, 2014 2:59 pm   Post subject: RE:Loading a File in one program created by another program.

ah, ok. I've got my data set like this:
code:

[Box1]
x
y
x2
y2
[Box2]
x
y
x2
y2
etc

Is what I am doing good enough for this?
Insectoid




PostPosted: Sun Mar 23, 2014 3:16 pm   Post subject: RE:Loading a File in one program created by another program.

You tell me. Is it good enough to contain all the information you need? Honestly, I don't understand what your problem is.
poww10s




PostPosted: Sun Mar 23, 2014 3:28 pm   Post subject: RE:Loading a File in one program created by another program.

What I want is for it to read the numbers and store them as the 4 variables in the array of the array "platform".

I've changed it so when it reads, it seeks the second line and gets that, but all it ever says is.
"Invalid Integer Input."

Also, when it asks me for the file name, none of the put text shows up until it gets it, and only if it can read the file.
poww10s




PostPosted: Sun Mar 23, 2014 3:36 pm   Post subject: RE:Loading a File in one program created by another program.

Oh, and because they are stored as text, they are strings not integers.

Is there a way to make it read them as integers?
Dreadnought




PostPosted: Sun Mar 23, 2014 3:40 pm   Post subject: Re: Loading a File in one program created by another program.

poww10s wrote:

Is there a way to make it read them as integers?


strintok and strint is what you are looking for.
poww10s




PostPosted: Sun Mar 23, 2014 3:44 pm   Post subject: RE:Loading a File in one program created by another program.

so the only way is to convert them after you get them?

Also, how to I use seek?
how to I tell it filePosition and seek filePosition.
Sponsor
Sponsor
Sponsor
sponsor
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 8 Posts ]
Jump to:   


Style:  
Search: