SRL Archive - Help and Support

Ini help


Bonfield

2011-03-21 05:21:41

Im trying to make a procedure that writes an ini of a custom type here is the code

program new;
type
TItem = record
Name: String;
Uptext: TStringArray;
Outline_Count: Integer;
Width: Integer;
Height: Integer;
Middle_Colour : Integer;
Red_Count: Integer;
Ref_ID: Integer;
WithdrawAmount: Integer;
end;

var
Item1, Item2, Item3 : TItem;
i, h : integer;
Item: Array of TItem;

procedure LoadRecords;
begin
with Item1 do
begin
Name := 'Item1';
UpText := ['Item1', 'tem1'];
Outline_Count := 141;
Width := 29;
Height := 13;
Middle_Colour := 2105392;
Red_Count := 0
Ref_ID := 12;
WithdrawAmount := 1;
end;

with Item2 do
begin
Name := 'Item2';
UpText := ['Item2', 'tem2'];
Outline_Count := 70;
Width := 29;
Height := 12;
Middle_Colour := 5731970;
Red_Count := 86;
Ref_ID := 13;
WithdrawAmount := 1;
end;

with Item3 do
begin
Name := 'Item3';
UpText := ['Item3', 'tem3'];
Outline_Count := 71;
Width := 39;
Height := 13;
Middle_Colour := 5863556;
Red_Count := 78;
Ref_ID := 14;
WithdrawAmount := 0;
end;
end;

begin
SetLength(Item, 3);
LoadRecords;
Item :=[Item1, Item2, Item3];
h := High(Item);
for i:= 0 to h do
begin
WriteINI(Item[i].Name+' Record', 'Name', Item[i].Name, ScriptPath+'players.ini');
WriteINI(Item[i].Name+' Record', 'UpText', ToStr(Item[i].UpText), ScriptPath+'players.ini');
WriteINI(Item[i].Name+' Record', 'Outline_Count', ToStr(Item[i].Outline_Count), ScriptPath+'players.ini');
WriteINI(Item[i].Name+' Record', 'Width', ToStr(Item[i].Width), ScriptPath+'players.ini');
WriteINI(Item[i].Name+' Record', 'Height', ToStr(Item[i].Height), ScriptPath+'players.ini');
WriteINI(Item[i].Name+' Record', 'Middle_Colour', ToStr(Item[i].Middle_Colour), ScriptPath+'players.ini');
WriteINI(Item[i].Name+' Record', 'Red_Count', ToStr(Item[i].Red_Count), ScriptPath+'players.ini');
WriteINI(Item[i].Name+' Record', 'Ref_ID', ToStr(Item[i].Ref_ID), 'C:\Users\SAMSUNG\Desktop\New Folder\players.ini');
WriteINI(Item[i].Name+' Record', 'WithdrawAmount', ToStr(Item[i].WithdrawAmount), ScriptPath+'players.ini');
end;
end.

it works fine once, but if I try to run it again I get this error
Error: Exception: Unable to create file
it cycles through Width, Ref_ID and UpText lines, i can not see what is causing this


also I would like to compare the current ini with records created during runtime, i want this to eventually end up auto-updating my item records, what would be the easiest way to compare the values to see if an update is needed?

something like this?
function Item(ItemOutLine, ItemWidth, ItemHeight, ItemColor: Integer): TItem;
begin
with Result do
begin
OutLine := ItemOutLine;
Width := ItemWidth;
Height := ItemHeight;
Color := ItemColor;
//etc for the rest of the type
end;
end;

and compare from there?

Floor66

2011-03-21 11:01:34

Have you tried changing the Path to "./players.ini" instead of ScriptPath? That should def. fix the error.

Btw, this line:
      WriteINI(Item[i].Name+' Record', 'Ref_ID', ToStr(Item[i].Ref_ID), 'C:\Users\SAMSUNG\Desktop\New Folder\players.ini');

The path is incorrect of course.

And yes, you could use a constructor like Item(): TItem;

EDIT:
This is an example of how it can be done:

program new;
type
TItem = record
Name: String;
Uptext: TStringArray;
Outline_Count: Integer;
Width: Integer;
Height: Integer;
Middle_Colour : Integer;
Red_Count: Integer;
Ref_ID: Integer;
WithdrawAmount: Integer;
end;

type
TItemArray = Array of TItem;

var
i, h : integer;
Items: TItemArray;

function Item(v : TVariantArray): TItem;
begin
SetLength(v, 9);
with Result do
begin
Name := v[0];
UpText := v[1];
Outline_Count := v[2];
Width := v[3];
Height := v[4];
Middle_Colour := v[5];
Red_Count := v[6];
Ref_ID := v[7];
WithdrawAmount := v[8];
end;
end;

function LoadRecords: TItemArray;
begin
Result := [
Item(['Item1', ['Item1', 'tem1'], 141, 29, 13, 2105392, 0, 12, 1]),
Item(['Item2', ['Item2', 'tem2'], 129, 25, 15, 5102382, 0, 19, 1]),
Item(['Item3', ['Item3', 'tem3'], 135, 20, 12, 4105832, 0, 10, 1]) //Just keep adding 'em.
];
end;

begin
Items := LoadRecords;
h := High(Items);
for i:= 0 to h do
begin
WriteINI(Items[i].Name +' Record', 'Name', Items[i].Name, './players.ini');
WriteINI(Items[i].Name +' Record', 'UpText', ToStr(Items[i].UpText), './players.ini');
WriteINI(Items[i].Name +' Record', 'Outline_Count', ToStr(Items[i].Outline_Count), './players.ini');
WriteINI(Items[i].Name +' Record', 'Width', ToStr(Items[i].Width), './players.ini');
WriteINI(Items[i].Name +' Record', 'Height', ToStr(Items[i].Height), './players.ini');
WriteINI(Items[i].Name +' Record', 'Middle_Colour', ToStr(Items[i].Middle_Colour), './players.ini');
WriteINI(Items[i].Name +' Record', 'Red_Count', ToStr(Items[i].Red_Count), './players.ini');
WriteINI(Items[i].Name +' Record', 'Ref_ID', ToStr(Items[i].Ref_ID), './players.ini');
WriteINI(Items[i].Name +' Record', 'WithdrawAmount', ToStr(Items[i].WithdrawAmount), './players.ini');
end;
end.

Bonfield

2011-03-21 15:53:35

i changed it to
'./players.ini'
but still get this error
Error: Exception: Unable to create file "./players.ini" at line 71
this is line 71
 WriteINI(Item[i].Name+' Record', 'UpText', (Implode(',',Item[i].UpText)), './players.ini'); 
also how is ./players.ini different to scriptpath+….?

i luffs yeww

2011-03-21 16:03:33

You never opened the file, which I'm prettttty sure you need to do before writing to it. idr the params for OpenFile.

Floor66

2011-03-21 16:38:17

It's not openfile, it's WriteINI.
Openfile = WriteFileString

E:
From: Bonfield
i changed it to
'./players.ini'
but still get this error
Error: Exception: Unable to create file "./players.ini" at line 71
this is line 71
 WriteINI(Item[i].Name+' Record', 'UpText', (Implode(',',Item[i].UpText)), './players.ini'); 
also how is ./players.ini different to scriptpath+….?


Have you tried what I posted at the bottom? That worked for me.
What OS are you on? You might need to set read/write permissions.

Gu3st...

2011-03-21 18:58:55

Are you running Simba with administrator rights?

Bonfield

2011-03-22 01:57:22

yeah running with administrator rights, i restarted my computer and it seems to work fine, i will try to recreate the error as i havent changed any code

floor will run your code and see how it goes thanks