- Home /
error CS1023: An embedded statement may not be declaration or labeled statement
I am getting this error "error CS1023: An embedded statement may not be declaration or labeled statement" in Unity and I can't fix it. I am using this video (http://www.youtube.com/watch?v=yIhfPluMGTU). So if you could can you please help me. Thank you.
EDIT: The error is on line 77.
using UnityEngine;
using System.Collections;
using System;
public class GameSettings : MonoBehaviour {
void Awake(){
DontDestroyOnLoad(this);
}
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
public void SaveCharacterData(){
GameObject pc = GameObject.Find("pc");
PlayerCharacter pcClass = pc.GetComponent<PlayerCharacter>();
PlayerPrefs.DeleteAll();
PlayerPrefs.SetString("pc", pcClass.Name);
for(int cnt = 0; cnt < Enum.GetValues(typeof(AttributeName)).Length; cnt++) {
PlayerPrefs.SetInt(((AttributeName)cnt).ToString() + " - Base Value", pcClass.GetPrimaryAttribute(cnt).BaseValue);
PlayerPrefs.SetInt(((AttributeName)cnt).ToString() + " - Exp To Level", pcClass.GetPrimaryAttribute(cnt).ExpToLevel);
}
for(int cnt = 0; cnt < Enum.GetValues(typeof(VitalName)).Length; cnt++) {
PlayerPrefs.SetInt(((VitalName)cnt).ToString() + " - Base Value", pcClass.GetVital(cnt).BaseValue);
PlayerPrefs.SetInt(((VitalName)cnt).ToString() + " - Exp To Level", pcClass.GetVital(cnt).ExpToLevel);
PlayerPrefs.SetInt(((VitalName)cnt).ToString() + " - Current Value", pcClass.GetVital(cnt).CurValue);
PlayerPrefs.SetString(((VitalName)cnt).ToString() + " - Mods", pcClass.GetVital(cnt).GetModiyingAttributeString());
pcClass.GetVital(cnt).GetModiyingAttributeString();
}
for(int cnt = 0; cnt < Enum.GetValues(typeof(SkillName)).Length; cnt++) {
PlayerPrefs.SetInt(((SkillName)cnt).ToString() + " - Base Value", pcClass.GetSkill(cnt).BaseValue);
PlayerPrefs.SetInt(((SkillName)cnt).ToString() + " - Exp To Level", pcClass.GetSkill(cnt).ExpToLevel);
PlayerPrefs.SetString(((SkillName)cnt).ToString() + " - Mods", pcClass.GetSkill(cnt).GetModiyingAttributeString());
}
}
public void LoadCharacterData(){
GameObject pc = GameObject.Find("pc");
PlayerCharacter pcClass = pc.GetComponent<PlayerCharacter>();
pcClass.Name = PlayerPrefs.GetString("pc", "Name Me");
for(int cnt = 0; cnt < Enum.GetValues(typeof(AttributeName)).Length; cnt++) {
pcClass.GetPrimaryAttribute(cnt).BaseValue = PlayerPrefs.GetInt(((AttributeName)cnt).ToString() + " - Base Value", 0);
pcClass.GetPrimaryAttribute(cnt).ExpToLevel = PlayerPrefs.GetInt(((AttributeName)cnt).ToString() + " - Exp To Level", 0);
}
for(int cnt = 0; cnt < Enum.GetValues(typeof(VitalName)).Length; cnt++) {
pcClass.GetVital(cnt).BaseValue = PlayerPrefs.GetInt(((VitalName)cnt).ToString() + " - Base Value", 0);
pcClass.GetVital(cnt).ExpToLevel = PlayerPrefs.GetInt(((VitalName)cnt).ToString() + " - Exp To Level", 0);
string myMods = PlayerPrefs.GetString(((VitalName)cnt).ToString() + " - Mods","");
string[] mods = myMods.Split("|");
foreach(string s in mods)
string[] modStats = s.Split("_");
for(int x = 0; x < Enum.GetValues(typeof(AttributeName)).Length; x++) {
if(modStats[0] == ((AttributeName)x).ToString())
Debug.Log(modStats[0] + " = " ((AttributeName)x).ToString());
}
//pcClass.GetVital((int)VitalName.Health).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Constitution), modStats[1]));
}
//PlayerPrefs.SetString(((VitalName)cnt).ToString() + " - Mods", pcClass.GetVital(cnt).GetModiyingAttributeString());
//pcClass.GetVital(cnt).CurValue = PlayerPrefs.GetInt(((VitalName)cnt).ToString() + " - Current Value", 0);
}
}
Answer by tanoshimi · Dec 12, 2013 at 09:05 PM
The problem is indeed in line 77. You're looping through mods (an array of strings) using foreach and, on each iteration, attempting to re-declare a new array variable modStats and populate it by splitting the current string element.
You could stop the error by moving the string[] modStats declaration outside the loop and simply assigning its value within the foreach, but then at the end of the loop it would only have the result of splitting the last string from mods (because you're reassigning it every time.
What value do you actually want modStats to have at the end of this? An array of arrays, perhaps?
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
C# Capture Keypress 3 Answers
Accessing Functions from other Scripts 1 Answer
Assets/MELLE.js(1,15): BCE0044: unexpected char: ';'. 1 Answer
Can someone help me with my script. It won't work for me. 0 Answers