- Home /
Question by
$$anonymous$$ · Jan 17, 2015 at 06:36 PM ·
c#arraystring
Only assignment, call, increment, decrement, and new object expressions can be used as a statement
I am trying to flatten a 2D Array into a 1D Array and get this error when converting the values over via index.
oneDimTable[x*tableA.GetLength(0)+y];
Assets/Timetable.cs(75,77): error CS0201: Only assignment, call, increment, decrement, and new object expressions can be used as a statement.
Here is the section with the error:
for (int x = 0; x < tableA.GetLength(1); x++){
for (int y = 0; y < tableA.GetLength(0); y++){
String = tableA[x,y];
oneDimTable[x*tableA.GetLength(0)+y];
}
}
Here is the whole script "Timetable":
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class Timetable : MonoBehaviour {
public bool setupMode = true;
int dayPosition;
int lessonPosition;
int realDay, realLesson;
public Transform Lesson, Room, Teacher, Info, ConfirmPage;
public GameObject LessonInfo, RoomInfo, TeacherInfo;
string[,] tableA;
string[,] tableB;
// Use this for initialization
void Start () {
if(PlayerPrefs.GetInt("SetupMode") == 0){
setupMode = false;
tableA = PlayerPrefsX.GetStringArray("TableA");
}
tableA = new string[5,5];
tableB = new string[5,5];
dayPosition = 1;
lessonPosition = 1;
realDay = 1;
realLesson = 1;
}
// Update is called once per frame
void Update () {
if(!setupMode){
string info = tableA[realDay-1,realLesson-1];
print (info);
string[] infoSplit = info.Split(","[0]);
print (info.Split(","[0]));
LessonInfo.GetComponent<Text>().text = infoSplit[0];
RoomInfo.GetComponent<Text>().text = infoSplit[1];
TeacherInfo.GetComponent<Text>().text = infoSplit[2];
}
}
void Submit (){
string lesson = Lesson.FindChild("Text").GetComponent<Text>().text;
Lesson.FindChild("Text").GetComponent<Text>().text = "";
string room = Room.FindChild("Text").GetComponent<Text>().text;
Room.FindChild("Text").GetComponent<Text>().text = "";
string teacher = Teacher.FindChild("Text").GetComponent<Text>().text;
Teacher.FindChild("Text").GetComponent<Text>().text = "";
print ("Lesson: "+lesson+" Room: "+room+" Teacher: "+teacher);
tableA[dayPosition-1,lessonPosition-1] = lesson+","+room+","+teacher;
lessonPosition++;
if(lessonPosition==6){
lessonPosition=1;
dayPosition++;
}
Info.GetComponent<Text>().text = "Day: "+dayPosition+"\nPeriod: "+lessonPosition;
if(dayPosition==6 && lessonPosition==1){
for (int x = 0; x < tableA.GetLength(1); x++){
for (int y = 0; y < tableA.GetLength(0); y++){
print(tableA[x,y]);
}
}
setupMode = false;
PlayerPrefs.SetInt("SetupMode", 0);
string[] oneDimTable = new string[tableA.GetLength(1)*tableA.GetLength(0)];
string String;
for (int x = 0; x < tableA.GetLength(1); x++){
for (int y = 0; y < tableA.GetLength(0); y++){
String = tableA[x,y];
oneDimTable[x*tableA.GetLength(0)+y];
}
}
PlayerPrefsX.SetStringArray("TableA", tableA);
}
}
void Reset() {
ConfirmPage.gameObject.SetActive(true);
}
void Cancel() {
ConfirmPage.gameObject.SetActive(false);
}
void RealReset() {
setupMode = true;
PlayerPrefs.SetInt("SetupMode", 1);
ConfirmPage.gameObject.SetActive(false);
}
}
Comment
Best Answer
Answer by ArkaneX · Jan 17, 2015 at 07:29 PM
You lack assigning a value to a table element:
oneDimTable[x*tableA.GetLength(0)+y] = tableA[x,y];
You don't even need to store it in a 'String' variable.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
bool[string] = true; array possible? 2 Answers
if a string has certain letter(s) or number(s) 2 Answers
Iterating through multidimensional arrays 2 Answers
Get JSON array object string value 2 Answers