-
Mar 8th, 2015, 12:47 PM
#1
Thread Starter
Member
[VB.Net]RPG Game Accounts
Hello, I am making a VB.Net RPG and I would like to set it up so there are Log-Ins, I want the program to read(write/edit) text from a Text file and interpret the text as Usable data by my program. What I need to know is how would I (First)create a Directory in my program from which I can place/retrieve said Text Files and (Second) Read the text so the program can interpret it / Write to the file to save character information / and Edit Text to modify stats and such and then Save the Text File.
I was hoping this was possible my using Resources.TextFile but apparently, those are meant to NOT be edited, which is good, because I dont want these said text files to be (easily at least) editable by outside sources, only by my programs Runtime Code
Thanks in Advance for any information!
-
Mar 8th, 2015, 10:19 PM
#2
Thread Starter
Member
Re: [VB.Net]RPG Game Accounts
Anybody? And Nevermind the Encrypt
-
Mar 9th, 2015, 05:49 AM
#3
Re: [VB.Net]RPG Game Accounts
It sounds like you're just after some pretty straight forward file handling. I'd suggest reading up on FileSystemObject which should provide everything you need.
The best argument against democracy is a five minute conversation with the average voter - Winston Churchill
Hadoop actually sounds more like the way they greet each other in Yorkshire - Inferrd
-
Mar 11th, 2015, 02:30 AM
#4
Thread Starter
Member
Re: [VB.Net]RPG Game Accounts
Originally Posted by FunkyDexter
It sounds like you're just after some pretty straight forward file handling. I'd suggest reading up on FileSystemObject which should provide everything you need.
Hey FunckyDexter, I'm not sure I want to go along with Updating Text Files anylonger and just implement a Database into my program. The Only problem with that is, I dont have Access, and I want a database with multiple tables to save space. And when ever I try to create a database and Tables inside VB.net, It won't let me edit/add rows to the table. So I'm stuck with an empty Table. Any Idea where I can get a FREE database program that allows for multiple Tables?
-
Mar 11th, 2015, 10:18 AM
#5
Re: [VB.Net]RPG Game Accounts
Why on earth would you want to use Access to handle saving databases? The beauty of game programming is saving the data in your own format based on the structure you created, save it as a binary file using whatever extention you want, and as an option since you don't really have to do it, you can also encrypt it and decrypt it. True game programmers never use database files that run in things like Access. That would almost would be as bad as making a game using pictureboxes and command buttons
-
Mar 11th, 2015, 11:29 AM
#6
Re: [VB.Net]RPG Game Accounts
I agree with Jacob Roman here. Why not create a class and then use the built in .NET binary serialization class? This will be simpler for you because:
- Classes help keep the code organized
- The serialization is already built for you
- Binary serialization with give you some encryption
-
Mar 11th, 2015, 12:11 PM
#7
Thread Starter
Member
Re: [VB.Net]RPG Game Accounts
Ok, so before I respond to this, let me set up for you what my text file looks like:
Code:
Username = Password :: Name: CharacterName $$ Race: CharacterRace $$ Class: CharacterClass $$ etc, etc.. ::EndofCharacter1:: ::EndofAccount::
And I was trying to use File.ReadAllText and File.WriteAllText to edit the lines by loading it into an Array, and splitting the aray into lines, editing the line, then butting them back together. But apparently I don't know how to do that because it won't work. I get an error stating that VB can't access the file because another program is using it.
I, too, agree with you guys. I don't want to use a database. I wan't to use a custom file, butI cant seem to get it to work. I'll look up this binary serialization stuff and see what I can do.
-
Mar 11th, 2015, 01:05 PM
#8
Re: [VB.Net]RPG Game Accounts
Here is a quick example that I worked up for you:
Code:
Imports System.Runtime.Serialization.Formatters.Binary
Imports System
Imports System.Runtime.Serialization.Formatters.Binary
Public Module Module1
Public Sub Main()
Console.WriteLine("Hello World")
End Sub
End Module
Public Class Character
Private _username As String
Public Property Username() As String
Get
Return _username
End Get
Set(ByVal value As String)
If _username <> value Then
_username = value
Me.OnUsernameChanged()
End If
End Set
End Property
Private _password As String
Public Property Password() As String
Get
Return _password
End Get
Set(ByVal value As String)
If _password <> value Then
_password = value
Me.OnPasswordChanged()
End If
End Set
End Property
Private _name As String
Public Property Name() As String
Get
Return _name
End Get
Set(ByVal value As String)
If _name <> value Then
_name = value
Me.OnNameChanged()
End If
End Set
End Property
Protected Overridable Sub OnUsernameChanged()
RaiseEvent UsernameChanged(Me, EventArgs.Empty)
End Sub
Protected Overridable Sub OnPasswordChanged()
RaiseEvent PasswordChanged(Me, EventArgs.Empty)
End Sub
Protected Overridable Sub OnNameChanged()
RaiseEvent NameChanged(Me, EventArgs.Empty)
End Sub
Public Event UsernameChanged(ByVal sender As Object, ByVal e As EventArgs)
Public Event PasswordChanged(ByVal sender As Object, ByVal e As EventArgs)
Public Event NameChanged(ByVal sender As Object, ByVal e As EventArgs)
Public Sub Save(ByVal path As String)
Using stream As IO.FileStream = IO.File.Create(path)
Dim formatter As BinaryFormatter = New BinaryFormatter()
formatter.Serialize(stream, Me)
End Using
End Sub
Public Function Restore(ByVal path As String) As Character
Dim loadedCharacter As Character = Nothing
Using stream As IO.FileStream = IO.File.OpenRead(path)
Dim formatter As BinaryFormatter = New BinaryFormatter()
loadedCharacter = DirectCast(formatter.Deserialize(stream), Character)
End Using
Return loadedCharacter
End Function
End Class
Obviously you would create more properties for race, class, and the etc's. I just didn't know what types those would be.
Last edited by dday9; Mar 16th, 2015 at 01:16 PM.
Reason: Fixed Indents in Code
-
Mar 16th, 2015, 12:47 PM
#9
Thread Starter
Member
Re: [VB.Net]RPG Game Accounts
Hey dday, thanks for that, but theres a small problem. I wouldn't consider my self "new" by anymeans, just a little.... rusty. I havn't worked with VB in over 2 years before I started this project, so most of the stuff I've learned is from videos and core knowledge and common snese lol. So with that said, would you be so kind as to explain what this does? It looks like it just updates whenever stats change, but how do I call that specific function(do this when UserNameChanged, or PasswordChanged, etc..)
Any help would be extremely appreciated. I've also decided to put this project off for a little bit to move to something a little less complicated. I'm making an 2d TopView zombie shooter. It's be kinda open-world with all kinds of weapons. NO CURRENCY! When the zombie apocolypse happens, do you really think people are going to be using Money? No.
-
Mar 16th, 2015, 01:08 PM
#10
Re: [VB.Net]RPG Game Accounts
Yeah, I'll breakdown just the Username property as all the others do exactly the same thing(only for their specific property). First let's start out with this chunk of code:
Code:
Private _username As String
Public Property Username() As String
Get
Return _username
End Get
Set(ByVal value As String)
If _username <> value Then
_username = value
Me.OnUsernameChanged()
End If
End Set
End Property
What it does is first declare a private variable named _username, this will be the object that we work with inside of the class. Next it declares a property named Username, this will be the object that we work with outside of the class.
Next we setup the Get/Set methods. The Get function is simple in that all that it does is return the value of the variable _username when somebody wants to get the value of the property Username outside of the class. If you really wanted to screw with somebody, return a different variable other than the one it's designed to represent! The Set sub seems a little bit complicated, but it's really not. Basically what it does is it checks if the _username variable is different then the value it's to be set to. If it is, then set the _username variable to the user desired value and call the OnUsernameChanged method. If it isn't, then don't do anything at all because the value really did not change.
Now let's move onto the OnUsernameChanged method and the UsernameChanged event:
Code:
Protected Overridable Sub OnUsernameChanged()
RaiseEvent UsernameChanged(Me, EventArgs.Empty)
End Sub
Public Event UsernameChanged(ByVal sender As Object, ByVal e As EventArgs)
The OnUsernameChanged method is protected and overridable meaning that it is accessible only from within it's own class or from a derived class as well as that a programmer override the method. Inside the sub all we do is raise the UsernameChanged event while passing the current class as the sender and pass empty event arguments.
The UsernameChanged event is used to be raised when the _username variable is changed. The parameters follow the normal standards of other events. Take a look at the following button click event:
Code:
Private Sub btnFoo_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnFoo.Click
End Sub
Notice how it passes the same exact handles? This means that we can actually handle both a button's click event as well as a Character's UsernameChanged event all in the same method:
Code:
Private Sub Anyname(ByVal sender As Object, ByVal e As EventArgs) Handles btnFoo.Click, characterFoo.UsernameChanged
End Sub
That is how the Properties and their Events work.
-
Mar 28th, 2015, 05:13 AM
#11
Thread Starter
Member
Re: [VB.Net]RPG Game Accounts
Thanks for that dday, I appreciate you taking the time to explain that
Now I have a very serious and heartbreaking problem. My laptop has been through hell and back and has acquired malware and adware. So I system restored it to factory settings, resulting in the complete destruction of my projects D': So I will begin anew with all this information you all have shared with me. Thanks alot and I'm sure I'll be back with more problems!
-
Mar 28th, 2015, 07:57 AM
#12
Re: [VB.Net]RPG Game Accounts
Also be sure you are using a graphical library such as DirectX so it has a more professional look.
If you need help with spell icons having that World of Warcraft "Cooldown" effect, take a look at my World of Warcraft Spell Cooldown effect in my signature, along with other sample DirectX applications to get a feel on how to get this badboy going. Who knows, maybe it'll end up looking like Bosskillers. Its the best RPG I've ever made considering that I literally made WoW in 2D.
-
Mar 28th, 2015, 02:32 PM
#13
Thread Starter
Member
Re: [VB.Net]RPG Game Accounts
Thanks, I'll keep that in mind. I dont know how to use DirectX, but im sure I can learn.
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
|