Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Declaring Custom Variables/Properties

Declaring Custom Variables/Properties

Scheduled Pinned Locked Moved Visual Basic
game-devxmlhelp
6 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Codemonkey85
    wrote on last edited by
    #1

    Hiya all. I'm planning on making a program for a card game I have (Munchkin, if you wanna know). In creating this program, I was hoping to declare a Player type variable, if it's possible, and create my own properties like Level, Gender, and so on. Unfortunately, I have been unable to find a way to do this. If anyone can help me, or can think of another way to accomplish my goal (XML files might work, I dunno), I'd appreciate it. Thanks in advance. EDIT: In case my post wasn't clear enough, I want something like this: Dim plrMike as Player ... plrMike.Level = 1 plrMike.Gender = Male Signed, Mecha-Poobah of The Love Which Dare Not Speaketh Its Name, Codemonkey Jackson Title Generator - http://title.flywheel.org/

    J 1 Reply Last reply
    0
    • C Codemonkey85

      Hiya all. I'm planning on making a program for a card game I have (Munchkin, if you wanna know). In creating this program, I was hoping to declare a Player type variable, if it's possible, and create my own properties like Level, Gender, and so on. Unfortunately, I have been unable to find a way to do this. If anyone can help me, or can think of another way to accomplish my goal (XML files might work, I dunno), I'd appreciate it. Thanks in advance. EDIT: In case my post wasn't clear enough, I want something like this: Dim plrMike as Player ... plrMike.Level = 1 plrMike.Gender = Male Signed, Mecha-Poobah of The Love Which Dare Not Speaketh Its Name, Codemonkey Jackson Title Generator - http://title.flywheel.org/

      J Offline
      J Offline
      John Kuhn
      wrote on last edited by
      #2

      One of two things you could do: 1) Create a Class: Assuming VB.NET: You will create a new class library named Player.vb. Assuming VB6: You will create a new class library named Player.cls. 2) Create a type/structure: Assuming VB.NET: Create a structure definition using Structure...End Structure. Assuming VB6: Create a type using Type ... End Type What a piece of work is man, how noble in reason, how infinite in faculties, in form and moving how express and admirable . . . and yet to me, what is this quintessence of dust? -- Hamlet, Act II, Scene ii.

      C 1 Reply Last reply
      0
      • J John Kuhn

        One of two things you could do: 1) Create a Class: Assuming VB.NET: You will create a new class library named Player.vb. Assuming VB6: You will create a new class library named Player.cls. 2) Create a type/structure: Assuming VB.NET: Create a structure definition using Structure...End Structure. Assuming VB6: Create a type using Type ... End Type What a piece of work is man, how noble in reason, how infinite in faculties, in form and moving how express and admirable . . . and yet to me, what is this quintessence of dust? -- Hamlet, Act II, Scene ii.

        C Offline
        C Offline
        Codemonkey85
        wrote on last edited by
        #3

        Well, I went ahead and made a new class library (my new variable type ends up being Munchkin.Player.Character). I can do things now like assign "Male" to Character.Gender, but I can also do wacky things like Character.Gender = "Chicken". Another thing is that the maximum level is supposed to be ten, but I could make Character.Level whatever integer I want, even negatives. What do I do to limit what kinds of genders there are, or specify which ones do and don't work? As I sit here, I contemplate the last words of Socrates: "I drank what?".

        J 1 Reply Last reply
        0
        • C Codemonkey85

          Well, I went ahead and made a new class library (my new variable type ends up being Munchkin.Player.Character). I can do things now like assign "Male" to Character.Gender, but I can also do wacky things like Character.Gender = "Chicken". Another thing is that the maximum level is supposed to be ten, but I could make Character.Level whatever integer I want, even negatives. What do I do to limit what kinds of genders there are, or specify which ones do and don't work? As I sit here, I contemplate the last words of Socrates: "I drank what?".

          J Offline
          J Offline
          John Kuhn
          wrote on last edited by
          #4

          Well, you could do a couple of things. You could have an Enum in your project, like:

          Namespace Munchkin
          Public Enum Genders
          Male
          Female
          End Enum
          End Namespace

          Then, you could declare your Gender field like:

          Public Gender As Genders

          And the only valid thing to put in it would be:

          someCharacter.Gender = Genders.Male

          You could do the same thing with levels, or you could throw an exception if a character's level is set below 1 or above 10:

          Public Class Character
              Private \_level As Integer
              Public Property Level() As Integer
                  Get
                      Return \_level
                  End Get
                  Set(ByVal Value As Integer)
                      If Value < 1 Or Value > 10 Then
                          Throw New ApplicationException("Level must be between 1 and 10")
                      Else
                          \_level = Value
                      End If
                  End Set
              End Property
          End Class
          

          But guess what? Your Character is starting to sound more like a class than a structure... What a piece of work is man, how noble in reason, how infinite in faculties, in form and moving how express and admirable . . . and yet to me, what is this quintessence of dust? -- Hamlet, Act II, Scene ii.

          C 1 Reply Last reply
          0
          • J John Kuhn

            Well, you could do a couple of things. You could have an Enum in your project, like:

            Namespace Munchkin
            Public Enum Genders
            Male
            Female
            End Enum
            End Namespace

            Then, you could declare your Gender field like:

            Public Gender As Genders

            And the only valid thing to put in it would be:

            someCharacter.Gender = Genders.Male

            You could do the same thing with levels, or you could throw an exception if a character's level is set below 1 or above 10:

            Public Class Character
                Private \_level As Integer
                Public Property Level() As Integer
                    Get
                        Return \_level
                    End Get
                    Set(ByVal Value As Integer)
                        If Value < 1 Or Value > 10 Then
                            Throw New ApplicationException("Level must be between 1 and 10")
                        Else
                            \_level = Value
                        End If
                    End Set
                End Property
            End Class
            

            But guess what? Your Character is starting to sound more like a class than a structure... What a piece of work is man, how noble in reason, how infinite in faculties, in form and moving how express and admirable . . . and yet to me, what is this quintessence of dust? -- Hamlet, Act II, Scene ii.

            C Offline
            C Offline
            Codemonkey85
            wrote on last edited by
            #5

            >But guess what? Your Character is starting to sound more like a class than a structure... In that case, I must have misinterpreted your orginal advice; I had a project named Munchkin, a Class named Player, and a Structure named Character. It looked something like this: Structure Character Public Name As String Public Gender As String Public Level As Integer End Structure But I guess I should do the Class thing and the Structure thing seperately. Anyway, thanks for the help. I'm gonna try the Enum and Exception code now. As I sit here, I contemplate the last words of Socrates: "I drank what?".

            J 1 Reply Last reply
            0
            • C Codemonkey85

              >But guess what? Your Character is starting to sound more like a class than a structure... In that case, I must have misinterpreted your orginal advice; I had a project named Munchkin, a Class named Player, and a Structure named Character. It looked something like this: Structure Character Public Name As String Public Gender As String Public Level As Integer End Structure But I guess I should do the Class thing and the Structure thing seperately. Anyway, thanks for the help. I'm gonna try the Enum and Exception code now. As I sit here, I contemplate the last words of Socrates: "I drank what?".

              J Offline
              J Offline
              John Kuhn
              wrote on last edited by
              #6

              Although, on the other hand, you could produce a Class that acts like a Character factory. Anyway, glad I could lend a hand. What a piece of work is man, how noble in reason, how infinite in faculties, in form and moving how express and admirable . . . and yet to me, what is this quintessence of dust? -- Hamlet, Act II, Scene ii.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups