Mirage Source http://web.miragesource.net/forums/ |
|
Different way to do stats http://web.miragesource.net/forums/viewtopic.php?f=201&t=3988 |
Page 1 of 11 |
Author: | Jacob [ Tue Jul 15, 2008 6:59 pm ] |
Post subject: | Different way to do stats |
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 ? |
Author: | GIAKEN [ Tue Jul 15, 2008 7:09 pm ] |
Post subject: | Re: Different way to do stats |
A really nice way to do it Could easily add new stats now and save on the amount of functions / subs. |
Author: | Dragoons Master [ Tue Jul 15, 2008 7:13 pm ] |
Post subject: | Re: Different way to do stats |
It's a very good programming practice. Should be added to every system in MS. |
Author: | Jacob [ Tue Jul 15, 2008 7:14 pm ] |
Post subject: | Re: Different way to do stats |
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. |
Author: | Robin [ Tue Jul 15, 2008 7:19 pm ] |
Post subject: | Re: Different way to do stats |
Classes > Enums. |
Author: | Lea [ Tue Jul 15, 2008 7:22 pm ] |
Post subject: | Re: Different way to do stats |
Robin wrote: Classes > Enums.
|
Author: | Jacob [ Tue Jul 15, 2008 9:39 pm ] |
Post subject: | Re: Different way to do stats |
This same concept can be used for Equipment slots too. |
Author: | Robin [ Tue Jul 15, 2008 9:42 pm ] |
Post subject: | Re: Different way to do stats |
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 >_> |
Author: | Jacob [ Tue Jul 15, 2008 10:30 pm ] |
Post subject: | Re: Different way to do stats |
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* But even with classes you could use Enums the same way. |
Author: | Spodi [ Wed Jul 16, 2008 12:23 am ] |
Post subject: | Re: Different way to do stats |
Robin wrote: Classes > Enums. Not in VB6 they ain't. If you take away polymorphism, modularity (interfaces), and inheritance, you have a really shitty object. |
Author: | Robin [ Wed Jul 16, 2008 12:31 am ] |
Post subject: | Re: Different way to do stats |
Spodi wrote: Robin wrote: Classes > Enums. 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! |
Author: | Robin [ Wed Jul 16, 2008 12:59 pm ] |
Post subject: | Re: Different way to do stats |
You two spend too much time reading stuff up :\ |
Author: | Lea [ Wed Jul 16, 2008 4:18 pm ] |
Post subject: | Re: Different way to do stats |
Is there a function to get how many items are in an enum? |
Author: | Jacob [ Wed Jul 16, 2008 4:27 pm ] |
Post subject: | Re: Different way to do stats |
I was trying to look for a way in vb6 and couldn't find anything. For Each only works on Collections and Arrays. |
Author: | Coke [ Wed Jul 16, 2008 4:32 pm ] |
Post subject: | Re: Different way to do stats |
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? 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 |
Author: | GIAKEN [ Wed Jul 16, 2008 6:45 pm ] |
Post subject: | Re: Different way to do stats |
Use LBound and UBound? But I think they only work on arrays, not enums. |
Author: | Jacob [ Wed Jul 16, 2008 6:49 pm ] |
Post subject: | Re: Different way to do stats |
I would just stick with the Stat_Count in the enum. It's the easiest way to do it. |
Author: | GIAKEN [ Wed Jul 16, 2008 6:56 pm ] |
Post subject: | Re: Different way to do stats |
Yeah that's what I would do...people are trying to make it more complicated than it needs to be |
Author: | Spodi [ Wed Jul 16, 2008 7:01 pm ] |
Post subject: | Re: Different way to do stats |
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. |
Author: | Jacob [ Wed Jul 16, 2008 7:08 pm ] |
Post subject: | Re: Different way to do stats |
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 |
Author: | Dragoons Master [ Wed Jul 16, 2008 8:46 pm ] |
Post subject: | Re: Different way to do stats |
Guys, do not complicate... Code: Enum x a = 0 b c Count End Enum Count will have 3, that's it... |
Page 1 of 11 | All times are UTC |
Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |