- Home /
Static Class unmodifiable variable
Wow, wording the questing was more difficult then I thought.
Hello, I have a problem I've been trying to figure out for some time now. Couldn't find any answers both here and on Google ( I usually manage to solve my own problems). But now I seem to have landed in a bottomless pit.
This is my first question and I'm quite the newbie so be gentle ;) Anyways, the problem!
I have a problem with a static class I'm using in my game. It's a class that holds stats for different characters. It has been working for the longest time so while testing I raised some of the stats temporarily. The problem occurred when I tried to change the stats back to normal. No errors show up but in-game the numbers(of the stats) won't change, they're stuck with the temporary numbers, as if I'm unable to modify them.
Here is the kicker though. I have other static classes that work perfectly, I'm able to modify the numbers in the script without any problems. There are even variables within the script that's giving me problems which work. It's just that one variable within that one static class.
I have no idea how to fix this!
Here is the code from the script that giving me problems: #pragma strict
static class HeroClass extends MonoBehaviour {
public class Stats {
//Basic stats
var Name:String;
var Strength:int;
var Smart:int;
var Speed:int;
var Luck:int;
//constructor for stats
public function Stats(NAME : String, STR : int, INT : int, SPEED : int, LUCK : int) {
Name = NAME;
Strength = STR;
Smart = INT;
Speed = SPEED;
Luck = LUCK;
}
}
//Stats for different heroes
public var HeroDStats : Stats = new Stats("HeroDeedee", 15, 15, 15, 15); //15
public var TinaStats : Stats = new Stats("Tina", 14, 20, 17, 14); //THIS IS BROKEN FOR SOME REASON
}
It's only TinaStats that's broken. I'm able to edit the numbers freely for HeroDStats then for example using print(HeroClass.HeroDStats.Name) works perfectly but if I edit TinaStats then use print(HeroClass.TinaStats.Name) it only gives me the temporary input.
It's probably something pretty obvious but I'm stumped! Please let me know if there are any details I'm missing.
Answer by Odinnorn · Jan 23, 2014 at 12:19 PM
Doesn't matter anymore. Figured it out myself. I had: var otherScript = GetComponent(HeroClass).TinaStats; in another script. This for some reason was blocking any modification of TinaStats in the class.