Hi,
i’ve a problem with classes in UnityScript. My first file, named “CubeType.js” includes the class with functions:
static var IDList = new CubeType[64];
public class CubeType {
public var ID : int;
public var name : String;
public var treeChance : int;
public var flowerChance : int;
public var grassChance : int;
public var rainSnowChance : int;
public var temperatureMin : int;
public var temperatureMax : int;
public var snow : boolean;
public var rain : boolean;
public var defaultColor : Color;
/*
### Set Functions
*/
public function SetID (par1)
{
this.ID = parseInt(par1);
IDList[par1] = this;
return true;
}
public function SetName (par1)
{
this.name = par1;
return true;
}
public function SetTreeChance (par1)
{
this.treeChance = parseInt(par1);
return true;
}
public function SetFlowerChance (par1)
{
this.flowerChance = parseInt(par1);
return true;
}
public function SetGrassChance (par1)
{
this.grassChance = parseInt(par1);
return true;
}
public function SetRainSnowChance (par1)
{
this.rainSnowChance = parseInt(par1);
return true;
}
public function SetTemperature(par1, par2)
{
this.temperatureMin = parseInt(par1);
this.temperatureMax = parseInt(par2);
return true;
}
function EnableSnow (par1 : boolean)
{
this.snow = par1;
}
function EnableRain (par1 : boolean)
{
this.rain = par1;
}
public function SetDefaultColor (par1 : Color) {
this.defaultColor = par1;
}
/*
### Get Functions
*/
public function GetID ()
{
return this.ID;
}
public function GetName ()
{
return this.name;
}
public function GetTreeChance ()
{
return this.treeChance;
}
public function GetFlowerChance ()
{
return this.flowerChance;
}
public function GetGrassChance ()
{
return this.grassChance;
}
public function GetRainSnowChance ()
{
return this.rainSnowChance;
}
public function GetTemperatureMin ()
{
return temperatureMin;
}
public function GetTemperatureMax ()
{
return temperatureMax;
}
public function GetEnabledSnow ()
{
return this.snow;
}
public function GetEnabledRain ()
{
return this.rain;
}
public function GetDefaultColor ()
{
return this.defaultColor;
}
}
I’ll create a new object of this class in the file “CubeTypeFlat.js”:
static var CubeTypeFlat = new CubeType();
CubeTypeFlat.SetName("flache Wiese");
CubeTypeFlat.SetDefaultColor(Color(0.752,0.874,0.3647,1));
CubeTypeFlat.SetTreeChance(50);
CubeTypeFlat.SetFlowerChance(20);
CubeTypeFlat.SetGrassChance(250);
If I try to call the function GetTreeChance, or GetName from an other file like this:
Debug.Log("Trees: " + CubeTypeFlat.CubeTypeFlat.GetTreeChance());
it 'll debug the following text:
Trees: 0
I hope to get some help!
bb
(Sorry for my very bad English)