Results 1 to 11 of 11

Thread: Creating and using ini files

  1. #1
    Join Date
    Dec 2009
    Location
    Newcastle, Australia
    Posts
    888
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default Creating and using ini files

    I want to use ini files to save player data, however I can't find a decent tutorial on the subject.

    if I wanted to save multiple characters with 4 data types (Name, Pass, Nick, Pin), how would I do it...

    Current Script Project
    Pot of flour gatherer - 95% done

    Can't get Simba to work? Click here for a tutorial

  2. #2
    Join Date
    Oct 2009
    Location
    Stockton, CA
    Posts
    2,040
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    Code:
     WriteINI
    
     procedure WriteINI(const Section, KeyName, NewString, FileName: string);
    
     
     
      ReadINI
    
     function ReadINI(const Section, KeyName, FileName: string): string;
    
     
     
      DeleteINI
    
     procedure DeleteINI(const Section, KeyName, FileName: string);
    Here is an example ini:
    Quote Originally Posted by filename.ini
    [section]
    keyname=kyle
    To read the key you would do ReadKey := ReadINI('section', 'keyname', AppPath + Filename);
    That would return 'kyle'.
    Write and read should be self explanatory I hope.
    Join the IRC! irc.rizon.net:6667/srl | SQLite (0.99rc3+) | SRL Doc | Simba Doc | Extra Simba Libraries (openSSL & sqlite3)
    Quote Originally Posted by #srl
    10:45 < Toter> daphil when can get sex anyday I want
    10:45 < Toter> he is always on #SRL
    "A programmer is just a tool which converts caffeine into code"

  3. #3
    Join Date
    Oct 2006
    Posts
    1,190
    Mentioned
    0 Post(s)
    Quoted
    2 Post(s)

    Default

    here is how i increased my stats
    Simba Code:
    Inc(Script_Total[TOTAL_HIGH_ALCHES]);
      WriteINI('Script_Total', '1', IntToStr(Script_Total[TOTAL_HIGH_ALCHES]), ScriptPath + 'ScriptStats.INI');
      IncEx(Script_Total[TOTAL_XP_GAINED], 65);
      WriteINI('Script_Total', '3', IntToStr(Script_Total[TOTAL_XP_GAINED]), ScriptPath + 'ScriptStats.INI');

    i read them like this

    SCAR Code:
    procedure Script_Totals;
    var
      i : Integer;
    begin
      for i := 0 to 4 do
        Script_Total[i] := StrToIntDef(ReadINI('Script_Total', IntToStr(i), ScriptPath + 'ScriptStats.INI'), 0);

        Writeln(' Total Time Ran      : ' + MsToTime(Script_Total[TOTAL_TIME_RAN], Time_Formal));
        Writeln(' Total High Alches   : ' + IntToStr(Script_Total[TOTAL_HIGH_ALCHES]));
        Writeln(' Total Curses        : ' + IntToStr(Script_Total[TOTAL_CURSES]));
        Writeln(' Total XP Gained     : ' + IntToStr(Script_Total[TOTAL_XP_GAINED]));
        Writeln(' Script Runs         : ' + IntToStr(Script_Total[TOTAL_STARTS]));
    end;

    for each player just do a for to do loop and write each players name, pin, etc

    i didnt really explain it to well but i hope you get the idea



  4. #4
    Join Date
    Dec 2009
    Location
    Newcastle, Australia
    Posts
    888
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    OK thanks guys, just a quick question on forms, can I open a second form (ie like load players form) and if you can, how, because CreateForm doesn't seem to be working...
    Last edited by Bad Boy JH; 03-06-2011 at 06:40 AM.

    Current Script Project
    Pot of flour gatherer - 95% done

    Can't get Simba to work? Click here for a tutorial

  5. #5
    Join Date
    Oct 2009
    Location
    Stockton, CA
    Posts
    2,040
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    You can but iirc it can't be modal?

    Edit: Idk what I'm talking about ? I done it before lon ago, search the forum .
    Last edited by Sex; 03-06-2011 at 06:46 AM.
    Join the IRC! irc.rizon.net:6667/srl | SQLite (0.99rc3+) | SRL Doc | Simba Doc | Extra Simba Libraries (openSSL & sqlite3)
    Quote Originally Posted by #srl
    10:45 < Toter> daphil when can get sex anyday I want
    10:45 < Toter> he is always on #SRL
    "A programmer is just a tool which converts caffeine into code"

  6. #6
    Join Date
    Dec 2009
    Location
    Newcastle, Australia
    Posts
    888
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    I forgot to call ShowModal, but that freezed everything
    so I just called Show, but that stuffed it up, because the function that loaded it kept working. Which means I can't load the player, any ideas?

    In the mean time i may look into some other scripts with a form and load player.

    Current Script Project
    Pot of flour gatherer - 95% done

    Can't get Simba to work? Click here for a tutorial

  7. #7
    Join Date
    Oct 2009
    Location
    Stockton, CA
    Posts
    2,040
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    Show me what you put I'll do it.
    Join the IRC! irc.rizon.net:6667/srl | SQLite (0.99rc3+) | SRL Doc | Simba Doc | Extra Simba Libraries (openSSL & sqlite3)
    Quote Originally Posted by #srl
    10:45 < Toter> daphil when can get sex anyday I want
    10:45 < Toter> he is always on #SRL
    "A programmer is just a tool which converts caffeine into code"

  8. #8
    Join Date
    Dec 2009
    Location
    Newcastle, Australia
    Posts
    888
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Got a method that makes it work, but when i free the sub-form it causes the error message "access violation"

    Current Script Project
    Pot of flour gatherer - 95% done

    Can't get Simba to work? Click here for a tutorial

  9. #9
    Join Date
    Aug 2007
    Location
    Colorado
    Posts
    7,421
    Mentioned
    268 Post(s)
    Quoted
    1442 Post(s)

    Default

    It's like your own personal SRL stats. How original and nice idea!

  10. #10
    Join Date
    Oct 2006
    Posts
    1,190
    Mentioned
    0 Post(s)
    Quoted
    2 Post(s)

    Default

    I think he just wants to save/load player details to an ini I'm guessing so a form will load all the info, or load players that way save re-writing declareplayers each time

    The example i posted kept track of players stats in a script I made



  11. #11
    Join Date
    Oct 2009
    Location
    Stockton, CA
    Posts
    2,040
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    Simba Code:
    Program FormTest;

    var
      frmDesign : TForm;
      frmDesign2 : TForm;
      OpenNewForm : TButton;
      Label1 : TLabel;

    Procedure ButtonClick(Sender: TObject); Forward;

    Procedure InitForm;
    Begin
    frmDesign := TForm.Create(nil);
    frmDesign.Left := 250;
    frmDesign.Top := 114;
    frmDesign.Width := 258;
    frmDesign.Height := 118;
    frmDesign.Caption := 'frmDesign';
    frmDesign.Color := clBtnFace;
    frmDesign.Font.Color := clWindowText;
    frmDesign.Font.Height := -11;
    frmDesign.Font.Name := 'MS Sans Serif';
    frmDesign.Font.Style := [];
    frmDesign.Visible := False;
    frmDesign.PixelsPerInch := 96;
    OpenNewForm := TButton.Create(frmDesign);
    OpenNewForm.Parent := frmDesign;
    OpenNewForm.Left := 88;
    OpenNewForm.Top := 32;
    OpenNewForm.Width := 89;
    OpenNewForm.Height := 25;
    OpenNewForm.Caption := 'Open New Form';
    OpenNewForm.TabOrder := 8;
    OpenNewForm.OnClick := @ButtonClick;
    End;

    procedure SafeInitForm;
    var
      v: TVariantArray;
    begin
      setarraylength(V, 0);
      ThreadSafeCall('InitForm', v);
    end;

    procedure ShowFormModal;
    begin
      frmDesign.ShowModal;
    end;

    procedure SafeShowFormModal;
    var
      v: TVariantArray;
    begin
      setarraylength(V, 0);
      ThreadSafeCall('ShowFormModal', v);
    end;

    Procedure InitForm2;
    Begin
    frmDesign2 := TForm.Create(nil);
    frmDesign2.Left := 288;
    frmDesign2.Top := 151;
    frmDesign2.Width := 172;
    frmDesign2.Height := 61;
    frmDesign2.Caption := 'frmDesign';
    frmDesign2.Color := clBtnFace;
    frmDesign2.Font.Color := clWindowText;
    frmDesign2.Font.Height := -11;
    frmDesign2.Font.Name := 'MS Sans Serif';
    frmDesign2.Font.Style := [];
    frmDesign2.Visible := False;
    frmDesign2.PixelsPerInch := 96;
    Label1 := TLabel.Create(frmDesign);
    Label1.Parent := frmDesign2;
    Label1.Left := 48;
    Label1.Top := 8;
    Label1.Width := 72;
    Label1.Height := 13;
    Label1.Caption := 'Yay New Form!';
    End;

    procedure SafeInitForm2;
    var
      v: TVariantArray;
    begin
      setarraylength(V, 0);
      ThreadSafeCall('InitForm2', v);
    end;

    procedure ShowFormModal2;
    begin
      frmDesign2.ShowModal;
    end;

    procedure SafeShowFormModal2;
    var
      v: TVariantArray;
    begin
      setarraylength(V, 0);
      ThreadSafeCall('ShowFormModal2', v);
    end;

    Procedure ButtonClick(Sender: TObject);
    Begin
      Case Sender Of
        OpenNewForm :
        Begin
          SafeInitForm2;
          SafeShowFormModal2;
        End;
      End;
    End;

    Begin
      SafeInitForm;
      SafeShowFormModal;
    End.
    I found that here.
    Join the IRC! irc.rizon.net:6667/srl | SQLite (0.99rc3+) | SRL Doc | Simba Doc | Extra Simba Libraries (openSSL & sqlite3)
    Quote Originally Posted by #srl
    10:45 < Toter> daphil when can get sex anyday I want
    10:45 < Toter> he is always on #SRL
    "A programmer is just a tool which converts caffeine into code"

Thread Information

Users Browsing this Thread

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

Posting Permissions

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