# Help with adjusting script.

**URL:** https://discussions.unity.com/t/help-with-adjusting-script/663193
**Category:** Scripting
**Tags:** Scripting
**Created:** [April 29, 2017, 7:03pm UTC](https://discussions.unity.com/t/help-with-adjusting-script/663193 "2017-04-29T19:03:38Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Enderkill9](https://avatars.discourse-cdn.com/v4/letter/e/ecccb3/32.png) [@Enderkill9](https://discussions.unity.com/u/Enderkill9)
#### Post date: [April 29, 2017, 7:03pm UTC](https://discussions.unity.com/t/help-with-adjusting-script/663193/1 "2017-04-29T19:03:38Z")

</div>

```csharp
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class statroll : MonoBehaviour {

    public void RandomizeStats() {

    for(int x = 0; x < 20; x++)
    {
        int str = 5, agi = 5, inte = 5;
        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;
        }
            Debug.Log("str=" + str + " :agi=" + agi + " :inte=" + inte);

    }

}
}

```

I know this is like the fifth thread I opened on this one annoying script, but I’m struggling with this.  
Thanks to the help of some posters in these forums, I’ve been able to assemble this code that somewhat works. The problem is that it’s not working the way I want it to. The code does change the numbers when I press a button but it only changes int and agi and doesnt change str at all, and I want the stats that were randomly generated to equal to 35 and so far it only only changes to either 5 or 6. I’ve already tried adjusting the values myself, but when I messed with the Random.range, it just crashed my program.

---

<div class="post-metadata">

### Author: ![methos5k](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/methos5k/32/387158_2.png) [@methos5k](https://discussions.unity.com/u/methos5k)
#### Post date: [April 29, 2017, 7:10pm UTC](https://discussions.unity.com/t/help-with-adjusting-script/663193/2 "2017-04-29T19:10:44Z")

</div>

The Random.Range is written incorrectly for your script. The Range in this situation would be 1 and 4.  
The variables are declared in the wrong spot. They should be outside of the function’s scope entirely (not to mention outside of the for loop).

---

<div class="post-metadata">

### Author: ![WarmedxMints\_1](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/warmedxmints_1/32/554395_2.png) [@WarmedxMints\_1](https://discussions.unity.com/u/WarmedxMints_1)
#### Post date: [April 29, 2017, 7:12pm UTC](https://discussions.unity.com/t/help-with-adjusting-script/663193/3 "2017-04-29T19:12:34Z")

</div>

From the docs;

public static int Range(int min, int max);

**Description**

Returns a random integer number between min [inclusive] and max [exclusive] (Read Only).

> **[Unity - Scripting API: Random.Range](https://docs.unity3d.com/ScriptReference/Random.Range.html)**

So you want Random.Range(1, 4);

You really should read the manual 😛

---

<div class="post-metadata">

### Author: ![Enderkill9](https://avatars.discourse-cdn.com/v4/letter/e/ecccb3/32.png) [@Enderkill9](https://discussions.unity.com/u/Enderkill9)
#### Post date: [April 29, 2017, 7:23pm UTC](https://discussions.unity.com/t/help-with-adjusting-script/663193/4 "2017-04-29T19:23:46Z")

</div>

> [@methos5k](#):
>
> The Random.Range is written incorrectly for your script. The Range in this situation would be 1 and 4.  
> The variables are declared in the wrong spot. They should be outside of the function’s scope entirely (not to mention outside of the for loop).

> [@WarmedxMints\_1](#):
>
> From the docs;
> 
> public static int Range(int min, int max);
> 
> **Description**
> 
> Returns a random integer number between min [inclusive] and max [exclusive] (Read Only).
> 
> [https://docs.unity3d.com/ScriptReference/Random.Range.html](https://docs.unity3d.com/ScriptReference/Random.Range.html)
> 
> So you want Random.Range(1, 4);
> 
> You really should read the manual 😛

Thanks guys for the help, but that just leaves me with one more problem, I want the values to equal to 35 and the values just keep increasing every time I press the button.

---

<div class="post-metadata">

### Author: ![methos5k](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/methos5k/32/387158_2.png) [@methos5k](https://discussions.unity.com/u/methos5k)
#### Post date: [April 29, 2017, 7:54pm UTC](https://discussions.unity.com/t/help-with-adjusting-script/663193/5 "2017-04-29T19:54:30Z")

</div>

@Enderkill9 , you should really look over some tutorials on scripting.

Reset your variables down to 5 at the beginning of the function. Just think about it 🙂  
They should be adding up to 35 for each call/activation. (already).
