Reputation: 33
so i ran into an problem with an Unity project i am currently on making
I have an Datatable with stats for different parts[Weight,Products,...] in a script
in this database there are multiple Tuples that i created. For example my Thrust Tuple<string, int>
in the database( in the sixth row) this tuple is assigned with this:
Tuple.Create("WASD",1)
WASD are the Directions the Thruster can fire and 1 is the strength.
at one part in my code I wanted to add the second value(1) to a variable. however it is just not working. if I print the Tuple out i get:
(WASD, 1)
UnityEngine.MonoBehaviour:print(Object) Master:Start() (at Assets/Scripts/Master.cs:68)
witch is fine
but I can not access it. it says it is an object but if I do GetType()
I get:
System.Tuple`2[System.String,System.Single]
I can't access it with Item2
or Item1
.
it's just (WASD,1)
BStats.Columns.Add(new DataColumn("Block", typeof(string)));
BStats.Columns.Add(new DataColumn("live", typeof(float)));
BStats.Columns.Add(new DataColumn("Weight", typeof(float)));
BStats.Columns.Add(new DataColumn("Products", typeof(Tuple<string,float>)));
BStats.Columns.Add(new DataColumn("Thrust", typeof(Tuple<string,float>)));
BStats.Columns.Add(new DataColumn("Consume", typeof(Tuple<string, float>)));
BStats.Columns.Add(new DataColumn("Desc", typeof(string)));
BStats.Rows.Add("Energy",1F,3F,Tuple.Create("Energy",1.0F),Tuple.Create("NAN",0F),
Tuple.Create("Thori um", 0.1F), "a Thorium Reactor");
BStats.Rows.Add("Armor", 5F, 4F, Tuple.Create("NAN", 0F), Tuple.Create("NAN", 0F),
Tuple.Create("NAN", 0F), "a simple Armor block");
BStats.Rows.Add("Engine", 2F, 2F, Tuple.Create("NAN", 0F), Tuple.Create("WASD", 1F),
Tuple.Create("Fuel", 0.2F), "a space engine");
BStats.Rows.Add("Gun", 1.5F, 0.5F, Tuple.Create("NAN", 0F), Tuple.Create("NAN", 0F),
Tuple.Create("Energy", 0.5F), "a simple laser Gun");
BStats.Rows.Add("Command Capsule", 3F, 5F, Tuple.Create("NAN", 0F), Tuple.Create("NAN", 0F),
Tuple.Create("Energy", 0.1F), "the Heart of your spaceship.");
print(BStats.Rows[2][4])
I am new to Unity so it's gonna be a stupid mistake or the way i use Datatables is just wrong.
Upvotes: 3
Views: 500
Reputation: 143463
DataRow
's indexer has return type of object
so you need to cast it to Tuple<string,float>
:
var tuple = (Tuple<string,float>)BStats.Rows[2][4];
Cosole.WriteLine(tuple.Item1)
Upvotes: 1