|
-
Jul 5th, 2006, 10:10 AM
#1
Thread Starter
Junior Member
Saving Game
Hi,
Well, I have most of my game done, except I need to learn the following:
How to transfer variables from form to form
How to transfer variables to an outside source, like notepad, so it will save the information in the game.
Also, I would like to learn how to create a database, that will run from a server, so they could create an account, and login. But this is not a neccesity.
Thanks a ton, I know its pretty broad.
Shiz
-
Jul 5th, 2006, 10:30 AM
#2
Re: Saving Game
 Originally Posted by Shizzell
How to transfer variables from form to form
One way is to add a Module to your project, and declare the shared variable(s) in it (using Public), the variable(s) are then available from anywhere in your project.
How to transfer variables to an outside source, like notepad, so it will save the information in the game.
That's complex.. an easier option is to save a text file - see the Classic VB FAQ link below for examples & explanations.
Also, I would like to learn how to create a database, that will run from a server, so they could create an account, and login. But this is not a neccesity.
That's a whole new kettle of fish.. see the ADO Tutorial link below. (note that if you are using a database, you could use that to save the game instead of files).
-
Jul 5th, 2006, 10:40 AM
#3
Thread Starter
Junior Member
Re: Saving Game
Could you give me an example of the module with public?
-
Jul 5th, 2006, 10:44 AM
#4
Re: Saving Game
If you want 2 variables called "Fred" and "Joe" to be available to your forms, you would put this at the top of a module:
VB Code:
Public Fred as String, Joe as String
-
Jul 5th, 2006, 10:51 AM
#5
Thread Starter
Junior Member
Re: Saving Game
I know this is noobish, but i'ved never written a module, how does it work?
-
Jul 5th, 2006, 11:38 AM
#6
Addicted Member
Re: Saving Game
 Originally Posted by Shizzell
I know this is noobish, but i'ved never written a module, how does it work?
Rich click on the project explorer, Add->Module. Then bung Si's code into it. The project explorer is were all your forms are listed.
As for saving the game vars
http://www.vbforums.com/showpost.php...75&postcount=7
Rich
A)bort, R)etry, I)nfluence with large hammer.
Please take a moment to rate useful posts.

-
Jul 5th, 2006, 11:40 AM
#7
Thread Starter
Junior Member
Re: Saving Game
Dude, nice. That helps alot. Thanks bro.
But where do i put my variables?
-
Jul 5th, 2006, 11:46 AM
#8
Addicted Member
Re: Saving Game
Just write them in at the top and declare them as public.
Code:
Public gamevariable1 as integer, HighScore as long
Rich
A)bort, R)etry, I)nfluence with large hammer.
Please take a moment to rate useful posts.

-
Jul 5th, 2006, 12:14 PM
#9
Thread Starter
Junior Member
Re: Saving Game
Just write them in at the top and declare them as public.
Code:
Public gamevariable1 as integer, HighScore as long
No, I mean in the saving the game, where in that code do I put my information?
And I simply don't get the code to save, and get. What must I do completely? And do I put that under a command button?
??
Last edited by Shizzell; Jul 5th, 2006 at 12:19 PM.
-
Jul 5th, 2006, 12:41 PM
#10
Addicted Member
Re: Saving Game
 Originally Posted by Shizzell
No, I mean in the saving the game, where in that code do I put my information?
And I simply don't get the code to save, and get. What must I do completely? And do I put that under a command button?
??
Ah i see
yes command buttons
VB Code:
'the varibales in the following udt should be replaced with you setting variables, for example. Play position, high score.....
Private Type MyType
setting1 as integer
setting2 as string * 10
setting3 as byte
End Type
'command button save
Dim settings As MyType
Open "C:\settings.set" For Binary Access Write As #1
Put #1, , settings
Close #1
'command button load
Dim settings As MyType
Open "C:\settings.set" For Binary Access Read As #1
Get #1, , settings
Close #1
'assign the values of the type to the game variables.
var1 = settings.setting1
Rich
A)bort, R)etry, I)nfluence with large hammer.
Please take a moment to rate useful posts.

-
Jul 5th, 2006, 12:47 PM
#11
Thread Starter
Junior Member
Re: Saving Game
Could you give me an example? I think I'm catching on though.
-
Jul 5th, 2006, 01:27 PM
#12
Thread Starter
Junior Member
Re: Saving Game
Ok, I got it to work kinda. Code:
VB Code:
Option Explicit
Dim wow2 As String
Private Type MyType
setting1 As Integer
setting2 As String * 10
setting3 As Byte
End Type
Private Sub Command2_Click()
Dim settings As MyType
Open "C:\settings.txt" For Binary Access Write As #1
Put #1, , label1.Caption
Close #1
End Sub
Private Sub Command3_Click()
Dim settings As MyType
Open "C:\settings.txt" For Binary Access Read As #1
Get #1, , settings
Close #1
wow2 = settings.setting2
Label3.Caption = wow2
End Sub
Private Sub Form_Load()
Label1.caption = "Helloooooo"
End Sub
And when I click the load command button (Command2) It gives me the following in label3: lloooooo
I need some help =/
Thanks guys
Last edited by Shizzell; Jul 5th, 2006 at 01:47 PM.
-
Jul 5th, 2006, 04:07 PM
#13
Addicted Member
Re: Saving Game
almost correct
VB Code:
Option Explicit
Private Type MyType
setting1 As Integer
setting2 As String * 10
setting3 As Byte
End Type
Private Sub Command1_Click()
Dim settings As MyType
'assign your caption to setting2 first.
settings.setting2 = Label1.Caption
Open "C:\settings.txt" For Binary Access Write As #1
Put #1, , settings
Close #1
End Sub
Private Sub Command2_Click()
Dim settings As MyType
Open "C:\settings.txt" For Binary Access Read As #1
Get #1, , settings
Close #1
Label2.Caption = settings.setting2
End Sub
Private Sub Form_Load()
Label1.Caption = "Helloooooo"
End Sub
Of course you can have as many variables of different types in the UDT. Just to note ive changed it to command1 and command2 and label 1 and 2.
Last edited by Rich2189; Jul 5th, 2006 at 04:15 PM.
Rich
A)bort, R)etry, I)nfluence with large hammer.
Please take a moment to rate useful posts.

Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|