Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Different way to do stats
#1
I wanted to do stats differently then the default setup so here's what i came up with:

I created an enum for my stats:
Code:
Public Enum Stats
    Strength = 1
    Defense
    Speed
    Magic
    ' Make sure Stat_Count is below everything else
    Stat_Count
End Enum

In the PlayerRec: Setup our array of stats and delete the old stat variables
Code:
Stat(1 To Stats.Stat_Count - 1) As Long

Delete GetPlayerSTR, GetPlayerDEF, GetPlayerSpeed, GetPlayerMAGI and add the following
You pass in what stat you want and it returns it's value
Code:
Public Function GetPlayerStat(ByVal Index As Long, ByVal Stat As Stats) As Long
    GetPlayerStat = Player(Index).Char(Player(Index).CharNum).Stat(Stat)
End Function

Example of use:
Code:
GetPlayerStat(Index, Stats.Strength)

Delete SetPlayerSTR, SetPlayerDEF, SetPlayerSpeed, SetPlayerMAGI and add the following
You pass in what stat to set the value to.
Code:
Public Sub SetPlayerStat(ByVal Index As Long, ByVal Stat As Stats, ByVal Value As Long)
    Player(Index).Char(Player(Index).CharNum).Stat(Stat) = Value
End Sub

Example of use
Code:
Call SetPlayerStat(Index, Stats.Strength, GetPlayerStat(Index, Stats.Strength) + 1)

LoadPlayer:
Code:
For n = 1 To Stats.Stat_Count - 1
    Get #nFileNum, , Player(Index).Char(i).Stat(n)
Next n

SavePlayer:
Code:
For n = 1 To Stats.Stat_Count - 1
    Put #nFileNum, , Player(Index).Char(i).Stat(n)
Next n

ClearChar
Code:
For n = 1 To Stats.Stat_Count - 1
        Player(Index).Char(CharNum).Stat(n) = 0
    Next n

ClearPlayer
Code:
For n = 1 To Stats.Stat_Count - 1
            Player(Index).Char(i).Stat(n) = 0
        Next n


I figure with this new method it would be easier to add / remove stats for a game.

This can also be used in ClassRec and NpcRec.

Any thoughts / comments / questions ?
Reply
#2
A really nice way to do it Big Grin Could easily add new stats now and save on the amount of functions / subs.
Reply
#3
It's a very good programming practice. Should be added to every system in MS.
Reply
#4
If everyone likes it I'll talk with DFA and get it added to the next version of MSE2.3. Players, Npcs, and Classes would have this method.
Reply
#5
Classes > Enums.

Tongue
Quote:Robin:
Why aren't maps and shit loaded up in a dynamic array?
Jacob:
the 4 people that know how are lazy
Robin:
Who are those 4 people?
Jacob:
um
you, me, and 2 others?
Reply
#6
This same concept can be used for Equipment slots too.
Reply
#7
Dugor Wrote:This same concept can be used for Equipment slots too.

Tbh, I think it's a lot better to simply switch to classes >_>
Quote:Robin:
Why aren't maps and shit loaded up in a dynamic array?
Jacob:
the 4 people that know how are lazy
Robin:
Who are those 4 people?
Jacob:
um
you, me, and 2 others?
Reply
#8
I agree that it would be better to switch to classes but a lot of people won't take the time to do that.

*cough* me *cough*
Big Grin

But even with classes you could use Enums the same way.
Reply
#9
Robin Wrote:Classes > Enums.

Tongue

Not in VB6 they ain't. If you take away polymorphism, modularity (interfaces), and inheritance, you have a really shitty object.
Reply
#10
Spodi Wrote:
Robin Wrote:Classes > Enums.

Tongue

Not in VB6 they ain't. If you take away polymorphism, modularity (interfaces), and inheritance, you have a really shitty object.

But I can pretend to be using Java. It's fucking amazing!
Quote:Robin:
Why aren't maps and shit loaded up in a dynamic array?
Jacob:
the 4 people that know how are lazy
Robin:
Who are those 4 people?
Jacob:
um
you, me, and 2 others?
Reply
#11
You two spend too much time reading stuff up :\
Quote:Robin:
Why aren't maps and shit loaded up in a dynamic array?
Jacob:
the 4 people that know how are lazy
Robin:
Who are those 4 people?
Jacob:
um
you, me, and 2 others?
Reply
#12
I was trying to look for a way in vb6 and couldn't find anything. For Each only works on Collections and Arrays.
Reply
#13
Sorry guys, but this is where VB6 fails at classes - what is the point of creating an object you can essentially only have one instance of? Tongue

VB6 was so close, so so close to being a bloody brilliant little language but some immigrant at MS had the bright idea of implimenting OOP to the extent of it being useless >_>;

Edit: MS = Microsoft* xD
Reply
#14
Use LBound and UBound? But I think they only work on arrays, not enums.
Reply
#15
I would just stick with the Stat_Count in the enum. It's the easiest way to do it.
Reply
#16
Yeah that's what I would do...people are trying to make it more complicated than it needs to be Tongue
Reply
#17
Dave Wrote:Is there a function to get how many items are in an enum?

Nope. Most languages do not have this without some form of reflection / metacoding.

Also, Enums are, in most languages (I believe), a collection of constants. The only difference between:

Code:
enum X
   a = 1
   b = 2
   c = 3
end enum

and

Code:
X_a = 1
X_b = 2
X_c = 3

is the forced relation between the elements in the enum and the intellisense. That way, if you specify an enum (instead of the underlying value of an enum which is usually the system's word size), you can show that only the given constants should be used for the input value.
Reply
#18
I know in C# you can get the length of the enum with this:

Code:
enum Stats : byte
        {
            Strength = 1,
            Defense,
            Speed,
            Magic
        }

Code:
int Stat_Count = Enum.GetValues(typeof(Stats)).Length;

But that doesn't help us with vb6 :p
Reply
#19
Guys, do not complicate...
Code:
Enum x
    a = 0
    b
    c
    Count
End Enum

Count will have 3, that's it...
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)