Custom Save/Load System (lots of scripting)

This forum is meant for people to share their knowledge by writing their own tutorials for Adventure Maker.

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

Custom Save/Load System (lots of scripting)

Postby Lyberodoggy » 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 :P).

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.
User avatar
Lyberodoggy
Administrator
 
Posts: 2526
Joined: Sat Feb 17, 2007 3:31 pm
Location: Athens

Postby GM-Support » Thu Apr 03, 2008 10:11 pm

Great idea!
GM-Support
Forum Admin and Games Page admin
 
Posts: 2221
Joined: Thu Jun 05, 2003 7:52 pm

Postby Candle » Thu Apr 03, 2008 10:14 pm

Could you add a small project for others.
Looks good.
Please don't PM me questions, ask here in the forums!
``````````````
Between grand theft and a legal fee, there only stands a law degree.
User avatar
Candle
Administrator
 
Posts: 3077
Joined: Sat Feb 07, 2004 2:21 am
Location: Rudy's Bar

Postby Lyberodoggy » Thu Apr 03, 2008 10:20 pm

Thanks guys!
To candle: Oh gosh! I hoped you wouldn't ask me :P

Anyway, I 'll try... But tommorow. I 'm too tired and it's 12:20 at midnight over here...
User avatar
Lyberodoggy
Administrator
 
Posts: 2526
Joined: Sat Feb 17, 2007 3:31 pm
Location: Athens

Postby Lyberodoggy » Sat Apr 05, 2008 8:32 am

Yeah... I finally prevailed over that BIG FAT BUG!!!
:lol: Sorry guys, the system needed a lot of fixing, that's why It took me so long. It's not finalised. In fact it stores one entry to the INI which is not currently needed and that Ubound line will be probably replaced by another entry that counts the stored Inventory Items... But anyway, you are free to modify it if you have any ideas. It's working pretty good right now (although I dislike the load feature because currently the player has to enter the name of the file to load. But I promise to find a way to fix this 8) )
Attachments
custom save and load.rar
A very primitive Sample
(562.98 KiB) Downloaded 995 times
User avatar
Lyberodoggy
Administrator
 
Posts: 2526
Joined: Sat Feb 17, 2007 3:31 pm
Location: Athens

Postby Imari » Sat Apr 05, 2008 11:33 pm

Hi Lyberodoggy,

Thanks for making this demo as well as all of the other bits of neat coding that you share with us. I downloaded the project demo, but the RAR file apparently is corrupted --- specifically it says the House_far.jpg. Also, when I went to run the project, I get the message in AM that the project is protected and I can't open it.

~C
User avatar
Imari
VIP
 
Posts: 872
Joined: Fri Jun 20, 2003 4:49 pm
Location: Virginia, USA

Postby Candle » Sun Apr 06, 2008 1:07 am

Works for me, only thing I would add is have it show the saved password when you go to load it.
Please don't PM me questions, ask here in the forums!
``````````````
Between grand theft and a legal fee, there only stands a law degree.
User avatar
Candle
Administrator
 
Posts: 3077
Joined: Sat Feb 07, 2004 2:21 am
Location: Rudy's Bar

Postby Mystery » Sun Apr 06, 2008 1:36 am

Works for me fine aswell, thanks Lyberodoggy :)

Imari, maybe something went wrong for you during the download process or the decompression.
User avatar
Mystery
Forum Admin and Games Page admin
 
Posts: 2990
Joined: Sat Feb 04, 2006 8:12 am
Location: Switzerland

Postby Lyberodoggy » Sun Apr 06, 2008 9:09 am

Thanks guys.
To Imari: Mystery must be right... The forum is not working sometimes... Maybe you downloaded the file at the wrong time... Try again, I 'm waiting for feed-back.
To Candle: mmm... I don't really get your point... Do you mean adding a password protection during load?
EDIT: I think I understood. Yes it's something I mentioned too:
Lyberodoggy wrote:although I dislike the load feature because currently the player has to enter the name of the file to load
.
I 'll try to add a common dialog (you know, the window that allows you to select a file from a location) when I find enough free time.
User avatar
Lyberodoggy
Administrator
 
Posts: 2526
Joined: Sat Feb 17, 2007 3:31 pm
Location: Athens

Postby Imari » Mon Feb 02, 2009 5:37 pm

Hi Lyberodoggy,
I apologize in advance for being dense, but it's been a long since I worked with AM and I'm struggling to get the hang of it again. I'm inspired to begin again, though, by all of the advances --- including the new puzzle tutorials, your wonderful tweaks, and by Shadowhunter's new FX plug-in.

Here's what I want to do....
I'm going to have a hotspot on every page that can take the player back to the Menu where I have buttons for START, LOAD, NEW GAME, RETURN TO GAME, and QUIT. When the player clicks LOAD or START, they go to a new Save/Load frame. So far, this is pretty much like your tutorial.

But I want the Save/Load frame to have 12 (or 16) slots (hotspots), each for a saved game. I'll make thumbnails for each scene and put it in the Areas folder. When the Save/Load frame is entered I want the corresponding thumbnail for the player's last place in the game to load in the next available save slot. When loading a game, I want the person to be able to click on the thumbnail/hotspot to load it.

So I guess, what I need (I guess) is a way to capture where the player was before entering the Menu frame, then have the corresponding thumbnail appear in the next available hotspot - Save01 through Save12 (or Save16 ... not sure how many save people need). Finally clicking the thumbnail needs to take the player back to that saved game.

Thanks.

(I doubt that this makes any difference at all, but I'm also going to use the same thumbnails for a "portal" device (a la the one in Myst Revelation). On the device, once the player has been to an area, the thumbnail for that area appears as a choice on the device. I'm using variables to do this.)

EDIT: Argh, sorry, Lyberodoggy. Your tutorial calls up text boxes. I see that what I'm asking for is entirely different. Back to the drawing board.
User avatar
Imari
VIP
 
Posts: 872
Joined: Fri Jun 20, 2003 4:49 pm
Location: Virginia, USA

Postby Lyberodoggy » Mon Feb 02, 2009 6:37 pm

You could use the thumbnails AM creates automatically, use them as hotspots to load the game from
User avatar
Lyberodoggy
Administrator
 
Posts: 2526
Joined: Sat Feb 17, 2007 3:31 pm
Location: Athens

Postby Imari » Tue Feb 03, 2009 10:00 pm

Good idea. Thanks again for making this. Even though it does not do exactly what I needed, it is a good learning tool for someone that is not a coder. Seeing where the bits of code should go helps i nunderstanding how it all works together.
User avatar
Imari
VIP
 
Posts: 872
Joined: Fri Jun 20, 2003 4:49 pm
Location: Virginia, USA

Postby Lyberodoggy » Tue Feb 03, 2009 10:42 pm

Code: Select all
For i = 1 To WindowObject.Variables.Count
Action.WriteINI filename+".save",2,i,WindowObject.Variables.Item(i).Name
Action.WriteINI filename+".save",3,i,WindowObject.Variables.Item(i).Value
Next
For i = 1 To WindowObject.VariablesVariant.Count
Action.WriteINI filename+".save",4,i,WindowObject.VariablesVariant.Item(i).Name
Action.WriteINI filename+".save",5,i,WindowObject.VariablesVariant.Item(i).Value
Next


This is the new code I use for storing variables instead of manually adding their names
User avatar
Lyberodoggy
Administrator
 
Posts: 2526
Joined: Sat Feb 17, 2007 3:31 pm
Location: Athens

Postby Imari » Wed Feb 04, 2009 1:32 am

Hi Lyberodoggy,
What you have here has really been useful. (There is no light bulb yet, but there are a couple of sparks coming from the socket on top my head, thanks to you, Lyberodoggy. :wink: )

I realized that if I moved from the Menu frame to a Save/Load frame that simply setting my Resume Game hotspot (on the Menu frame) to "go back to the last visited frame" would no longer work. So I did the following --

On the Advanced tab of my "Resume Game" hotspot, I put -
Code: Select all
Action.GoToFrame Action.ReadINI(filename+".room",1,1)


and on the "Menu" hotspot that I have on each frame, I set the hotspot to go to the menu frame and on the Advanced tab I put -
Code: Select all
frametosave = Action.GetCurrentFrameName
Action.WriteINI filename+".room",1,1,frametosave


It seems to work.

I have a question before I move onto my larger problem (how to set up the actual Save/Load frame). Can I write more than one INI so long as the extention is changed? I've named this first INI *.room and I'm planning to name the others *.save as you did.

Thanks.
User avatar
Imari
VIP
 
Posts: 872
Joined: Fri Jun 20, 2003 4:49 pm
Location: Virginia, USA

Postby Lyberodoggy » Wed Feb 04, 2009 2:08 pm

Yes you can do that...

It's great to see someone actually fitting the code to their game instead of the opposite :wink:
User avatar
Lyberodoggy
Administrator
 
Posts: 2526
Joined: Sat Feb 17, 2007 3:31 pm
Location: Athens

Postby Imari » Wed Feb 04, 2009 4:52 pm

I've moved onto the next step, which I hope to tackle this weekend. (I got side tracked last night trying to make fireflies with Shadowhunter's Particle+ . :P ) If you don't mind, I'm going to think out loud here....

My current plan of attack is to make a thumbnail for each general area to be used as a button on my "portal" device. The Portal Device hotspot is on every page (once you achieve it) and takes you to a separate Portal frame. After each area in the game is entered, the corresponding variable for the hotspot on the portal becomes "1" and you can then "travel" via the device back to the area.... it beats walking, right? :wink: The device will just take you to the area, though --- maybe outside the door of the building or on a nearby street. There is no saving or loading involved.

