Okay, I have been searching the forum about this error for a few hours now. ALL of the questions have been closed with no answer and the ones that have been answered don’t explain what the error actually is…
ANY help will be greatly appreciated.
My error is:
Assets/SCRIPTS/SaveLoad/LoadInformation.cs(9,33): error CS0029: Cannot implicitly convert type string' to BaseCharacterClass’
The code is:
using UnityEngine;
using System.Collections;
public class LoadInformation
{
public static void LoadAllInformation()
{
GameInformation.PlayerName = PlayerPrefs.GetString("PLAYERNAME");
GameInformation.PlayerClass = PlayerPrefs.GetString("PLAYERCLASS");
GameInformation.Strength = PlayerPrefs.GetInt("PLAYERSTR");
GameInformation.Dexterity = PlayerPrefs.GetInt("PLAYERDEX");
GameInformation.Constitution = PlayerPrefs.GetInt("PLAYERCON");
GameInformation.Intelligence = PlayerPrefs.GetInt("PLAYERINT");
GameInformation.Wisdom = PlayerPrefs.GetInt("PLAYERWIS");
GameInformation.Charisma = PlayerPrefs.GetInt("PLAYERCHA");
GameInformation.StrBonus = PlayerPrefs.GetInt("PLAYERSTRB");
GameInformation.DexBonus = PlayerPrefs.GetInt("PLAYERDEXB");
GameInformation.ConBonus = PlayerPrefs.GetInt("PLAYERCONB");
GameInformation.IntBonus = PlayerPrefs.GetInt("PLAYERINTB");
GameInformation.WisBonus = PlayerPrefs.GetInt("PLAYERWISB");
GameInformation.ChaBonus = PlayerPrefs.GetInt("PLAYERCHAB");
}
}
Don’t complain, your questions are without detail and can’t be answered objectively. Even in this case, you’ve given the part where the error is occuring, but the error is really telling you some quite different.
This line:
GameInformation.PlayerClass = PlayerPrefs.GetString("PLAYERCLASS");
You’re attempting to get a string back from PlayerPrefs, that’s great and all but in the class(or it’s inherited members) you have a Field/Property called PlayerClass, this is not of type string and thus you can not set it to a string. It appears to be of type BaseCharacterClass (probably in a file called BaseCharacterClass.cs or a nested class somewhere that we have no idea about) and again, putting a string into it doesn’t work. It’s like trying to put a potato into a key hole for a door knob. Potato is not of type key, likewise, string is not of type BaseCharacterClass.
Rant:
This is a common problem, if you did not create the code and you’re unfamiliar with how a language and the structures it’s employs work, then you spend a great deal of time trying to get help rather then trying to learn the language. If you studied c# to some degree, you would understand that generally speaking one type is not like the other and this error would have automagically flagged something in your brain.