Character Generator

ok they are loaded

Great. So, our class can now access the Text GameObjects to output its calculated values to, and now that we have those references as member variables we can access them anywhere within our class. We also have a method for each characteristic and a more generic method which is responsible for effectively rolling the dice.

Lets put it together;

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class RollStats : MonoBehaviour {

    public Text strength;
    public Text dexterity;
	public Text constitution;
	public Text intelligence;
	public Text wisdom;
	public Text charisma;

    private int DiceRoller()
    {
	    // TODO: remove the hard-coded "4"
        int[] results = Dice.Roll(Dice.DieType.D6, 4, Dice.SortOrder.Descending);

        int sumOfDiceRolls = 0;

		// TODO: remove the hard-coded "3"
        for (int i = 0; i < 3; i++)
        {
            sumOfDiceRolls += results[i];
        }

		return sumOfDiceRolls;
    }

    public void RollStrength()
    {
        strength.text = DiceRoller();
    }

    public void RollDexterity()
    {
        // intentionally left empty
    }

    public void RollConsititution()
    {
        // intentionally left empty
    }

    public void RollIntelligence()
    {
        // intentionally left empty
    }

    public void RollWisdom()
    {
        // intentionally left empty
    }

    public void RollCharisma()
    {
        // intentionally left empty
    }
}

I have updated the RollStrength method, you can see that it now sets the strength GameObject’s text property to the returned value from our DiceRoller method.

Update the script, run the game, text - you should see a value appear within the UI - Text GameObject for the strength characteristic.

Note: You may want to set the default text value (in the Inspector) for these UI-Text GameObjects to “0”, that way, they will appear as “0” before the button is clicked.

Assuming all is good and no errors occur, you can then update the other five characteristic methods in the same way.

i have a error cant convert int to string.

public void RollStrength()
{
    int strength = DiceRoller();

    strength.text = strength.ToString();
)

Give that a try :slight_smile:


public void RollStrength()
{
int strength = DiceRoller();
strength.text = strength.ToString();

}


text has the error now

oooh, my bad… we have just used a variable name twice for different data types… once at the top for the type of Text and the second as int.

Ok, lets try this;

 public void RollStrength()
    {
        strength.text = DiceRoller().ToString();
    }

that one worked and this dice roller is not nice with the stats lol

hehehe…

I am.going to have to call it a night for now, its 02:27 here, guessing you are probably the other side of the pond. Hopefully you should be able to get a value for each characteristic and have it displayed now, even if the numbers are not what you would like :slight_smile:

Yes i am and thank you so much for your help

You are very welcome. I hope some of this evening has been useful.

Next step would probably be to create an instance of your character, perhaps pick up tomorrow.

ok sounds great

1 Like

I was able to add Races to the Character Creation scrip this morning.


using UnityEngine;

public class CharacterCreator : MonoBehaviour
{
    private enum CharacterClass { Barbarian, Bard, Cleric, Druid, Fighter, Monk, Paladin, Ranger, Rogue, Sorcerer, Warlock, Wizard };

[Header("Class Type")]

[SerializeField]
[Tooltip("Select the class of character")]
private CharacterClass characterClass;

 private enum PlayerRace { Dwarf = 0, Elf, Gnome, Half_Elf, Half_Orc, Halfling, Human };
 [Header("Race Type")]

 [SerializeField]
 [Tooltip("Select the Race of character")]
  private  PlayerRace playerRace;
}
1 Like

Very nice, well done Michael.

I will have limited availability today as I am still having a lot of problems with my laptop and I urgently need to get it resolved. I will check in from time to time on my mobile.

Thank you. I hope you get it fixed. Right now im trying to add in modifiers for the stats ex: (Strength value - 10) / 2 is the formula

Thanks, me too. Just managed to stop the 100% disc usage, but that has taken the best part of two days!

Ref the modifiers, what are the rules for those? are they race specific or are they rolled?

they are used to add to your total rolls for saves, skill checks, armor class, chance to hit and base attack damage.
exp: if i have an 18 Str. i get a +4 to all attacks, damage and so on

i think i need to use get and set to get the stats and set to do the math is that right

get and set are typically used with properties.

Before deciding on an approach it would be good to understand the mechanics of the modifiers a little further. I do get the general idea, but it is the rules around them which may determine our approach.

You gave an example above with regards to the 18 strength so you get a +4 on attacks. Is that the rule? e.g. 18+ on strength and you get a +4, or are there multiple rules depending on the value?

Are there any negative modifiers, for example if you have low strength?

This is for the strength characteristic and you have mentioned attacks as the modifier, are there other relating to strength?

Presumably then there are also some for the other characteristics too?

Do you have any form of chart for this? A matrix etc.

We need to ensure we move forwards in small steps but at the same time be aware of ths bigger picture. So with modifiers you want to be able to maybe only actually put one or two in place now but maybe design the architecture to support all of them.

On a related note - does the race also influence these?

so the math if it is what ever the stat is say 18. (18 - 10 )/2 round down
if your stat is 10 you have a modifier of 0
yes there are negs if you stat is under 8 then you start to get neg modifiers


this is a screenshot from www.d20pfsrd.com pathfinders
the only way the race or any thing that would influence these is if it adds or takes away form the stats itself
exp: i roll an 18 for Str and im a human humans get a +2 to any one stat so if i want i can put it in Str to get a 20 my modifier would then go up to 5

Ok (chart is useful).

So, you mentioned attacks earlier, so presumably there are other types that these modifiers could be applied to?

Also - other than the example you just gave with regards to the +2 for being human (which I assume would be calculated at the beginning), are there any rules which may reduce a characteristic value (even if temporarily), which would then also reduce the modifier?

yes there are items that can lower stats, spells, abilities and level drains.

Privacy & Terms