For the save/load function, I plan to make a thumbnail for each "room" and to associate it with the corresponding frame. For instance, in an office, I might have three or four frames, but only one thumbnail to represent the "room".

So.... someplace (on the rest of the lines in that INI file *.room maybe?).... I need to have something like ---

Code: Select all
If frametosave = FrameName "Office.jpg"
then thumbnail = Action."Thumb_Office.jpg"
End if


and then on the Save hotspot of my Save/Load frame, I would put some code like this for every frame in the game ---

Code: Select all
If frametosave = FrameName "Office.jpg"
Action.LoadAPicture  Hotspot(#) thumbnail


In addition to figuring out how to do the above, I will also have to figure out how to make the thumbnail load into the "next" available hotspot on the Save/Load frame. Um.... and then have it add in your code for the actual saving/INI writing of the game's inventory, variables, location, etc. in that *.save file. :shock:

If I can get that far, then surely clicking the hotspot to load the game should be "easy".... :roll:
User avatar
Imari
VIP
 
Posts: 872
Joined: Fri Jun 20, 2003 4:49 pm
Location: Virginia, USA

Postby Lyberodoggy » Wed Feb 04, 2009 9:18 pm

Carefull there... The extention isn't included in the frame name...
it's "Office" instead of "Office.jpg"
User avatar
Lyberodoggy
Administrator
 
Posts: 2526
Joined: Sat Feb 17, 2007 3:31 pm
Location: Athens

Postby Imari » Wed Feb 04, 2009 10:19 pm

Thanks. :P
User avatar
Imari
VIP
 
Posts: 872
Joined: Fri Jun 20, 2003 4:49 pm
Location: Virginia, USA

Postby Imari » Sat Feb 07, 2009 5:56 pm

Okay, I'm stiill fighting with this.... If I name all of my thumbnails "Thumb_" plus the name of the corresponding frame, can I use something like this for all instances -

Code: Select all
If frametosave = FrameName ""
then thumbnail = "Thumb_" FrameName
End if


instead of associating each of the frames with their thumbnails like this? -
Code: Select all
If frametosave = FrameName "GovOff"
then thumbnail = Action."Thumb_GovOff" 
End if

If frametosave = FrameName "Garden"
then thumbnail = Action."Thumb_Garden" 
End if

If frametosave = FrameName "Kitchen"
then thumbnail = Action."Thumb_Kitchen" 
End if

Also do I need to supply an "else" ?

Thanks.
User avatar
Imari
VIP
 
Posts: 872
Joined: Fri Jun 20, 2003 4:49 pm
Location: Virginia, USA

Postby Lyberodoggy » Sat Feb 07, 2009 10:40 pm

first of all if Framename is a variable then your code is alright, else you have to enclose it between double quotes

If you want to add a string to another, you must type varname+"string", instead of varname "string" you are using
User avatar
Lyberodoggy
Administrator
 
Posts: 2526
Joined: Sat Feb 17, 2007 3:31 pm
Location: Athens

Postby Imari » Sun Feb 08, 2009 9:13 pm

Thanks for the reply, Lyberodoggy. I'll keep working on it.
User avatar
Imari
VIP
 
Posts: 872
Joined: Fri Jun 20, 2003 4:49 pm
Location: Virginia, USA

Postby Imari » Mon Feb 16, 2009 7:56 am

Lyberodoggy, I'm totally stumped....

On each frame of the game that can be saved from, I've made a Menu button that returns the player to the Main Menu page and that has this code in the Advanced tab of the hotspot -

Code: Select all
frametosave = Action.GetCurrentFrameName
Action.WriteINI filename+".room",1,1,frametosave


On the Main Menu frame, I've been trying to add code to the Save hotspot, but I just don't know how.
I want to.... (warning.... seriously broken code follows) -
Code: Select all
'go to the save-load page
   Action.GoToFrame "Save-Load",1,1

'read the INI file to determine the frame to save from
   Action.ReadINI(filename+".room",1,1)

'add something like this for each frame in the game (maybe this should be global?)
   If frametosave = "Scene1"
   then framethumbnail = "Th_Sc1"
   If frametosave = "Scene2"
   then framethumbnail = "Th_Sc2"
   If frametosave = "Scene3"
   then framethumbnail = "Th_Sc3"
   If frametosave = "Scene4"
   then framethumbnail = "Th_Sc4"
   If frametosave = "Scene5"
   then framethumbnail = "Th_Sc5"
'[etc. etc.]

'using the above info, load the proper thumbnail onto the NEXT hotspot on the save-load frame.
'I think that I need a counter in here somewhere....

Action.LoadGraphicFile Hotspot(+1) framethumbnail
'or
Action.LoadAPicture Hotspot(+1), framethumbnail

'Then, use your code to get the names of the inventory items and store them
I=0
For Each X in InventoryItemObject
I=I+1
A=X.tag

'write this to the new *.save INI file.
Action.WriteINI filename+".save",1,I,A
Next

'take the status of the variables 
For i = 1 To WindowObject.Variables.Count
Action.WriteINI filename+".save",2,i,WindowObject.Variables.Item(i).Name
Action.WriteINI filename+".save",3,i,WindowObject.Variables.Item(i).Value
Next
For i = 1 To WindowObject.VariablesVariant.Count
Action.WriteINI filename+".save",4,i,WindowObject.VariablesVariant.Item(i).Name
Action.WriteINI filename+".save",5,i,WindowObject.VariablesVariant.Item(i).Value
Next

'save the frametosave in the *.save file
Action.WriteINI filename+".save",6,1,frametosave


I'm not sure what happens if the frametosave is the same frame that a previous saved game used. Maybe I need a counter for th at too?

Finally, I need to add the code to reload the game by clicking teach thumbnail/hotspot to call the corresponding filename.save file.

Is what I'm trying to do just impossible?
User avatar
Imari
VIP
 
Posts: 872
Joined: Fri Jun 20, 2003 4:49 pm
Location: Virginia, USA

Postby Lyberodoggy » Mon Feb 16, 2009 2:50 pm

No, it should work...

Follows somewhat fixed code:

Code: Select all
'go to the save-load page
   Action.GoToFrame "Save-Load",1,1

'read the INI file to determine the frame to save from
'##here you DO need a variable to save the value to
   frametosave=Action.ReadINI(filename+".room",1,1)

'add something like this for each frame in the game (maybe this should be global?)
'## here you should redo your ifs, because "then" needs to be in the same line with "if"
   If frametosave = "Scene1" then framethumbnail = "Th_Sc1"
   If frametosave = "Scene2" then framethumbnail = "Th_Sc2"
   If frametosave = "Scene3" then framethumbnail = "Th_Sc3"
   If frametosave = "Scene4" then framethumbnail = "Th_Sc4"
   If frametosave = "Scene5" then framethumbnail = "Th_Sc5"
'[etc. etc.]
'## You could also name your thumbnails in a template like framenamethumbnail, then use this code
framethumbnail=frametosave+"thumb.jpeg" 'change jpeg but DO include an extention

'using the above info, load the proper thumbnail onto the NEXT hotspot on the save-load frame.
'I think that I need a counter in here somewhere....

Action.LoadGraphicFile Hotspot(+1) framethumbnail
'## definitely not
'or
'##this one will do... I don't understand your +1, just leave it 1 if the hotspot has that index
Action.LoadAPicture Hotspot(1), framethumbnail

'Then, use your code to get the names of the inventory items and store them
'## this code worked previously, so there's no need to review it
I=0
For Each X in InventoryItemObject
I=I+1
A=X.tag

'write this to the new *.save INI file.
Action.WriteINI filename+".save",1,I,A
Next

'take the status of the variables
For i = 1 To WindowObject.Variables.Count
Action.WriteINI filename+".save",2,i,WindowObject.Variables.Item(i).Name
Action.WriteINI filename+".save",3,i,WindowObject.Variables.Item(i).Value
Next
For i = 1 To WindowObject.VariablesVariant.Count
Action.WriteINI filename+".save",4,i,WindowObject.VariablesVariant.Item(i).Name
Action.WriteINI filename+".save",5,i,WindowObject.VariablesVariant.Item(i).Value
Next

'save the frametosave in the *.save file
Action.WriteINI filename+".save",6,1,frametosave
User avatar
Lyberodoggy
Administrator
 
Posts: 2526
Joined: Sat Feb 17, 2007 3:31 pm
Location: Athens

Postby Imari » Mon Feb 16, 2009 5:38 pm

:D

That worked, Lyberodoggy! Thank you, thank you. I struggled with that for two days. Finally, I put the gotto frame command on the Save hotspot of the Menu frame and added the rest of your code onto the Save-Load frame's Advanced tab. One step closer to the goal. I does add the hotspot to hotspot #1 and it does create the save file.

I had to add the JPG extension to the thumbnails, because I kept getting an error message that they did not exist in the Areas folder.
Code: Select all
If frametosave = "Scene1" then framethumbnail = "Th_Sc1.jpg"

I'm not sure why I was getting this message as the thumbnail files were definitely there. I guess that I'll need to store them in the External folder as well.

Now to make it add a hotspot to the NEXT hotspot on the page when subsequent games are saved and to load the game again when the hotspot is clicked.
User avatar
Imari
VIP
 
Posts: 872
Joined: Fri Jun 20, 2003 4:49 pm
Location: Virginia, USA

Postby Imari » Tue Feb 17, 2009 7:37 pm

Still working... :P But a question for Lyberodoggy, please.

Does this code on the SAVE "OKAY" button
Code: Select all
 
If TextBoxObject(1).Text<>"" then
filename=TextBoxObject.Text

I=0
For Each X in InventoryItemObject
I=I+1
A=X.tag

Action.WriteINI filename+".save",1,I,A
Next

For i = 1 To WindowObject.Variables.Count
Action.WriteINI filename+".save",2,i,WindowObject.Variables.Item(i).Name
Action.WriteINI filename+".save",3,i,WindowObject.Variables.Item(i).Value
Next
For i = 1 To WindowObject.VariablesVariant.Count
Action.WriteINI filename+".save",4,i,WindowObject.VariablesVariant.Item(i).Name
Action.WriteINI filename+".save",5,i,WindowObject.VariablesVariant.Item(i).Value
Next

Action.WriteINI filename+".save",6,1,frametosave


...match up with the code on the LOAD OKAY button?
Code: Select all
filename=TextBoxObject(2).Text
For I=2 to 50
savedinventoryitem=Action.ReadINI(filename+".save",1,I)
If HasItem(cstr(savedinventoryitem))=False Then
Action.AddItem cstr(savedinventoryitem)
End If
Next
 
lampon=ConvertToNumber(Action.ReadINI(filename+".save",3,1))
Action.GoToFrame cstr(Action.ReadINI(filename+".save",6,1))
UnloadControl TextBoxObject(2)


I'm guessing that this line with the "lampon" variable no longer pertains and that I need different lines to retreive the information for the variables.
Code: Select all
lampon=ConvertToNumber(Action.ReadINI(filename+".save",3,1))


Sorry to be so much trouble.
User avatar
Imari
VIP
 
Posts: 872
Joined: Fri Jun 20, 2003 4:49 pm
Location: Virginia, USA

Postby Lyberodoggy » Tue Feb 17, 2009 10:01 pm

No problem ;)


Modify the save code in this section
Code: Select all
For Each X in InventoryItemObject
I=I+1
A=X.tag

Action.WriteINI filename+".save",1,I,A
Next
Action.WriteINI filename+".save",7,1,I

This will save the Ubound for the items
Now use this code to load
Code: Select all
filename=TextBoxObject(2).Text
For O=1 to Action.ReadINI(filename+".save",7,1)
savedinventoryitem=Action.ReadINI(filename+".save",1,O)
If HasItem(cstr(savedinventoryitem))=False Then
Action.AddItem cstr(savedinventoryitem)
End If
Next
For i = 1 To WindowObject.Variables.Count
WindowObject.Variables.Item(i).Value=ConvertToNumber(Action.ReadINI(filename+".save",3,i))
Next
For i = 1 To WindowObject.VariablesVariant.Count
WindowObject.VariablesVariant.Item(i).Value=Action.ReadINI(filename+".save",5,i)
Next
Action.GoToFrame cstr(Action.ReadINI(filename+".save",6,1))
UnloadControl TextBoxObject(2)



This should be the easy way out, but in case you change your variables, the earlier saved games won't work properly. To solve that, instead of using a for loop from i to WindowObject.Variables.Count and since you have saved the variable names, you can get their reference using Set reference = Action.GetVariableReferenceFromName("name")
reference.Value=ReadINI... etc
User avatar
Lyberodoggy
Administrator
 
Posts: 2526
Joined: Sat Feb 17, 2007 3:31 pm
Location: Athens

Postby Imari » Wed Feb 18, 2009 1:14 am

Thanks, Lyberodoggy. I think that I've figure out how to do it by combining yout text box saves with my visual clues. The code doesn't work, yet, but I think the logic is correct.

I'll try to do this in a couple of posts...

1. Make a Main Menu Frame with add Save and Load Buttons and a Resume Game Button (hotspots)

2. Make a Save/Load Frame and add to it enough hotspots to accomodate the number of saved games that you'll allow in your game. Do this in an orderly sequence.

3. On each frame of the game that can be saved from, make a Menu button that returns the player to the Main Menu page and add this code to the Advanced tab of the hotspot -

Code: Select all
frametosave = Action.GetCurrentFrameName
Action.WriteINI filename+".room",1,1,frametosave


4. On the Main Menu frame on the Resume Game hotspot add this code -

Code: Select all
Action.GoToFrame Action.ReadINI(filename+".room",1,1),1,1


5. On the Main Menu Page have the Save and the Load hotspots take you to the Save/Load frame, which looks like this in the editor.

http://www.realmsforge.com/Screenshot3.jpg
User avatar
Imari
VIP
 
Posts: 872
Joined: Fri Jun 20, 2003 4:49 pm
Location: Virginia, USA

Postby Imari » Wed Feb 18, 2009 1:24 am

LOADING THE THUMBNAIL ONTO THE PROPER HOTSPOT

AM is politely asking for a "sub" in here. :roll:
____________________________________________________________

6. Make a thumbnail for each of the frames in your game from which the player can save. Add the thumbnails to the your Areas and your External folder. I made mine 160 x 90 pixels.

7. On the Advanced tab of the Save-Load frame, add this code

'read the INI file to determine the frame to save from
Code: Select all
frametosave=Action.ReadINI(filename+".room",1,1)


'match up your thumbnails with youtr frames
Code: Select all
   If frametosave = "Scene1" then framethumbnail = "Th_Sc1.jpg"
   If frametosave = "Scene2" then framethumbnail = "Th_Sc2.jpg"
   If frametosave = "Scene3" then framethumbnail = "Th_Sc3.jpg"
   If frametosave = "Scene4" then framethumbnail = "Th_Sc4.jpg"
   If frametosave = "Scene5" then framethumbnail = "Th_Sc5.jpg"

'[etc. etc.]

' Make 12 integer variables, one for each save slot and picture spot and call it SAVESPOT1 thru SAVESPOT12
Code: Select all
savespot1 = Hotspot(1)
savespot2 = Hotspot(2)
savespot3 = Hotspot(3)
savespot4 = Hotspot(4)
savespot5 = Hotspot(5)
savespot6 = Hotspot(6)
savespot7 = Hotspot(7)
savespot8 = Hotspot(8)
savespot9 = Hotspot(9)
savespot10 = Hotspot(10)
savespot11 = Hotspot(11)
savespot12 = Hotspot(12)


'make a "highlight" GIF a little bit latger than your thumbnails and with an invisible center the size of your thumbnails. Put one on each hotspot and make it invisible with a corresponding variable -
Code: Select all
highlight1=Hotspot(13)
highlight2=Hotspot(14)
highlight3=Hotspot(15)
highlight4=Hotspot(16)
highlight5=Hotspot(17)
highlight6=Hotspot(18)
highlight7=Hotspot(19)
highlight8=Hotspot(20)
highlight9=Hotspot(21)
highlight10=Hotspot(22)
highlight11=Hotspot(23)
highlight12=Hotspot(24)


'using the above info, load the proper thumbnail onto the NEXT hotspot on the save-load frame and highlight it
Code: Select all
If savespot1=0 then Action.LoadAPicture Hotspot(1), framethumbnail
savespot1=1
highlight1=1
end if

If savespot1=1 & savespot2=0 then Action.LoadAPicture Hotspot(2), framethumbnail
savespot2=1
highlight2=1
end if

If savespot2=1 & savespot3=0 then Action.LoadAPicture Hotspot(3), framethumbnail
savespot3=1
highlight3=1
end if

If savespot3=1 & savespot4=0 then Action.LoadAPicture Hotspot(4), framethumbnail
savespot4=1
highlight4=1
end if

If savespot4=1 & savespot5=0 then Action.LoadAPicture Hotspot(5), framethumbnail
savespot5=1
highlight5=1
end if

If savespot5=1 & savespot6=0 then Action.LoadAPicture Hotspot(6), framethumbnail
savespot6=1
highlight6=1
end if

If savespot6=1 & savespot7=0 then Action.LoadAPicture Hotspot(7), framethumbnail
savespot7=1
highlight7=1
end if

If savespot7=1 & savespot8=0 then Action.LoadAPicture Hotspot(8), framethumbnail
savespot8=1
highlight8=1
end if

If savespot8=1 & savespot9=0 then Action.LoadAPicture Hotspot(9), framethumbnail
savespot9=1
highlight9=1
end if

If savespot9=1 & savespot10=0 then Action.LoadAPicture Hotspot(10), framethumbnail
savespot10=1
highlight10=1
end if

If savespot10=1 & savespot11=0 then Action.LoadAPicture Hotspot(11), framethumbnail
savespot11=1
highlight11=1
end if

If savespot11=1 & savespot12=0 then Action.LoadAPicture Hotspot(12), framethumbnail
savespot12=1
highlight12=1
end if


'if you've reached the limit of saves, then a hotspot JPG that says "NoMoreSaves" controlled by a variable becomes visible
Code: Select all
If savespot11=1 & savespot12=1 then NoMoreSaves=0
end if


'make the SAVE OKAY and save NOT okay buttons invisible
Code: Select all
Hotspot(26).enabled=False
text(26).caption=""
Hotspot(27).enabled=False
text(27).caption=""


'Load Text Box 1 & 2 and Place them where you want them LoadControl
Code: Select all
TextBoxObject(1)
TextBoxObject(1).move 231,627,212,30
TextBoxObject(1).visible=False

