PDA

View Full Version : regarding ini files


jhn9119
01-02-2004, 09:49 AM
hi guys

first off......happy new year to everyone :)

i've been playing with the ini file actions and what i'm lookin at is using an ini file to allow changes to an image (width, height, x pos, y pos & opacity) so say this is my ini section and values

[Sample Button 1]
Width = 300
Height = 50
X = 655
Y = 336
Opacity = 100

and this would be my code in the onpreload of the page to set the image stuff

-- get button information
strbutW = INIFile.GetValue(_SourceFolder .. "\\sample.ini", "Sample Button 1", "Width");
strbutH = INIFile.GetValue(_SourceFolder .. "\\sample.ini", "Sample Button 1", "Height");
strbutX = INIFile.GetValue(_SourceFolder .. "\\sample.ini", "Sample Button 1", "X");
strbutY = INIFile.GetValue(_SourceFolder .. "\\sample.ini", "Sample Button 1", "Y");
strbutO = INIFile.GetValue(_SourceFolder .. "\\sample.ini", "Sample Button 1", "Opacity");

-- set the values to the button
Image.SetSize("sample_but_1", strbutW, strbutH);
Image.SetPos("sample_but_1", strbutX, strbutY);
Image.SetOpacity("sample_but_1", strbutO);
Image.SetVisible("sample_but_1", true);

using that code works absolutly fine for what i want to achieve but if you had 10+ buttons on a page then the code would be quite long so i'm wondering if there is a better way to read the ini values for a specified section into a table

i see you can read all section names into a table but not the values within a section so would the way i've done it above be the best way to achieve this

one way i was thinking was to create the ini file sections like this

[Sample Button 1]
Setting1 = 300
Setting2 = 50
Setting3 = 655
Setting4 = 336
Setting5 = 100

and then use a loop to go through setting1-5 and add the values into a table but does anyone know a better way to script it

Thanks for any replies but dont post the code just your thoughts on possible ways, the best way to get used to it is coding it yourself :)

Brett
01-02-2004, 10:00 AM
It is not the INI file reading that will take a long time, it is the image processing. Reading from the INI file is very quick. However, if you want to read the INI file to a table I would make a table of tables. Here is an illustration of how to make a table of tables without going into the INI stuff...

tblOne = {};

tblOne[1] = {a = 1, b = 2};
tblOne[2] = {h = 8, kaj = 882};

Now you can index them like so:

Value = tblOne[2].h;

So, I would use the INI file actions to read the INI file sections and values into a table of tables - one subtable per section.

There is a lot of good info in the Scripting Reference about tables.

jhn9119
01-02-2004, 10:15 AM
thanks for the reply Brett, i'll go have a play using that method

jhn9119
01-02-2004, 03:10 PM
just to say that using the info you posted Brett i changed from calling the image info on the onpreload to a function

-- sample.ini function for getting details
function getimagelayout(Name)
strimgarray = {"Name", "Width", "Height", "X", "Y", "Opacity"};
strimgcount = 1;
strimgprops = {};
while (strimgcount <= 6) do
-- first check if value exists
strskinicheck = INIFile.GetValue(_SourceFolder .. "\\sample.ini", Name, strimgarray[strimgcount]);
if strskinicheck == "" then
break;
end -- end if ini value dosnt exist check
strimgprops[strimgcount] = {a = strskinicheck};
strimgcount = strimgcount + 1;
end -- end while
-- set image props
Image.SetSize(strimgprops[1].a, strimgprops[2].a, strimgprops[3].a);
Image.SetPos(strimgprops[1].a, strimgprops[4].a, strimgprops[5].a);
Image.SetOpacity(strimgprops[1].a, strimgprops[6].a);
Image.SetVisible(strimgprops[1].a, true);
end -- end function

this is the first write so once i tidy it up then i'll be happier but works perfectly and i cant tell if theres a speed difference but if there is then it isnt a noticeable difference

doing it this way means i only need 1 line of code (calling the function(imagename) for each image thats changeable) instead of the previously posted 9 lines per changeable image

thanks again Brett for the info and i now have smaller code to sort out :)