Skip to main content

News

Topic: A Character Creation Model from my RPG (Read 3349 times) previous topic - next topic

0 Members and 1 Guest are viewing this topic.
A Character Creation Model from my RPG
I've been developing a Character Creation Model (attached). The code does function properly. It is just the this.CharClass seems a little too if heavy. The attached code only has 4 Character Classes defined in it (early version). Overall there are 15 different classes. 7 different types of spellcasters alone. If i were to add all 15 classes the way it is now that would be a huge chunk of if statements. Might anybody have some suggestions on a way to simplify this without having to use so many if statements?
"I am to misbehave." - Malcom Renyolds, Captain of Serenity

  • Rhuan
  • [*][*][*][*]
Re: A Character Creation Model from my RPG
Reply #1
There are several ways you could rejig this.

The simplest way I can think of would be to make a global object to hold all of your class base values:

Code: [Select]
var class_bases = {};
class_bases.Fighter = {Str:20, Dex:20, Con:18, Int:15, Wis:15, Chrm:16};
class_bases.Thief = {Str:16, Dex:20, Con:18, Int:18, Wis:16, Chrm:20};
class_bases.WhiteMage = {Str:20, Dex:20, Con:18, Int:15, Wis:15, Chrm:16};
class_bases.BlackMage = {Str:15, Dex:13, Con:18, Int:20, Wis:20, Chrm:14};

Then you could reference into it as follows:

Code: [Select]
//in the place of all of the if/else statements:
this.Str = InitVal(class_bases[this.CharClass].Str);
this.Dex = InitVal(class_bases[this.CharClass].Dex);
this.Con = InitVal(class_bases[this.CharClass].Con);
this.Int = InitVal(class_bases[this.CharClass].Int);
this.Wis = InitVal(class_bases[this.CharClass].Wis);
this.Chrm = InitVal(class_bases[this.CharClass].Chrm);

Re: A Character Creation Model from my RPG
Reply #2
Thank you, that was a tremendous help and emilinated the need for all those if statements.
"I am to misbehave." - Malcom Renyolds, Captain of Serenity