Help with script.

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

public class statroll : MonoBehaviour {

    void Start() {

    for(int x = 0; x < 20; x++)
    {
        int str, agi, inte;
        int statroll = Random.Range(1,3);
        switch (statroll)
        {
        case 3:
            str++;
            break;
        case 2:
            agi++;
            break;
        case 1:
            inte++;
            break;
        default:
            Debug.LogError("Something went wrong, probbably with my Random.Range bounds!");
            x--;
            break;
        }

    }

}
}

It’s telling me that line 16 is using an unassigned local variable, when I clearly assigned it.

Try
int str=0, agi=0, inte=0;
This should resolve the error, but im not sure what your are going to do with them as they are local.

You declared by didn’t assign;

int str = 0, // ..etc
// or 
int str, agi, inte;
str = 0;

Thank you, what I’m trying to do is to make dice rolling button that randomizes your stats, so should strength, intelligence and agility be public variables, since I’m gonna use them in the future? I’m not sure.

They can be. You could have methods or properties that return and/or use their values, also.
It’s up to you how you build it.

Since this thread resolved your issue, maybe keep working on what you’re building and if you get stuck later or whatever, you can post a new thread :wink:

Alright, thanks!

I would start off by adding them as private, as you dont want them to be altered outside of the class, and then make them read only when needed, but as Enderkill9 said, thats a new thread :slight_smile: