![]() |
Different way to do stats - Printable Version +- Mirage Source (https://mirage-engine.uk/forums) +-- Forum: Mirage Source (Nostalgia) (https://mirage-engine.uk/forums/forumdisplay.php?fid=61) +--- Forum: Archive (2006-2011) (https://mirage-engine.uk/forums/forumdisplay.php?fid=18) +---- Forum: General (https://mirage-engine.uk/forums/forumdisplay.php?fid=17) +---- Thread: Different way to do stats (/showthread.php?tid=1925) |
Different way to do stats - Jacob - 15-07-2008 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 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 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) Example of use Code: Call SetPlayerStat(Index, Stats.Strength, GetPlayerStat(Index, Stats.Strength) + 1) LoadPlayer: Code: For n = 1 To Stats.Stat_Count - 1 SavePlayer: Code: For n = 1 To Stats.Stat_Count - 1 ClearChar Code: For n = 1 To Stats.Stat_Count - 1 ClearPlayer Code: For n = 1 To Stats.Stat_Count - 1 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 ? Re: Different way to do stats - GIAKEN - 15-07-2008 A really nice way to do it ![]() Re: Different way to do stats - Dragoons Master - 15-07-2008 It's a very good programming practice. Should be added to every system in MS. Re: Different way to do stats - Jacob - 15-07-2008 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. Re: Different way to do stats - Robin - 15-07-2008 Classes > Enums. ![]() Re: Different way to do stats - Jacob - 15-07-2008 This same concept can be used for Equipment slots too. Re: Different way to do stats - Robin - 15-07-2008 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 >_> Re: Different way to do stats - Jacob - 15-07-2008 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. Re: Different way to do stats - Spodi - 16-07-2008 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. Re: Different way to do stats - Robin - 16-07-2008 Spodi Wrote:Robin Wrote:Classes > Enums. But I can pretend to be using Java. It's fucking amazing! Re: Different way to do stats - Robin - 16-07-2008 You two spend too much time reading stuff up :\ Re: Different way to do stats - Jacob - 16-07-2008 I was trying to look for a way in vb6 and couldn't find anything. For Each only works on Collections and Arrays. Re: Different way to do stats - Coke - 16-07-2008 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 Re: Different way to do stats - GIAKEN - 16-07-2008 Use LBound and UBound? But I think they only work on arrays, not enums. Re: Different way to do stats - Jacob - 16-07-2008 I would just stick with the Stat_Count in the enum. It's the easiest way to do it. Re: Different way to do stats - GIAKEN - 16-07-2008 Yeah that's what I would do...people are trying to make it more complicated than it needs to be ![]() Re: Different way to do stats - Spodi - 16-07-2008 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 and Code: X_a = 1 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. Re: Different way to do stats - Jacob - 16-07-2008 I know in C# you can get the length of the enum with this: Code: enum Stats : byte Code: int Stat_Count = Enum.GetValues(typeof(Stats)).Length; But that doesn't help us with vb6 :p Re: Different way to do stats - Dragoons Master - 16-07-2008 Guys, do not complicate... Code: Enum x Count will have 3, that's it... |