using files as rooms

This is a discussion on using files as rooms within the C++ Programming forums, part of the General Programming Boards category; i want my prog to open a file read the contense and use the information in that file to output ...

  1. #1
    Registered User Ajsan's Avatar
    Join Date
    Dec 2003
    Posts
    55

    using files as rooms

    i want my prog to open a file read the contense and use the information in that file to output the description of what the character would see and create valid exits to other rooms that are also files to be opened. what is the best way to do this. the only reason that i want the rooms to be opened through files is that i want the game to be upgradeble through a txt file or something like that, that would include quests and items and such.

    the help is appreciated.
    Style is overrated.

    - 冷たい火 -

  2. #2
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,161
    There is no 'best' way. There are only ways. And here's one:

    File: kitchen.txt
    Code:
    This is the kitchen.  You may......
    ----
    east livingroom.txt
    down basement.txt
    north garden.txt
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

  3. #3
    Registered User Ajsan's Avatar
    Join Date
    Dec 2003
    Posts
    55
    is there a way that you can have the user input the address of a folder and have the prog copy those files in the folder and replace/ create them in another folder.

    along those lines is it possible to have the program in onefolder and the files that you want in another folder inside of the folder that the progs in and have the prog know to open that folder then grab the files from there?
    Style is overrated.

    - 冷たい火 -

  4. #4
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,161
    Of course. It just requires the manipulation of a path & filename string, and use of various file commands that can open, rename, and delete files.
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

  5. #5
    Registered User Ajsan's Avatar
    Join Date
    Dec 2003
    Posts
    55

    do you know the codes

    what is the code to open a file thats in a different folder or sub folder from where the prog is???

    i figured that there was a way i just wanted to know the code for it.
    Style is overrated.

    - 冷たい火 -

  6. #6
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    The answer is probably os dependant, but if you know the full path then just put that in where you normally put the file name (ie "c:\\program files\\myfile.txt" )
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  7. #7
    Registered User Ajsan's Avatar
    Join Date
    Dec 2003
    Posts
    55

    okay

    so do i include that inn the

    fin.open("c:\Program Files\myFile.txt");

    would that work or do i have the wrong idea al together
    Style is overrated.

    - 冷たい火 -

  8. #8
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    That should work, but you need to use two backslashes (\\).

    Otherwise what happens if you accidentally have an escape sequence like "c:\program files\thisisatest.txt" <--\t is for tab
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  9. #9
    Registered User Ajsan's Avatar
    Join Date
    Dec 2003
    Posts
    55

    thx

    thx so very much
    Style is overrated.

    - 冷たい火 -

  10. #10
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    Originally posted by JaWiB
    Otherwise what happens if you accidentally have an escape sequence like "c:\program files\thisisatest.txt" <--\t is for tab
    wouldn't the compiler complain about \p first and not even finish compilation?
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  11. #11
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    Yeah, you would get unknown escape sequence errors
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  12. #12
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Originally posted by major_small
    wouldn't the compiler complain about \p first and not even finish compilation?
    It's undefined.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  13. #13
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    I know it's undefined... or the compiler wouldn't complain...
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  14. #14
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,161
    Originally posted by major_small
    wouldn't the compiler complain about \p first and not even finish compilation?
    No, the compiler will happily compile it. Since \p is not a valid escape character, the \ is simply removed and the 'p' is left. As least that's how my compiler does it. I'm not sure if this is standard or not, but I've never had a compiler error on an undefined escape.
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

  15. #15
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>I'm not sure if this is standard or not
    It's undefined (repeating myself here )

    This means the compiler is free to do whatever it likes, you cannot guarantee an error or not.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. *.cpp and *.h files understanding
    By ElastoManiac in forum C++ Programming
    Replies: 4
    Last Post: 06-11-2006, 04:45 AM
  2. Linking header files, Source files and main program(Accel. C++)
    By Daniel Primed in forum C++ Programming
    Replies: 3
    Last Post: 01-17-2006, 10:46 AM
  3. Multiple Cpp Files
    By w4ck0z in forum C++ Programming
    Replies: 5
    Last Post: 11-14-2005, 01:41 PM
  4. Folding@Home Cboard team?
    By jverkoey in forum A Brief History of Cprogramming.com
    Replies: 398
    Last Post: 10-11-2005, 08:44 AM
  5. header and source files
    By gtriarhos in forum C Programming
    Replies: 3
    Last Post: 10-02-2005, 03:16 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21