Jump to content
Sign in to follow this  
Pharo

_FileWriteToLine question

Recommended Posts

Pharo

I'm try to get a value ($line) to increase by 1 and then write over the old value. It will read the number correctly, add 1 to it correctly but won't write it.

CODE

$line = FileReadLine("items.txt",3)

$line=$line+1

_FileWriteToLine("items.txt", 3,($a), 0)

Share this post


Link to post
Share on other sites
Authenticity

Try to play around with the _WinAPI_* functions as they use the pure (or close to pure) API call.

Like: _WinAPI_SetFilePointer, _WinAPI_WriteFile etc..

Share this post


Link to post
Share on other sites
Skruge

Welcome to the forums.

$a isn't defined anywhere in your code.

If you check @error after the _FileWriteLine call, you'll see that the text is invalid. Apparently the function wants an actual string, not an integer. You can get around this by converting it.

Also, to replace the line (not insert), set the fourth parameter to 1.

Try this:

$line = FileReadLine("items.txt", 3)
        $line = $line + 1
        _FileWriteToLine("items.txt", 3, String($line), 1)

[font="Tahoma"]"Tougher than the toughies and smarter than the smarties"[/font]

Share this post


Link to post
Share on other sites
Authenticity

Also, for the purpose of your problem try to build the file's line like this 'Item.txt|54' and use the following methods:

Opt('MustDeclareVars', 1)

Dim $sLine = 'Items.txt|53'
Dim $Arr

$Arr = StringSplit($sLine, '|')
$Arr[2] = '128'

$sLine = $Arr[1] & '|' & $Arr[2]

FileWrite('Weapons.txt', $sLine)

Or something similar...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.