Sign in to follow this  
Followers 0
Vindicator209

script re writing itself?

6 posts in this topic

myuh, Ive got a "Monster Maker" for a game of mine, and I want the user's to be able to "save" their monster, now, how would I go about writing a WHOLE region of my scipt to a text file?


[center]"When you look at old, classic games like Snake, you often put it off because it's such a simple game, but it's only when you actually try and create your own unique game from scratch, do you finally appreciate those games."[/center][center]Don't ask for answers if you haven't TRIED yet![/center][center]Most answers can be answered in the help file! Use it![/center]

Share this post


Link to post
Share on other sites



filewrite("script.txt", fileread(@scriptfullpath))

that should get you started out. Only works for un compiled code.

Or i would suggest using the INI functions. Look in the helpfile.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Maybe these functions can help you:

Func _FileWriteRegion($inFile, $nStartLine, $nEndLine, $outFile)
    if (not FileExists($inFile)) Then Return -1

    $hFile = FileOpen($inFile, 0)
    $hOutFile = FileOpen($outFile, 1)
    For $i = $nStartLine to $nEndLine
        FileWriteLine($hOutFile, FileReadLine($hFile, $i))
    Next
FileCLose($hFile)
FileClose($hOutFile)
EndFunc

Func _FileReadRegion($inFile, $nStartLine, $nEndLine)
    if (not FileExists($inFile)) Then Return -1
    Local $sStr = ""
    $hFile = FileOpen($inFile, 0)
    For $i = $nStartLine to $nEndLine
        $sStr &= FileReadLine($hFile, $i) & @CRLF
    Next
    Return $sStr
FileClose($hFile)
EndFunc

if your trying to save a game... you might want to write stuff like this to an INI like spyro said:

[Monster1]

Lives=1

Score=100

Level=25

and then reading it, and loading the game to that specific part. :whistle:

Edited by CHRIS95219

Share this post


Link to post
Share on other sites

Maybe these functions can help you:

Func _FileWriteRegion($inFile, $nStartLine, $nEndLine, $outFile)
    if (not FileExists($inFile)) Then Return -1

    $hFile = FileOpen($inFile, 0)
    $hOutFile = FileOpen($outFile, 1)
    For $i = $nStartLine to $nEndLine
        FileWriteLine($hOutFile, FileReadLine($hFile, $i))
    Next
EndFunc

Func _FileReadRegion($inFile, $nStartLine, $nEndLine)
    if (not FileExists($inFile)) Then Return -1
    Local $sStr = ""
    $hFile = FileOpen($inFile, 0)
    For $i = $nStartLine to $nEndLine
        $sStr &= FileReadLine($hFile, $i) & @CRLF
    Next
    Return $sStr
EndFunc

if your trying to save a game... you might want to write stuff like this to an INI like spyro said:

[Monster1]

Lives=1

Score=100

Level=25

and then reading it, and loading the game to that specific part. ;)

You never closed any of those files :whistle:

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

You never closed any of those files :whistle:

lmao! That was'nt part of the deal!!

Share this post


Link to post
Share on other sites

not even going to pretend I knew any of that'


[center]"When you look at old, classic games like Snake, you often put it off because it's such a simple game, but it's only when you actually try and create your own unique game from scratch, do you finally appreciate those games."[/center][center]Don't ask for answers if you haven't TRIED yet![/center][center]Most answers can be answered in the help file! Use it![/center]

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  
Followers 0