Creating a game...help - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Creating a game...help

Hey I need to create a game.. Im creating a code cracking game using delphi.

Anyway, I'm already stuck at the Username :P

{click on button}
Welcome.Hide;
Game.Show;
username:=Inputbox('Insert your username!', '' ,'');
//

How do I save the username using a file or record :D

Comments

  • zibadianzibadian Posts: 6,349Member
    : Hey I need to create a game.. Im creating a code cracking game using delphi.
    :
    : Anyway, I'm already stuck at the Username :P
    :
    : {click on button}
    : Welcome.Hide;
    : Game.Show;
    : username:=Inputbox('Insert your username!', '' ,'');
    : //
    :
    : How do I save the username using a file or record :D
    :
    Saving the username in a file:
    [code]
    var
    f: text;
    begin
    AssignFile(f, 'username.save');
    Rewrite(f);
    writeln(f, UserName);
    CloseFile(f);
    end;
    [/code]
    Saving the username in a record:
    [code]
    type
    TUser = record
    Name: string;
    end;

    var
    User: TUser;
    begin
    User.Name := Inputbox('Insert your username!', '' ,'');
    end;
    [/code]
    Help = (Throwable.getStackTrace() == null || SourceCode == null) ? null : getHelp(e, SourceCode);

  • swifty23swifty23 Posts: 2Member
    Ah okay thanks.

    How do I save the username into a text file using FILE. Like Im using a form not console app...
  • zibadianzibadian Posts: 6,349Member
    : Ah okay thanks.
    :
    : How do I save the username into a text file using FILE. Like Im using a form not console app...
    :
    The textfile can also be used in a GUI application. If you still want to use a file variable then you need to code it like this:
    [code]
    var
    f: file;
    i: integer;
    begin
    AssignFile(f, filename);
    Rewrite(f, 1);
    i := Length(UserName);
    BlockWrite(f, i, SizeOf(i)); // Write the length of the string
    BlockWrite(f, UserName[1], i); // Write the string itself
    CloseFile(f);
    end;
    [/code]
    Reading it is also more involved that using a textfile:
    [code]
    var
    f: file;
    i: integer;
    begin
    AssignFile(f, filename);
    Reset(f, 1);
    BlockRead(f, i, SizeOf(i)); // Read the length of the string
    SetLength(UserName, i);
    BlockRead(f, UserName[1], i); // Read the string itself
    CloseFile(f);
    end;
    [/code]



    Help = (Throwable.getStackTrace() == null || SourceCode == null) ? null : getHelp(e, SourceCode);

Sign In or Register to comment.