- Home /
Im not understanding the errors im getting in my script
So basically I'm building a inventory script and I'm not totally done but i keep getting unexpected symbol errors all over specifically:
Error CS1525: Unexpected symbol 'private' Error CS1525: Unexpected symbol ';', expecting ')' or ',' Error CS1525: Unexpected symbol 'GUILayout'
I can't find the problem i have look every where in the script! here it is all help is super appreciated :)
using UnityEngine; using System.Collections;
public class Inventory : MonoBehaviour {
private bool inventorywindowtoggle = false;
private Rect inventorywindowrect = new Rect (300, 100, 400, 400);
private dictonary <int,string> inventoryNameDictonary;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
//inventory show mechanic
void OnGUI()
{
inventorywindowtoggle = GUI.Toggle(new Rect (800,50,100,50), inventorywindowtoggle, "inventory");
if(inventorywindowtoggle)
inventorywindowrect = GUI.Window(0, inventorywindowrect, inventorywindowmethod, "inventory");
}
void inventorywindowmethod (int methodID)
{
//Dictonary
private dictonary <int, string> inventoryNameDictonary = new dictonary<int,string>()
{
{0, string.Empty},
{1, string.Empty},
{2, string.Empty},
{3, string.Empty},
{4, string.Empty},
{5, string.Empty},
{6, string.Empty},
{7, string.Empty},
{8, string.Empty},
{9, string.Empty},
{10, string.Empty},
{11, string.Empty},
{12, string.Empty},
{13, string.Empty},
{14, string.Empty},
{15, string.Empty}
}
//Items
ItemClass swordItem = new ItemClass (0,"Sword", SwordIcon, "Standard Sword nothing Special");
ItemClass staffItem = new ItemClass (1,"Mage Staff", StaffIcon, "Standard Staff for Wizard things");
ItemClass sheildItem = new ItemClass (2,"Sheild", SheildIcon, "Standard Metal Sheild to help prevent death");
//Display Dictionary
inventoryNameDictonary[0] = swordItem.name;
inventoryNameDictonary[1] = staffItem.name;
inventoryNameDictonary[2] = sheildItem.name;
//Inventory layout
GUILayout.BeginArea (new Rect (5,50,395,400));
GUILayout.BeginHorizontal ();
GUILayout.Button (inventoryNameDictonary[0], GUILayout.Height (50));
GUILayout.Button (inventoryNameDictonary[1], GUILayout.Height (50));
GUILayout.Button (inventoryNameDictonary[2], GUILayout.Height (50));
GUILayout.Button (inventoryNameDictonary[3], GUILayout.Height (50));
GUILayout.EndHorizontal ();
GUILayout.BeginHorizontal ();
GUILayout.Button (inventoryNameDictonary[4], GUILayout.Height ((50));
GUILayout.Button (inventoryNameDictonary[5], GUILayout.Height (50));
GUILayout.Button (inventoryNameDictonary[6], GUILayout.Height (50));
GUILayout.Button (inventoryNameDictonary[7], GUILayout.Height (50));
GUILayout.EndHorizontal ();
GUILayout.BeginHorizontal ();
GUILayout.Button (inventoryNameDictonary[8] GUILayout.Height (50));
GUILayout.Button (inventoryNameDictonary[9], GUILayout.Height (50));
GUILayout.Button (inventoryNameDictonary[10], GUILayout.Height (50));
GUILayout.Button (inventoryNameDictonary[11], GUILayout.Height (50));
GUILayout.EndHorizontal ();
GUILayout.BeginHorizontal ();
GUILayout.Button (inventoryNameDictonary[12], GUILayout.Height (50));
GUILayout.Button (inventoryNameDictonary[13], GUILayout.Height (50));
GUILayout.Button (inventoryNameDictonary[14], GUILayout.Height (50));
GUILayout.Button (inventoryNameDictonary[15], GUILayout.Height (50));
GUILayout.EndHorizontal ();
GUILayout.EndArea ();
}
public class ItemClass
{
int id;
string name;
Texture2D icon;
string discription;
public ItemClass (int ide, string nam, Texture2D ico, string dis)
{
id = ide;
name = nam;
icon = ico;
discription = dis;
}
}
}
Answer by supernat · Jun 17, 2014 at 03:57 AM
You have many issues. You need to add "using System.Collections.Generic;" because Dictionary only exists in this package. You're typing lower case dictionary instead of Dictionary. In several places, dictionary is misspelled. You can't declare a variable inside a method as private. You're missing semicolons at the end of some of your closing brackets for your variables. And you're missing closing parenthesis in several places. Once you clear some of these, the IDE will seem to provide more useful input to you.
Were would I place the Dictionary if not in the method? Can I place it with the Update, i guess that might make since since it needs to update based on the item attributes it is looking at but I'm not totally sure sorry for all the questions.
You can have the Dictionary inside inventorywindowmethod, no problem. But don't declare a local variable there with private Dictionary because you already declared a global Dictionary with the same name at the top of the script. To intialise it in inventorywindowmethod, you just need
inventoryNameDictonary = new Dictionary()<int,string>() { ... }
And please be careful with your spelling and attention to capitalisation etc. - you're going to run into a lot of problems otherwise.
Oh awesome thanks! and ya following someones how to guide kinda confused me I'm just going to start reading c# books ins$$anonymous$$d
Awesome thanks you so much man! haha ill go back through I didn't know I needed the Systems.Collections.Generic im just learning coding and some of the tutorials im using arnt very specific on case sensitivey and stuff.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Animation spins wildly after completed 0 Answers
hide object start script 4 Answers
Flashlight Blink? 1 Answer