Read file line and write to file

thorthor

Member
I am trying to write a script that reads the first line from TextA (an item name), look it up in a database, convert it to an itemid and write the ID in TextB.

PHP:
function main()
{
Declare Buffer binary

Declare File file TextA.txt
Declare FP filepath "${Script.CurrentDirectory}"

Declare File file TextB.txt
Declare FP filepath "${Script.CurrentDirectory}"

		string currentitem
		
		;;Loading DB
		LavishSettings:Import[${CONFIG_FILE}]
		LavishSettings[${SET_NAME}]:GetSetIterator[itemIterator]

		;; Read first line and convert to TypeID
		
		Position=${TextA.Position} 
                currentitem=${TextA.Read} 
                TypeID(currentitem)

		Write=${TextB:Write[" ${currentitem} , ${TypeID}"] 
	return
}
For some reason this doesnt work. Thanks for your help in advance :)
 

pr517

Active Member
The code looks incomplete with variables that may or may not be set prior (CONFIG_FILE and SET_NAME), but besides that this is what stands out right away to me:

Code:
Declare File file TextA.txt 
Declare FP filepath "${Script.CurrentDirectory}" 

Declare [COLOR="Red"]File[/COLOR] file TextB.txt 
Declare [COLOR="red"]FP [/COLOR]filepath "${Script.CurrentDirectory}"
You are making multiple declares for the same variable name. These need to be unique. The lowercase "file" and "filepath" are object types. The uppercase "File" and "FP" are arbitrary variable names that you picked. Choose something else for your variable names so it's not so confusing. Like...

"Declare fIn file texta.txt" and then manipulate it with ${fIn.Position}, ${fIn.Read}, etc.
"Declare fOut file textb.txt" and then manipulate it with ${fOut.Position}, ${fOut:Write["blah blah"]}, etc.

Code:
Position=${TextA.Position}
There is no such declared variable called TextA, remember? You called it "File". I don't know anything about ISXEVE, but in Lavishscript you cannot use the equal sign to assign value. So it would look something more like... "Position:Set[${TextA.Position}]" (assuming there actually is a TextA variable and "Position" isn't a reserved name.)

In the ObjectType:file Wiki page, you do see the "echo Position=${File.Position}" line, but that is because it is in an echo command. You can do practically anything syntax-wise with an echo command because it is simply writing what you pass to the console and not evaluating it for syntax.
 

Dim454

Member
I am trying to write a script that reads the first line from TextA (an item name), look it up in a database, convert it to an itemid and write the ID in TextB.

PHP:
function main()
{
Declare Buffer binary

Declare File file TextA.txt
Declare FP filepath "${Script.CurrentDirectory}"

Declare File file TextB.txt
Declare FP filepath "${Script.CurrentDirectory}"

		string currentitem
		
		;;Loading DB
		LavishSettings:Import[${CONFIG_FILE}]
		LavishSettings[${SET_NAME}]:GetSetIterator[itemIterator]

		;; Read first line and convert to TypeID
		
		Position=${TextA.Position} 
                currentitem=${TextA.Read} 
                TypeID(currentitem)

		Write=${TextB:Write[" ${currentitem} , ${TypeID}"] 
	return
}
For some reason this doesnt work. Thanks for your help in advance :)
LavishSettings:Import[${CONFIG_FILE}] is used for XML import/export.

http://www.lavishsoft.com/wiki/index.php/LavishSettings:settingset_(Object_Type)

you dont write to a settings file with "Write=${TextB:Write[" ${currentitem} , ${TypeID}"]"

it looks more like:

LavishSettings[DataTrackerSettings].FindSet[${SetName}]:AddSetting[TypeID,${OrderIterator.Value.TypeID}]
LavishSettings[DataTrackerSettings]:Export[${DATA_FILE}]
 
Top Bottom