HeroEngine Forums
Welcome, Guest. Please login or Register for HeroCloud Account.

Author Topic: [Resolved] Question about Arrays  (Read 1493 times)

OblivionMMO

  • General Accounts
  • *
  • Posts: 37
  • Hey all, How do I....
    • View Profile
    • Oblivion Entertainment
[Resolved] Question about Arrays
« on: Feb 20, 13, 08:53:43 AM »

In our MUD, an array was simply defined in a header file, such as this:

int                     stats[5];

How would I do a similar definition in the DOM Editor for player statistics which I am coding onto the O_PlayerCharacter class?

« Last Edit: Feb 22, 13, 08:21:51 AM by HE-Cooper »
Logged
Joshua Clay - Owner
Oblivion Entertainment
http://oblivionent.com

AWW_boss

  • General Accounts
  • *
  • Posts: 846
  • gdfgd
    • View Profile
Re: Question about Arrays
« Reply #1 on: Feb 20, 13, 09:09:50 AM »

not at my dev machine now to confirm it, but try  array 5 of integer
Logged

HE-CHRISTOPHER

  • HeroEngine
  • *****
  • Posts: 424
    • View Profile
Re: Question about Arrays
« Reply #2 on: Feb 20, 13, 09:21:03 AM »

AWW_boss is correct.


Code: [Select]
array [num elements] of [type]

Like all DOM types, arrays can also be used in complex types (though, you should consider the size of the data).

Code: [Select]
list of array 5 of string
lookuplist indexed by string of array 5 of string
lookuplist indexed by string of array 5 of class foo


That said, I would not use an array personally.  Arrays are fixed size at definition time without a way to resize them, this makes later expansion problematic.  Additionally, array indexes are too much like magic numbers as far as I am concerned (e.g. expecting a developer to know that stats[4] = strength) making your code harder to maintain.

Like many of my suggestions, I like using specs to handle statistics just like almost all other forms of game data.  This makes your stats systems data driven rather than explicitly hard coded. 


If want a very simple mechanic for stats, then I would recommend something like:

Code: [Select]
enum STATISTICS values (STRENGTH, INTELLIGENCE, WISDOM...)
stats field of type - lookuplist indexed by enum STATISTICS of integer
// allowing easy to read lookups, not that you would need to copy it to a
//    local variable...since you could reference it directly
strength_value as integer = my_char.stats[STRENGTH]
« Last Edit: Feb 20, 13, 09:24:42 AM by HE-CHRISTOPHER »
Logged
Christopher Larsen
CTO
HeroEngine