Custom Save/Load System (lots of scripting)
Posted: Thu Apr 03, 2008 8:00 pm
Hey! Did you miss my tutorials? Here I am again with a brand new one!
I always wanted to use custom save/load frames, because I don't like being unable to customize AM's own system. So today, while looking into a VB guide to find some new techniques, I discovered how to do this (it has nothing to do with the guide I was reading, just came to my mind ).
What you can use this method for: You can create custom frames containing custom Save/Load Buttons and no pop-up box is going to spoil the ambience of your game anymore.
As you should know, if you 've watched my tutorials, I definitely love the INI-based systems. So we are going to use .ini files to save our progress. Here's how to do this:
We 've got to save the information needed by AM to load the situation of a game into the ini. So we 've got to save the variables' status, the current frame and the current state of the inventory.
But let's start from the basics:
Create the frame that will be used for saving/loading.
Create two Hotspots representing save and load
Go to the "save" hotspot. Go to advanced. Add this code:
Now create a hotspot representing OK.
Go to the frame's advanced, add this code:
Go to the hotspot representing the OK Button
In Advanced place this code:
declare the variables frametosave and filename as Variants using AM variable system
Go to the Load Button and use the same code as for the save button, only alter it, so as to load a textbox with an index of "2":
Create a second Ok button, which will be used for the Load feature.
Read the .INI file using returnvalue=Action.ReadINI(filename+".save",index,row):
Now create a "back" button
Make it so that it takes the player back to the last visited frame.
Now in the hotspots which are going to take the player to the custom save/load screen, apart from adding that code, add this one too
Hope you understand this and you like it.
You can also use Browsing objects to load the game instead of writting the filename.
I always wanted to use custom save/load frames, because I don't like being unable to customize AM's own system. So today, while looking into a VB guide to find some new techniques, I discovered how to do this (it has nothing to do with the guide I was reading, just came to my mind ).
What you can use this method for: You can create custom frames containing custom Save/Load Buttons and no pop-up box is going to spoil the ambience of your game anymore.
As you should know, if you 've watched my tutorials, I definitely love the INI-based systems. So we are going to use .ini files to save our progress. Here's how to do this:
We 've got to save the information needed by AM to load the situation of a game into the ini. So we 've got to save the variables' status, the current frame and the current state of the inventory.
But let's start from the basics:
Create the frame that will be used for saving/loading.
Create two Hotspots representing save and load
Go to the "save" hotspot. Go to advanced. Add this code:
- Code: Select all
LoadControl TextBoxObject(1)
UnLoadControl TextBoxObject(2)
'the next line will be explained later
Hotspot(thehotspotrepresentingthesecondOk).Enabled=False
'Place the textbox where you want it using your coordinates instead of x,y,w,h
TextBoxObject(1).move x,y,w,h
TextBoxObject(1).visible=True
Hotspot(thehotspotrepresentingOK).enabled=True
Now create a hotspot representing OK.
Go to the frame's advanced, add this code:
- Code: Select all
Hotspot(thehotspotrepresentingOK).enabled=False
Go to the hotspot representing the OK Button
In Advanced place this code:
- Code: Select all
If TextBoxObject(1).Text<>"" then
filename=TextBoxObject.Text
'This will take the names of the inventory items and store them under index 1
I=0
For Each X in InventoryItemObject
I=I+1
A=X.tag
Action.WriteINI filename+".save",1,I,A
'You can replace .save with anything you want
next
'to take the status of your variables, manually add this line for each of your variables:
Action.writeINI filename+".save",2,1,myvariable
Action.writeINI filename+".save",3,1,"myvariable"
'remember to change the row number each time (the 1 you can see above)
Action.WriteINI filename+".save",4,1,frametosave
'frametosave will be set in another part of the tutorial
TextBoxObject(1).Text="Progress Saved"
declare the variables frametosave and filename as Variants using AM variable system
Go to the Load Button and use the same code as for the save button, only alter it, so as to load a textbox with an index of "2":
- Code: Select all
LoadControl TextBoxObject(2)
UnLoadControl TextBoxObject(1)
'etc
Hotspot(thehotspotrepresentingthesecondOK).Enabled=True
Create a second Ok button, which will be used for the Load feature.
Read the .INI file using returnvalue=Action.ReadINI(filename+".save",index,row):
- Code: Select all
For I=2 to ubound
savedinventoryitem=Action.ReadINI(filename+".save",1,I)
If HasItem(savedinventoryitem)=False then
Action.AddItem savedinventoryitem
Next
'to make this work, copy/paste the HasItem Function in your project's VBS Procedures
Function HasItem(ItemName)
HasItem = False
For Each X in InventoryItemObject
If X.Tag = ItemName Then
HasItem = True
End If
Next
End Function
For C=1 to Ubound
Action.ReadINI(filename+".save",3,C)=Action.ReadINI(filename+".save",2,C)
Next
Action.GotoFrame Action.ReadINI(filename+".save",4,1
Now create a "back" button
Make it so that it takes the player back to the last visited frame.
Now in the hotspots which are going to take the player to the custom save/load screen, apart from adding that code, add this one too
- Code: Select all
frametosave=Action.GetCurrentFrameName
Hope you understand this and you like it.
You can also use Browsing objects to load the game instead of writting the filename.