ReadINI / WriteINI for Action.Quit / Action.StopEverything

This forum is meant for requesting technical support or reporting bugs.

Moderators: time-killer-games, Vengeance66, Candle, reneuend, GM-Support

ReadINI / WriteINI for Action.Quit / Action.StopEverything

Postby time-killer-games » Wed Jun 08, 2011 7:56 pm

I'm making an external software for AM that allows your game to close after the escape key is pressed. Before I can do that, I'm a little confused with INI reading and writing. I want to write an INI file that would (once read) would close the game. There will be two versions of this, one will perform Action.Quit and the other Action.StopEverything.

How do I go about writing and reading and INI file that could trigger closing the game? What will the VBScript code be?

Please note I'm not asking how to close the game from the escape key I already know how to do that.

Thanks!
TKG
User avatar
time-killer-games
Expert Member
 
Posts: 400
Joined: Fri Dec 24, 2010 6:10 pm
Location: Virginia Beach, VA

Postby reneuend » Wed Jun 08, 2011 8:01 pm

Instead of using the ini file which works with Key/Values, you could just use a text file to store the information.

Here are some routines I wrote a long time ago which works very well.
Note: the file is stored in the External folder

Code: Select all
Sub Write2File(yourfilename, byval savetext)
  dim myfile
  set filesys = CreateObject ("Scripting.FileSystemObject")
  set myfile = filesys.CreateTextFile (GetPath(2) & yourfilename, true)
  set myfile = filesys.GetFile(GetPath(2) & yourfilename)
  set txtstream = myfile.OpenAsTextStream (2, -2)
  txtstream.Write savetext
  txtstream.Close
End Sub


Code: Select all
Function GetFileContents(yourfilename)
  dim mytext
  dim myfile
  set filesys = CreateObject ("Scripting.FileSystemObject")
  set myfile = filesys.GetFile(GetPath(2) & yourfilename)
  set txtstream = myfile.OpenAsTextStream (1, -2)
  mytext = txtstream.readline()
  txtstream.Close
  GetFileContents = mytext
End Function


Code: Select all
Function GetAllFileContents(yourfilename)

  Dim mytext
  Dim myfile

  set filesys = CreateObject ("Scripting.FileSystemObject")
  set myfile = filesys.GetFile(GetPath(2) & yourfilename)
  set txtstream = myfile.OpenAsTextStream (1, -2)

  mytext = txtstream.readall()
  txtstream.Close

  GetAllFileContents = mytext

End Function




Usage:

----------------------------
'Grab all the lines of data from the file and display each line by line

Code: Select all
Dim alldata
Dim idx

data = GetAllFileContents("testfile.txt")

alldata = split(data,vbcrlf)

for idx = 0 to ubound(alldata)
  MsgBox alldata(idx)
Next

------------------------------
---


Image
Image
User avatar
reneuend
Administrator
 
Posts: 2691
Joined: Sat Nov 22, 2008 8:37 pm
Location: Midwest Cornfield, USA


Return to Adventure Maker Technical Support and Bug Reports

Who is online

Users browsing this forum: No registered users and 2 guests

cron