Page 1 of 1 1
Topic Options
#180330 - 2007-09-10 05:20 AM help need variable from ini
thunderchero Offline
Fresh Scripter

Registered: 2007-09-08
Posts: 14
Loc: USA
Help again,

I need to set a variable from an ini file. right now I want to use $rom as variable, ini file name is "stbof.ini". also the path variable I am using to ini file is "$install+" And ini file looks like this;

CDPATH=F:\
HDPATH=C:\botf\
CURRENTGAME=0
LANGUAGE=ENGLISH
VICTORY=KILLALL
INSTALL=MAXIMUM
3D=DIRECT3D
TACTICAL=DETAILED
SOUNDON=ON

I need Variable to be "F:\" "or what ever is in ini"

if any one can get me the right script it would be great.

thunderchero

Top
#180331 - 2007-09-10 05:23 AM Re: help need variable from ini [Re: thunderchero]
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
You don't show the section header. What is it?
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#180333 - 2007-09-10 05:30 AM Re: help need variable from ini [Re: Les]
thunderchero Offline
Fresh Scripter

Registered: 2007-09-08
Posts: 14
Loc: USA
that is all that is in the ini

thunderchero


Edited by thunderchero (2007-09-10 05:32 AM)

Top
#180334 - 2007-09-10 05:51 AM Re: help need variable from ini [Re: thunderchero]
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Then IMHO it is not a properly formatted INI. I don't think ReadProfileString() will be able to read it. Is it of your making? Can you not add a header?
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#180335 - 2007-09-10 05:54 AM Re: help need variable from ini [Re: Les]
thunderchero Offline
Fresh Scripter

Registered: 2007-09-08
Posts: 14
Loc: USA
It is not of my making it was made in 1999

thunderchero

Top
#180336 - 2007-09-10 06:02 AM Re: help need variable from ini [Re: thunderchero]
thunderchero Offline
Fresh Scripter

Registered: 2007-09-08
Posts: 14
Loc: USA
Ok If I make ini look like this;

[settings]
CDPATH=F:\
HDPATH=C:\botf\
CURRENTGAME=0
LANGUAGE=ENGLISH
VICTORY=KILLALL
INSTALL=MAXIMUM
3D=DIRECT3D
TACTICAL=DETAILED
SOUNDON=ON


the next time game starts it removes it so would that work?

thunderchero

Top
#180337 - 2007-09-10 06:03 AM Re: help need variable from ini [Re: thunderchero]
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
YOu could add a section header to the INI file and then use ReadProfileString().
 Code:
Break On

$path='C:\'
$file='test.ini'
$rom=ReadProfileString($path+$file,'header','CDPATH')

$rom ?
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#180338 - 2007-09-10 06:06 AM Re: help need variable from ini [Re: thunderchero]
thunderchero Offline
Fresh Scripter

Registered: 2007-09-08
Posts: 14
Loc: USA
ReadProfileString() was what I was tring to use But never got it to work now I know why. but please still help me.

thunderchero

Top
#180339 - 2007-09-10 06:17 AM Re: help need variable from ini [Re: thunderchero]
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Alternately, you can use the ReadFile() UDF and Split().
 Code:
Break On
Function ReadFile($file)
	Dim $lf, $f, $_, $t
	$lf=chr(10)
	$f=freefilehandle
	$_=open($f,$file)
		if @error   exit @error   endif
		do $t=$t+$lf+readline($f) until @error
		$_=close($f)
	$ReadFile=split(substr($t,2),$lf)
EndFunction
$rom=''
$path='C:\'
$file='test.ini'
$romarray=Readfile($path+$file)
For $Line = 0 to UBound($romarray)
 If Split($romarray[$Line],'=')[0]='CDPATH'
  $rom = Split($romarray[$Line],'=')[1]
  $Line = UBound($romarray)
 EndIf
Next
$rom ?
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#180345 - 2007-09-10 01:23 PM Re: help need variable from ini [Re: Les]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
Hmm- it sounds like the "real" utility that uses this file removes the header. I guess you want to be able to change values in this before you use the real program? If so, try this:
 Code:
Move 'stbof.ini' 'stbof.bak'    ; rename original file
$ = RedirectOutput('stbof.ini') ; create new file
'[Settings]' ?                  ; add header
Display 'stbof.bak'             ; add original content to new file
$ = RedirectOutput('')          ; Close redirection
Del 'stbof.bak'                 ; clean up

If you don't need to modify the original content, but simply read it, simplify the above to:
 Code:
$ = RedirectOutput('MYstbof.ini') ; create new file
'[Settings]' ?                    ; add header
Display 'stbof.ini'               ; add original content to new file
$ = RedirectOutput('')            ; Close redirection

; read whatever you need from the new, properly formatted INI file
$Install = ReadProfileString('MYstbof.ini', 'SETTINGS', 'CDPATH')

Del 'MYstbof.ini'                 ; clean up


Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#180348 - 2007-09-10 01:49 PM Re: help need variable from ini [Re: Glenn Barnas]
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Ummm... you renamed it, remember?
 Code:
Display 'stbof.bak'             ; add original content to new file
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#180349 - 2007-09-10 02:43 PM Re: help need variable from ini [Re: Les]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
That's right, I renamed it...

Then created a new empty file with the original name.

Then added a header line to the new file that was missing in the original.

Then took the backed-up file contents and added them to the new file after the header, which is why I'm referencing the .BAK file in the Display command. Remember - the RedirectOutput is still in effect. Thus, the content in the original file name now looks like a valid INI file.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#180350 - 2007-09-10 02:54 PM Re: help need variable from ini [Re: Glenn Barnas]
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Ja, but in your simplified version, it no worky unless you have stbof.bak as in the first example.
[edit]Nevermind... you surely went back and edited your original post


Edited by Les (2007-09-10 02:56 PM)
Edit Reason: Glenn is playing a shell game
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#180352 - 2007-09-10 03:03 PM Re: help need variable from ini [Re: Les]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
Huh?

The first example is used if you want to modify the orignial and convert it to an INI format, hence the rename and copy of the BAK onto the INI. The second makes a new .INI file in proper format called MYstbof.ini. Since the original wasn't renamed, Display references the original .INI file and not the BAK.

G-
_________________________
Actually I am a Rocket Scientist! \:D

Top
#180353 - 2007-09-10 03:12 PM Re: help need variable from ini [Re: Glenn Barnas]
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
I know what the currently posted code does. I should have taken a screenshot *before* you edited. \:\)
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#180360 - 2007-09-10 05:20 PM Re: help need variable from ini [Re: Les]
thunderchero Offline
Fresh Scripter

Registered: 2007-09-08
Posts: 14
Loc: USA
Les,

I got the second one (read file) to work for me. Had to create folder in my install folder and copy the ini into folder so it would read from full path.

Thanks
thunderchero

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Allen) and 466 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.067 seconds in which 0.023 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org