//Reset the player public void Stop() { //Change color back Table.transform.GetChild(i).GetComponent <Image>().color = color_save; //Move the player back to start and and move to the beggining of the array transform.position = GameObject.Find("Start").transform.position; i = 0; compile = false; stop = false; elseIF = false; endPos = transform.position; //Reset the animaion SetAnimation(0, 0); //Reset warning message For.SetActive(false); ForParanthesis.SetActive(false); If.SetActive(false); IfParanthesis.SetActive(false); Else.SetActive(false); ElseParanthesis.SetActive(false); }
//Create array public void Compile() { //Reset if the player is moving if (compile) { Stop(); } //Set values move = new char[Table.transform.childCount]; for (int i = 0; i < Table.transform.childCount; i++) { move[i] = Table.transform.GetChild(i).name[0]; } //checked for Errors //Check for FOR bool checkFor = true, foundFor = false, loneParanthesis = true; for (int i = 0; i < move.Length; i++) { if (move[i] == '5') { foundFor = true; for (int x = i + 1; i < move.Length; i++) { if (move[i] == '6') { checkFor = true; break; } else { checkFor = false; } } if (!checkFor) { For.SetActive(true); } } else if (move[i] == '6' && !foundFor) { ForParanthesis.SetActive(true); loneParanthesis = false; } } //Check for IF bool checkIF = true, foundIF = false, loneParanthesis2 = true; for (int i = 0; i < move.Length; i++) { if (move[i] == '7') { foundIF = true; for (int x = i + 1; i < move.Length; i++) { if (move[i] == '9') { checkIF = true; break; } else { checkIF = false; } } if (!checkIF) { If.SetActive(true); } } else if (move[i] == '9' && !foundIF) { Debug.Log("closed paranthesis needs if statement"); IfParanthesis.SetActive(true); loneParanthesis2 = false; } } //Check for else to have IF bool found_IF = false, loneParanthesis4 = true; for (int i = 0; i < move.Length; i++) { if (move[i] == '7') { found_IF = true; } else if (move[i] == '8' && !found_IF) { Debug.Log("else needs if statement"); Else.SetActive(true); loneParanthesis4 = false; } } //Check for else paranthesis and if statement bool checkElse = true; for (int i = 0; i < move.Length; i++) { if (move[i] == '8') { for (int x = i + 1; i < move.Length; i++) { if (move[i] == '9') { checkElse = true; break; } else { checkElse = false; } } if (!checkElse) { ElseParanthesis.SetActive(true); } } } //Stop compiler if there are errors if (checkFor && loneParanthesis && checkIF && loneParanthesis2 && checkElse && loneParanthesis4) { compile = true; once = true; } }