LoadControl TextBoxObject(2)
TextBoxObject(2).move 533,627,212,30
TextBoxObject(2).visible=False
User avatar
Imari
VIP
 
Posts: 872
Joined: Fri Jun 20, 2003 4:49 pm
Location: Virginia, USA

Postby Imari » Wed Feb 18, 2009 1:38 am

SAVE A GAME
________________________________________________________

(EDIT: Don't do step 8 as it breaks the journal and room saving.
8. Make 2 variant variables - frametosave and filename
(I don't think that I need this anymore ---> lampon (an integer variable)
)

9. Add a "SAVE GAME" button on the Save-Load frame and add code on the Advance tab of the hotspot to cause a text box to pop-up. The TEXT ON THE "YES" and "NO" hotspots next to it become visible, but the "yes" and "No" spots for the Load text box are hidden.

Code: Select all
TextBoxObject(1).Visible = True

Hotspot(29).Enabled=False
text(29).caption=""

Hotspot(30).Enabled=False
text(30).caption=""

'unhide the Save OKay button and specifiy the text for it
Hotspot(26).enabled=True
Text(26).caption="YES"

'unhide the Save NOT OKay button and specifiy the text for it
Hotspot(27).enabled=True
Text(27).caption="NO"



10. SAVE "NO" BUTTON's hotspot ("Save this Game? No" button) on the save-load page and the following code to the Advance tab.

Code: Select all
'set all highlights to 0 and unload picture from savespot
If savespot1=1 & savespot2=0 then Action.LoadAPicture Hotspot(1), ""
savespot1=0
highlight1=0
end if

If savespot2=1 & savespot3=0 then Action.LoadAPicture Hotspot(2), ""
savespot2=0
highlight2=0
end if

If savespot3=1 & savespot4=0 then Action.LoadAPicture Hotspot(3), ""
savespot3=0
highlight3=0
end if

If savespot4=1 & savespot5=0 then Action.LoadAPicture Hotspot(4), ""
savespot4=0
highlight4=0
end if

If savespot6=1 & savespot6=0 then Action.LoadAPicture Hotspot(5), ""
savespot5=0
highlight5=0
end if

If savespot6=1 & savespot7=0 then Action.LoadAPicture Hotspot(6), ""
savespot6=0
highlight6=0
end if

If savespot7=1 & savespot8=0 then Action.LoadAPicture Hotspot(7), ""
savespot7=0
highlight7=0
end if

If savespot8=1 & savespot9=0 then Action.LoadAPicture Hotspot(8), ""
savespot8=0
highlight8=0
end if

If savespot9=1 & savespot10=0 then Action.LoadAPicture Hotspot(9), ""
savespot9=0
highlight9=0
end if

If savespot10=1 & savespot11=0 then Action.LoadAPicture Hotspot(10), ""
savespot10=0
highlight10=0
end if

If savespot11=1 & savespot12=0 then Action.LoadAPicture Hotspot(11), ""
savespot11=0
highlight11=0
end if

If savespot11=1 & savespot12=1 then Action.LoadAPicture Hotspot(12), "" 
savespot12=0
highlight12=0
end if

TextBoxObject(1).Text="Game Not Saved"
Action.CreateTimedEvent 4, "TextBoxObject(1).Visible = False", FALSE



11. On the Save "YES" hotspot add code to the Adv. tab, which actually saves the game when "Yes" is clicked.

Code: Select all
If TextBoxObject(1).Text<>"" then
filename=TextBoxObject.Text

'get the names of the inventory items and store them
I=0

For Each X in InventoryItemObject
I=I+1
A=X.tag
Action.WriteINI filename+".save",1,I,A
Next
Action.WriteINI filename+".save",7,1,I
Action.WriteINI filename+".save",1,I,A
Next

'take the status of the variables
For i = 1 To WindowObject.Variables.Count
Action.WriteINI filename+".save",2,i,WindowObject.Variables.Item(i).Name
Action.WriteINI filename+".save",3,i,WindowObject.Variables.Item(i).Value
Next
For i = 1 To WindowObject.VariablesVariant.Count
Action.WriteINI filename+".save",4,i,WindowObject.VariablesVariant.Item(i).Name
Action.WriteINI filename+".save",5,i,WindowObject.VariablesVariant.Item(i).Value
Next

'save the frametosave in the *.save file
Action.WriteINI filename+".save",6,1,frametosave

'write the filename text under the proper hotspot
'turn the highlight# to 0 again.
'I think that I need to specifiy font, size, and color here?

If savespot1=1 & savespot2=0 then Hotspot(34).enabled=True
Text(34).caption=filename
highlight1=0
end if

If savespot2=1 & savespot3=0 then Action.LoadAPicture Hotspot(2), ""
Hotspot(35).enabled=True
Text(35).caption=filename
highlight2=0
end if

If savespot3=1 & savespot4=0 then Action.LoadAPicture Hotspot(3), ""
Hotspot(36).enabled=True
Text(36).caption=filename
highlight3=0
end if

If savespot4=1 & savespot5=0 then Action.LoadAPicture Hotspot(4), ""
Hotspot(37).enabled=True
Text(37).caption=filename
highlight4=0
end if

If savespot6=1 & savespot6=0 then Action.LoadAPicture Hotspot(5), ""
Hotspot(38).enabled=True
Text(38).caption=filename
highlight5=0
end if

If savespot6=1 & savespot7=0 then Action.LoadAPicture Hotspot(6), ""
Hotspot(39).enabled=True
Text(39).caption=filename
highlight6=0
end if

If savespot7=1 & savespot8=0 then Action.LoadAPicture Hotspot(7), ""
Hotspot(40).enabled=True
Text(40).caption=filename
highlight7=0
end if

If savespot8=1 & savespot9=0 then Action.LoadAPicture Hotspot(8), ""
Hotspot(41).enabled=True
Text(41).caption=filename
highlight8=0
end if

If savespot9=1 & savespot10=0 then Action.LoadAPicture Hotspot(9), ""
Hotspot(42).enabled=True
Text(42).caption=filename
highlight9=0
end if

If savespot10=1 & savespot11=0 then Action.LoadAPicture Hotspot(10), ""
Hotspot(43).enabled=True
Text(43).caption=filename
highlight10=0
end if

If savespot11=1 & savespot12=0 then Action.LoadAPicture Hotspot(11), ""
Hotspot(44).enabled=True
Text(44).caption=filename
highlight11=0
end if

If savespot11=1 & savespot12=1 then Action.LoadAPicture Hotspot(12), "" 
Hotspot(45).enabled=True
Text(45).caption=filename
highlight12=0
end if

TextBoxObject(1).Text="Game Saved"
Action.CreateTimedEvent 4, "TextBoxObject(1).Visible = False", FALSE
Last edited by Imari on Wed Feb 18, 2009 7:55 pm, edited 1 time in total.
User avatar
Imari
VIP
 
Posts: 872
Joined: Fri Jun 20, 2003 4:49 pm
Location: Virginia, USA

Postby Imari » Wed Feb 18, 2009 1:50 am

LOADING A SAVED GAME
__________________________________________


12. By referencing the thumbnails and their captions of his saved game on the screen, the player knows what to type to LOAD GAME button. The LOAD GAME button loads text box2 and accompanying hotspts for "Yes and "No".

On the LOAD GAME hotspot's Adv. tab -
Code: Select all
[code]TextBoxObject(2).Visible = True

'HIDE THE SAVE "YES" and "NO" BUTTONS
Hotspot(26).Enabled=False
Text(26).caption=""
Hotspot(27).Enabled=False
Text(27).caption=""

'unHIDE THE LOAD "YES" and "NO" BUTTONs
Hotspot(29).Enabled=True
Text(29).caption="YES"
Hotspot(30).Enabled=True
Text(30).caption="NO"[/code]


13. On the LOAD "Yes" button's Adv tab to actually load the chosen game and take the player into the game frame

Code: Select all
filename=TextBoxObject(2).Text

For O=1 to Action.ReadINI(filename+".save",7,1)
savedinventoryitem=Action.ReadINI(filename+".save",1,O)
If HasItem(cstr(savedinventoryitem))=False Then
Action.AddItem cstr(savedinventoryitem)
End If
Next
For i = 1 To WindowObject.Variables.Count
WindowObject.Variables.Item(i).Value=ConvertToNumber(Action.ReadINI(filename+".save",3,i))
Next
For i = 1 To WindowObject.VariablesVariant.Count
WindowObject.VariablesVariant.Item(i).Value=Action.ReadINI(filename+".save",5,i)
Next
Action.GoToFrame cstr(Action.ReadINI(filename+".save",6,1))

UnloadControl TextBoxObject(2)
UnloadControl TextBoxObject(1)


14. On the LOAD "NO" button (Doesn't load a game), Adv tab -

Code: Select all
TextBoxObject(2).Text="Game Not Loaded"
Action.CreateTimedEvent 4, "TextBoxObject(2).Visible = False", FALSE


15. This needs to be Copy/pasted into the project's global Procedures -

Code: Select all
Function HasItem(ItemName)
 HasItem = False
 For Each X in InventoryItemObject
  If X.Tag = ItemName Then
   HasItem = True
  End If
 Next
End Function
User avatar
Imari
VIP
 
Posts: 872
Joined: Fri Jun 20, 2003 4:49 pm
Location: Virginia, USA

Next

Return to Post Your Own Tutorials

Who is online

Users browsing this forum: No registered users and 0 guests

cron