Page 1 of 1

Reading and checking

Posted: Wed Apr 22, 2009 3:22 am
by izidor
I am working on a game in witch you must create account (with name and password)
Name is saved in n001.dat, password is saved in p001.dat.
and this is my problem: I want to make my program read n001.dat and p001.dat, and is the name and password that you wrote same as n001.dat and p001.dat

Code: Select all

input "-", startplay$
if startplay$ = "start game" then
input "Name: ",name$
input "Password: ",pass$
open "n001.dat" for output as #1
print #1, name$
close #1
open "p001.dat" for output as #1
print #1, pass$
close #1

end if

if startplay$ = "play game" then
input "Name: ",playname$
end if
if playname$ = name$ then
input "Password: ", playpass$
end if
if playpass$ = pass$ then
end if

Posted: Wed Apr 22, 2009 7:31 am
by Mentat
Hrm. Were you looking for this? I think you needed to load the Name$ and pass$ from the file.

Code: Select all

input "-", startplay$
if startplay$ = "start game" then
     input "Name: ",name$
     input "Password: ",pass$
     open "n001.dat" for output as #1
     print #1, name$
     close #1
     open "p001.dat" for output as #1
     print #1, pass$
     close #1
end if

if startplay$ = "play game" then
     input "Name: ",playname$
' Removed "end if"

     'Reading password and name from file
     open "p001.dat" for input as #1
     input #1, pass$
     close #1
     open "n001.dat" for input as #1
     input #1, name$
     close #1
     
     if playname$ = name$ then
          input "Password: ", playpass$
     end if
     if playpass$ = pass$ then
          'Something goes here
     end if

'Put New end if here
end if 
Sorry if there are any code errors above. I have no way of checking if it works.

Posted: Wed Apr 22, 2009 1:22 pm
by izidor
thx for reply but it says "C++ compilation failed"
but thx anyway

Posted: Wed Apr 22, 2009 1:24 pm
by burger2227
Why not just have a user enter an alias and search a file for that name?

If the name is found, the file also holds their password. Just verify it next.

If the name is not found, then ask for a password. Then start the game.

1) Who is gonna want to type "Start game" to play?
2) All you need is to APPEND a file if necesssary so that you can have more than one player's data. OUTPUT erases a file!

To verify that a data file exists just open for APPEND at the start of the program. This will make sure it exists.

Code: Select all

OPEN "Mydata.dat" FOR APPEND AS #1  'creates file if not found
     IF LOF(1) THEN exists = 1    'checks for data in file
CLOSE #1
INPUT "Enter your user name: ", name$
IF exists THEN 
   OPEN "Mydata.dat" FOR INPUT AS #1 'look for the name in file
   DO WHILE NOT EOF(1)
       INPUT #1, user$, pass$
       IF name$ = user$ THEN found = 1: EXIT DO
   LOOP
   CLOSE #1
END IF
IF found THEN 
    password$ = pass$
    INPUT "Enter your password: ", pw$
    IF pw$ = password$ THEN GOSUB Startgame ELSE SYSTEM
ELSE: INPUT "Enter a new password: ", passw$
    OPEN "Mydata.dat" FOR APPEND as # 1
      WRITE #1, name$, passw$
    CLOSE #1
    GOSUB Startgame
END IF
 
Ted

Posted: Wed Apr 22, 2009 1:35 pm
by Mentat
izidor wrote:thx for reply but it says "C++ compilation failed"
but thx anyway
What software are you using for running your code? C++ is a whole different language.

Posted: Wed Apr 22, 2009 1:42 pm
by izidor
@Mentant
There wasnt problem in your code, it was in my

@burger2227
Sorry but Mentant's code is better to me because its more simple :)

@Mentant

I'm using QB64, yeah its strange to me too but i think it compiles bas file to exe with some c++ app or something else

Posted: Wed Apr 22, 2009 3:21 pm
by burger2227
Programs are not made to be EASY for the programmer! They should be easy for the USER.

Using OPEN FOR OUTPUT allows only ONE data entry. That is not only simple, but stupid!

That makes any user overwrite another's data! So why even use a file?

Just make them use some hidden password you want LOL.......That is a game all by itself!

Posted: Wed Apr 22, 2009 7:24 pm
by MystikShadows
burger2227 wrote:Programs are not made to be EASY for the programmer! They should be easy for the USER.
Words of wisdom right there. :)