Results 1 to 8 of 8

Thread: Forms - Export/Import users

  1. #1
    Join Date
    Jun 2007
    Location
    Wednesday
    Posts
    2,446
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default Forms - Export/Import users

    After starting my script a while back, I dived into the uses of creating INI files to store data, thus the ExportUsers and ImportUsers was forged. It's very simple and should be easy to see how it works. You may need to tweak a couple of things depending on how your form works, but otherwise it *should* work straight oput the box. Also, you can change the filename it saves it as (I would recommend making it a const, but I just had it in like this because I was too lazy to scroll up when scripting it). To use it, just plop it in then make an export and import button, then direct them to the appropriate procedure.

    SCAR Code:
    Procedure ExportUsers(Sender: TObject);
    Var
      i: Integer;
     
    Begin
      For i:= 0 To GetArrayLength(Players) - 1 Do
      Begin
        WriteINI('Player' + IntToStr(i), 'Username', Players[i].Name, ScriptPath + 'sUsers.ini');
        WriteINI('Player' + IntToStr(i), 'Password', Players[i].Pass, ScriptPath + 'sUsers.ini');
        WriteINI('Player' + IntToStr(i), 'Nickname', Players[i].Nick, ScriptPath + 'sUsers.ini');
        WriteINI('Player' + IntToStr(i), 'Active', BoolToStr(Players[i].Active), ScriptPath + 'sUsers.ini');
      End;
    End;

    Procedure ImportUsers(Sender: TObject);
    Var
      i,ii: Integer;
     
    Begin
      While(Not(ReadINI('Player' + IntToStr(i), 'Username', ScriptPath + 'sUsers.ini') = '') and (i < 50)) Do
        Inc(i);
      Dec(i);
      SetArrayLength(Players,i+1);
      For ii:= 0 to i do
      Begin
        Players[ii].Name:= ReadINI('Player' + IntToStr(ii), 'Username', ScriptPath + 'sUsers.ini');
        Players[ii].Pass:= ReadINI('Player' + IntToStr(ii), 'Password', ScriptPath + 'sUsers.ini');
        Players[ii].Nick:= ReadINI('Player' + IntToStr(ii), 'Nickname' ,ScriptPath + 'sUsers.ini');
        Players[ii].Active:= StrToBool(ReadINI('Player' + IntToStr(ii), 'Active', ScriptPath + 'sUsers.ini'));
      End;
      FCurPla:= 0;
      edName.Text:= Players[FCurPla].Name;
      edPass.Text:= Players[FCurPla].Pass;
      edNick.Text:= Players[FCurPla].Nick;
      cbActive.Text:= BoolToStr(Players[FCurPla].Active);
    End;

    Note: This was before the end of my over-capitalizing phase, so lots of capitals, yay!
    By reading this signature you agree that mixster is superior to you in each and every way except the bad ways but including the really bad ways.

  2. #2
    Join Date
    Apr 2007
    Posts
    3,152
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    does that mean that you're going to have 4 .ini files per player? thats kinda...ehh. You could use something else...like make it write it all in one ini then write like
    Password:'blaj';
    and use the between function and do like Password' and ';
    SCAR Tutorials: The Form Tutorial | Types, Arrays, and Classes
    Programming Projects: NotePad | Tetris | Chess


  3. #3
    Join Date
    Jul 2007
    Posts
    1,431
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Oh, smart, simple and effective

    @Dan, there is no point is using between in reading ini's? You can read specific line with 1 command...don't remember exactly. I think im right.
    [CENTER][SIZE="4"]Inactive[/SIZE]I forgot my password[/CENTER]

  4. #4
    Join Date
    Jun 2007
    Location
    Wednesday
    Posts
    2,446
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    @Dan Cardin - It sets up 1 file for all the players (the end string in readINI and WriteINI). Player0, Player1 etc. are all sections, that then have Username, Password, Nickname and Active as sections in each player section, which are then assigned the players details.

    @Negaal - Thanks, I used them after getting pissed off at my StrToArray function when I kept assigning things to the wrong array (ended up having all the usernames for the 1st person, all the password for the 2nd etc.) so I checked out INI's after seeing them in the Scar manual when seeing other things. I played with them for a bit and got the general hang of it and added it to my form template (it's got infinite players and everything!).

    Also, as a note, it can't take more than 50 players atm as I doubted anyone would have more than that, but that just stops it reading an infinitely long file if the file gets messed up somehow. If you need more than 50, you just change the number in the repeat loop (for the file reading).
    By reading this signature you agree that mixster is superior to you in each and every way except the bad ways but including the really bad ways.

  5. #5
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    2,984
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    There is something very similar to this in the SRLPlayerForm you know .

    It exports your players info into a DeclarePlayers; procedure and saves this as a scar file in your desired location. Check it out, it's pretty neat.
    Administrator's Warning:


  6. #6
    Join Date
    Apr 2007
    Posts
    3,152
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    oops i didnt see the commas and thought that the whole thing was the name of the file
    SCAR Tutorials: The Form Tutorial | Types, Arrays, and Classes
    Programming Projects: NotePad | Tetris | Chess


  7. #7
    Join Date
    Jun 2007
    Location
    Wednesday
    Posts
    2,446
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    I knew I could never make anything original. Ahwell, atleast I made it much simpler and it saves it to a place you can change easily Took me a while to find SRLPlayerForm though, I looked for the filename most matching play in the misc section and I checked atleast 5 others before finding users.scar >< I'm just glad I finally found the form though, it looks kickass and it will only be a matter of time until I steal, err I mean, make something similar for my default script file
    By reading this signature you agree that mixster is superior to you in each and every way except the bad ways but including the really bad ways.

  8. #8
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    2,984
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    Quote Originally Posted by mixster05 View Post
    I knew I could never make anything original. Ahwell, atleast I made it much simpler and it saves it to a place you can change easily Took me a while to find SRLPlayerForm though, I looked for the filename most matching play in the misc section and I checked atleast 5 others before finding users.scar >< I'm just glad I finally found the form though, it looks kickass and it will only be a matter of time until I steal, err I mean, make something similar for my default script file
    Haha go ahead It is for use and learning purposes only I suppose
    Administrator's Warning:


Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 0
    Last Post: 02-16-2009, 10:12 AM
  2. LoginForm / Progress Bar / Export to .exe
    By Laur€ns in forum C#/Visual Basic Help and Tutorials
    Replies: 8
    Last Post: 11-12-2008, 10:37 AM
  3. Mac Users
    By elfenlyte in forum News and General
    Replies: 6
    Last Post: 01-07-2008, 09:54 PM
  4. Hello fellow SRL users!
    By cop212 in forum Who Are You ? Who ? Who ?
    Replies: 0
    Last Post: 09-30-2006, 04:42 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •