Calculating exp growth with scriptableobject not working?

Hey everyone, hoping for some help on using a function to calculate exp using an array.

I have these two scripts:

using System.Collections;
using System.Collections.Generic;
using UnityEditor.Experimental;
using UnityEngine;

[CreateAssetMenu(fileName = "New Job", menuName = "ScriptableObjects/Job")]
public class CharacterJobs_SO : ScriptableObject
{
    public new string name = "Job Name";

    public int currentLevel = 1;

    public int maxLevel = 99;

    private int currentExp = 0;

    public int[] expNext;

    public float growthRate;

    public int baseExp;
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class TestJobCall : MonoBehaviour
{

    public CharacterJobs_SO job;
    // Start is called before the first frame update
    void Awake()
    {


        job.expNext = new int[job.maxLevel];
        job.expNext[1] = job.baseExp;

        for (int i = 2; i < job.expNext.Length; i++)
        {
            job.expNext[i] = Mathf.FloorToInt(job.expNext[i - 1] * 1.3f);
        }

        Debug.Log("My class is " + job.name + " and my growth modifier to level up is " + job.growthRate + ", which means to reach level 3 I need " + job.expNext[3] + ".");
    }

}

One is the ScriptableObject that holds information for a job, and the ability to add in a growthRate for the exp needed for each level, which the test script then calculates and creates values for on start (at least that’s the idea).

However, when I run the function in the test script, the answer keeps coming up 0. Can anyone explain where I’ve gone wrong?

What is value of baseExp in ScriptableObject?
Because with this formula
Mathf.FloorToInt(job.expNext[i - 1] * 1.3f)
4 is minimum required value for first element (second in your case since you skipped first) to increase next value.
With anything below 4 all values will be equal each other.

I actually ended up solving this somehow…it wasn’t working and now it suddenly is. Not sure what changed.

But yes, the baseExp value was 100. I also made an error in this posting of the script in that the 1.3f in the formula is supposed to be job.growthRate so that it can be set in the Inspector.

Thank you for replying though! :slight_smile: