Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by samaxi · Dec 12, 2013 at 08:59 PM · savingrpgc++

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);
         }
     }
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
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?

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

17 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges