- Home /
Expecting ( found Update (Javascript)
Ok, so the title is pretty explanatory. In my coding, i have an error saying
Expecting ( found Update on line 333,10
I have no idea what i did...it all looks fine to me!
Error on 33,10
#pragma strict
var ItemID : String[] = ["Wood","Stone","Metal Ore","Iron"];
var Ammount : int[] = [0,0,0,0];
var ItemTransform : Transform[];
var NewTexture : Texture[];
var AllTextures : Texture[];
var InventoryGrid : int;
var Blank : Texture;
var GridNumber : int;
private var AddingItems = false;
private var InventoryOn = false;
private var MouseTexture : Texture;
private var Change = false;
private var Clicks : int;
private var PrevNo : int;
private var HotBarActive : int = 35;
private var PrevTexture : int;
private var TextureNumber : int;
private var JustClicked = false;
private var item : Texture;
function ADDTexture(ItemTexture : Texture)
{
item = ItemTexture;
AddingItems = true;
}
function ADD(material : int)
{
material = ItemNumber;
Ammount[material] +=1;
}
function OnGUI()
{
if(InventoryOn == true)
{
GUI.Label(Rect(Input.mousePosition.x - 25, Screen.height - Input.mousePosition.y - 25 ,100,50),MouseTexture);
GUI.BeginGroup(new Rect(Screen.width / 2 - 400, Screen.height /2 - 300,800,600));
if(GUI.Button(Rect(100,50,50,50),NewTexture[0]));
{
Change = true;
Clicks += 1;
GridNumber = 0;
}
if(GUI.Button(Rect(150,50,50,50),NewTexture[1]));
{
Change = true;
Clicks += 1;
GridNumber = 1;
}
if(GUI.Button(Rect(200,50,50,50),NewTexture[2]));
{
Change = true;
Clicks += 1;
GridNumber = 2;
}
if(GUI.Button(Rect(250,50,50,50),NewTexture[3]));
{
Change = true;
Clicks += 1;
GridNumber = 3;
}
if(GUI.Button(Rect(300,50,50,50),NewTexture[4]));
{
Change = true;
Clicks += 1;
GridNumber = 4;
}
if(GUI.Button(Rect(350,50,50,50),NewTexture[5]));
{
Change = true;
Clicks += 1;
GridNumber = 5;
}
if(GUI.Button(Rect(400,50,50,50),NewTexture[6]));
{
Change = true;
Clicks += 1;
GridNumber = 6;
}
if(GUI.Button(Rect(100,100,50,50),NewTexture[7]));
{
Change = true;
Clicks += 1;
GridNumber = 7;
}
if(GUI.Button(Rect(150,100,50,50),NewTexture[8]));
{
Change = true;
Clicks += 1;
GridNumber = 8;
}
if(GUI.Button(Rect(200,100,50,50),NewTexture[9]));
{
Change = true;
Clicks += 1;
GridNumber = 9;
}
if(GUI.Button(Rect(250,100,50,50),NewTexture[10]));
{
Change = true;
Clicks += 1;
GridNumber = 10;
}
if(GUI.Button(Rect(300,100,50,50),NewTexture[11]));
{
Change = true;
Clicks += 1;
GridNumber = 11;
}
if(GUI.Button(Rect(350,100,50,50),NewTexture[12]));
{
Change = true;
Clicks += 1;
GridNumber = 12;
}
if(GUI.Button(Rect(400,100,50,50),NewTexture[13]));
{
Change = true;
Clicks += 1;
GridNumber = 13;
}
if(GUI.Button(Rect(100,150,50,50),NewTexture[14]));
{
Change = true;
Clicks += 1;
GridNumber = 14;
}
if(GUI.Button(Rect(150,150,50,50),NewTexture[15]));
{
Change = true;
Clicks += 1;
GridNumber = 15;
}
if(GUI.Button(Rect(200,150,50,50),NewTexture[16]));
{
Change = true;
Clicks += 1;
GridNumber = 16;
}
if(GUI.Button(Rect(250,150,50,50),NewTexture[17]));
{
Change = true;
Clicks += 1;
GridNumber = 17;
}
if(GUI.Button(Rect(300,150,50,50),NewTexture[18]));
{
Change = true;
Clicks += 1;
GridNumber = 18;
}
if(GUI.Button(Rect(350,150,50,50),NewTexture[19]));
{
Change = true;
Clicks += 1;
GridNumber = 19;
}
if(GUI.Button(Rect(400,150,50,50),NewTexture[20]));
{
Change = true;
Clicks += 1;
GridNumber = 20;
}
if(GUI.Button(Rect(100,200,50,50),NewTexture[21]));
{
Change = true;
Clicks += 1;
GridNumber = 21;
}
if(GUI.Button(Rect(150,200,50,50),NewTexture[22]));
{
Change = true;
Clicks += 1;
GridNumber = 22;
}
if(GUI.Button(Rect(200,200,50,50),NewTexture[23]));
{
Change = true;
Clicks += 1;
GridNumber = 23;
}
if(GUI.Button(Rect(250,200,50,50),NewTexture[24]));
{
Change = true;
Clicks += 1;
GridNumber = 24;
}
if(GUI.Button(Rect(300,200,50,50),NewTexture[25]));
{
Change = true;
Clicks += 1;
GridNumber = 25;
}
if(GUI.Button(Rect(350,200,50,50),NewTexture[26]));
{
Change = true;
Clicks += 1;
GridNumber = 26;
}
if(GUI.Button(Rect(400,200,50,50),NewTexture[27]));
{
Change = true;
Clicks += 1;
GridNumber = 27;
}
if(GUI.Button(Rect(100,250,50,50),NewTexture[28]));
{
Change = true;
Clicks += 1;
GridNumber = 28;
}
if(GUI.Button(Rect(150,250,50,50),NewTexture[29]));
{
Change = true;
Clicks += 1;
GridNumber = 29;
}
if(GUI.Button(Rect(200,250,50,50),NewTexture[30]));
{
Change = true;
Clicks += 1;
GridNumber = 30;
}
if(GUI.Button(Rect(250,250,50,50),NewTexture[31]));
{
Change = true;
Clicks += 1;
GridNumber = 31;
}
if(GUI.Button(Rect(300,250,50,50),NewTexture[32]));
{
Change = true;
Clicks += 1;
GridNumber = 32;
}
if(GUI.Button(Rect(350,250,50,50),NewTexture[33]));
{
Change = true;
Clicks += 1;
GridNumber = 33;
}
if(GUI.Button(Rect(400,250,50,50),NewTexture[34]));
{
Change = true;
Clicks += 1;
GridNumber = 34;
}
if(GUI.Button(Rect(400,350,50,50),NewTexture[40]));
{
Change = true;
Clicks += 1;
GridNumber = 40;
}
if(GUI.Button(Rect(450,350,50,50),NewTexture[41]));
{
Change = true;
Clicks += 1;
GridNumber = 41;
}
if(GUI.Button(Rect(500,350,50,50),NewTexture[42]));
{
Change = true;
Clicks += 1;
GridNumber = 42;
}
if(GUI.Button(Rect(600,350,50,50),NewTexture[43]));
{
if(MouseTexture == Blank)
{
if(NewTexture[43] !=Blank)
{
JustClicked = true;
NewTexture[40] = Blank;
NewTexture[41] = Blank;
NewTexture[42] = Blank;
}
Change = true;
Clicks += 1;
GridNumber = 43;
}
GUI.EndGroup();
}
if(GUI.Button(Rect(100,550,65,65),NewTexture[35]))
{
Change = true;
Clicks += 1;
GridNumber = 35;
}
if(GUI.Button(Rect(165,550,65,65),NewTexture[36]))
{
Change = true;
Clicks += 1;
GridNumber = 36;
}
if(GUI.Button(Rect(230,550,65,65),NewTexture[37]))
{
Change = true;
Clicks += 1;
GridNumber = 37;
}
if(GUI.Button(Rect(295,550,65,65),NewTexture[38]))
{
Change = true;
Clicks += 1;
GridNumber = 38;
}if(GUI.Button(Rect(360,550,65,65),NewTexture[39]))
{
Change = true;
Clicks += 1;
GridNumber = 39;
}
}
function Update ()
{
if(Input.GetKeyDown(KeyCode.Alpha1))
{
HotBarActive = 35;
}
if(Input.GetKeyDown(KeyCode.Alpha2))
{
HotBarActive = 36;
}
if(Input.GetKeyDown(KeyCode.Alpha3))
{
HotBarActive = 37;
}
if(Input.GetKeyDown(KeyCode.Alpha4))
{
HotBarActive = 38;
}
if(Input.GetKeyDown(KeyCode.Alpha5))
{
HotBarActive = 39;
}
}
if(NewTexture[HotBarActive] == AllTextures[TextureNumber])
{
PrevTexture = TextureNumber;
ItemTransform[TextureNumber].active = true;
}
if(NewTexture[HotBarActive] != AllTextures[TextureNumber])
{
ItemTransform[PrevTexture].active = false;
TextureNumber += 1;
if(TextureNumber >= AllTextures.Length)
{
TextureNumber = 0;
}
}
{
if(NewTexture[40] == AllTextures[0] && NewTexture[41] == Blank && NewTexture[42] == AllTextures[0])
{
NewTexture[43] == AllTextures[3];
}
if(Input.GetKeyDown(KeyCode.Tab))
{
InventoryOn = !InventoryOn;
}
if(AddingItems == true)
{
if(NewTexture[InventoryGrid] == Blank)
{
NewTexture[InventoryGrid]=item;
AddingItems = false;
InventoryGrid = 0;
}
else if(NewTexture[InventoryGrid] != Blank)
{
InventoryGrid += 1;
}
}
if(Clicks == 1)
{
MouseTexture = NewTexture[GridNumber];
PrevNo = GridNumber;
}
if(Clicks == 0)
{
if(NewTexture[42] != Blank)
{
MouseTexture = Blank;
}
}
if(Clicks == 2)
{
if(GridNumber < 42)
{
if(JustClicked == true);
{
JustClicked = false;
}
if(NewTexture[GridNumber] == Blank);
{
NewTexture[GridNumber] == MouseTexture;
NewTexture[PrevNo] = Blank;
Clicks = 0;
}
if(NewTexture[GridNumber] == MouseTexture)
{
Clicks = 0;
}
if(NewTexture[GridNumber] != MouseTexture)
{
Clicks = 1;
}
}
}
}
}
Is your Update function supposed to close prematurely? At the moment, the code after the last part doesn't have a function.
function Update ()
{
if(Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.Alpha1))
{
HotBarActive = 35;
}
if(Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.Alpha2))
{
HotBarActive = 36;
}
if(Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.Alpha3))
{
HotBarActive = 37;
}
if(Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.Alpha4))
{
HotBarActive = 38;
}
if(Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.Alpha5))
{
HotBarActive = 39;
}
No, it shouldn't end right there. How can i go about fixing it (sorry im a newbie) and i think that would explain some other problems i have been having...
Answer by Eluate · Apr 17, 2014 at 02:23 AM
@Ian_McCleary I also found something weird, your end bracket connects to your ongui bracket. We should not be dumping code though but in your case, I need to.
Here's the code, I added //comments where I changed something:
#pragma strict
var ItemID : String[] = ["Wood","Stone","Metal Ore","Iron"];
var Ammount : int[] = [0,0,0,0];
var ItemTransform : Transform[];
var NewTexture : Texture[];
var AllTextures : Texture[];
var InventoryGrid : int;
var Blank : Texture;
var GridNumber : int;
private var AddingItems = false;
private var InventoryOn = false;
private var MouseTexture : Texture;
private var Change = false;
private var Clicks : int;
private var PrevNo : int;
private var HotBarActive : int = 35;
private var PrevTexture : int;
private var TextureNumber : int;
private var JustClicked = false;
private var item : Texture;
function ADDTexture(ItemTexture : Texture)
{
item = ItemTexture;
AddingItems = true;
}
function ADD(material : int)
{
material = ItemNumber;
Ammount[material] +=1;
}
function OnGUI()
{
if(InventoryOn == true)
{
GUI.Label(Rect(Input.mousePosition.x - 25, Screen.height - Input.mousePosition.y - 25 ,100,50),MouseTexture);
GUI.BeginGroup(new Rect(Screen.width / 2 - 400, Screen.height /2 - 300,800,600));
if(GUI.Button(Rect(100,50,50,50),NewTexture[0]));
{
Change = true;
Clicks += 1;
GridNumber = 0;
}
if(GUI.Button(Rect(150,50,50,50),NewTexture[1]));
{
Change = true;
Clicks += 1;
GridNumber = 1;
}
if(GUI.Button(Rect(200,50,50,50),NewTexture[2]));
{
Change = true;
Clicks += 1;
GridNumber = 2;
}
if(GUI.Button(Rect(250,50,50,50),NewTexture[3]));
{
Change = true;
Clicks += 1;
GridNumber = 3;
}
if(GUI.Button(Rect(300,50,50,50),NewTexture[4]));
{
Change = true;
Clicks += 1;
GridNumber = 4;
}
if(GUI.Button(Rect(350,50,50,50),NewTexture[5]));
{
Change = true;
Clicks += 1;
GridNumber = 5;
}
if(GUI.Button(Rect(400,50,50,50),NewTexture[6]));
{
Change = true;
Clicks += 1;
GridNumber = 6;
}
if(GUI.Button(Rect(100,100,50,50),NewTexture[7]));
{
Change = true;
Clicks += 1;
GridNumber = 7;
}
if(GUI.Button(Rect(150,100,50,50),NewTexture[8]));
{
Change = true;
Clicks += 1;
GridNumber = 8;
}
if(GUI.Button(Rect(200,100,50,50),NewTexture[9]));
{
Change = true;
Clicks += 1;
GridNumber = 9;
}
if(GUI.Button(Rect(250,100,50,50),NewTexture[10]));
{
Change = true;
Clicks += 1;
GridNumber = 10;
}
if(GUI.Button(Rect(300,100,50,50),NewTexture[11]));
{
Change = true;
Clicks += 1;
GridNumber = 11;
}
if(GUI.Button(Rect(350,100,50,50),NewTexture[12]));
{
Change = true;
Clicks += 1;
GridNumber = 12;
}
if(GUI.Button(Rect(400,100,50,50),NewTexture[13]));
{
Change = true;
Clicks += 1;
GridNumber = 13;
}
if(GUI.Button(Rect(100,150,50,50),NewTexture[14]));
{
Change = true;
Clicks += 1;
GridNumber = 14;
}
if(GUI.Button(Rect(150,150,50,50),NewTexture[15]));
{
Change = true;
Clicks += 1;
GridNumber = 15;
}
if(GUI.Button(Rect(200,150,50,50),NewTexture[16]));
{
Change = true;
Clicks += 1;
GridNumber = 16;
}
if(GUI.Button(Rect(250,150,50,50),NewTexture[17]));
{
Change = true;
Clicks += 1;
GridNumber = 17;
}
if(GUI.Button(Rect(300,150,50,50),NewTexture[18]));
{
Change = true;
Clicks += 1;
GridNumber = 18;
}
if(GUI.Button(Rect(350,150,50,50),NewTexture[19]));
{
Change = true;
Clicks += 1;
GridNumber = 19;
}
if(GUI.Button(Rect(400,150,50,50),NewTexture[20]));
{
Change = true;
Clicks += 1;
GridNumber = 20;
}
if(GUI.Button(Rect(100,200,50,50),NewTexture[21]));
{
Change = true;
Clicks += 1;
GridNumber = 21;
}
if(GUI.Button(Rect(150,200,50,50),NewTexture[22]));
{
Change = true;
Clicks += 1;
GridNumber = 22;
}
if(GUI.Button(Rect(200,200,50,50),NewTexture[23]));
{
Change = true;
Clicks += 1;
GridNumber = 23;
}
if(GUI.Button(Rect(250,200,50,50),NewTexture[24]));
{
Change = true;
Clicks += 1;
GridNumber = 24;
}
if(GUI.Button(Rect(300,200,50,50),NewTexture[25]));
{
Change = true;
Clicks += 1;
GridNumber = 25;
}
if(GUI.Button(Rect(350,200,50,50),NewTexture[26]));
{
Change = true;
Clicks += 1;
GridNumber = 26;
}
if(GUI.Button(Rect(400,200,50,50),NewTexture[27]));
{
Change = true;
Clicks += 1;
GridNumber = 27;
}
if(GUI.Button(Rect(100,250,50,50),NewTexture[28]));
{
Change = true;
Clicks += 1;
GridNumber = 28;
}
if(GUI.Button(Rect(150,250,50,50),NewTexture[29]));
{
Change = true;
Clicks += 1;
GridNumber = 29;
}
if(GUI.Button(Rect(200,250,50,50),NewTexture[30]));
{
Change = true;
Clicks += 1;
GridNumber = 30;
}
if(GUI.Button(Rect(250,250,50,50),NewTexture[31]));
{
Change = true;
Clicks += 1;
GridNumber = 31;
}
if(GUI.Button(Rect(300,250,50,50),NewTexture[32]));
{
Change = true;
Clicks += 1;
GridNumber = 32;
}
if(GUI.Button(Rect(350,250,50,50),NewTexture[33]));
{
Change = true;
Clicks += 1;
GridNumber = 33;
}
if(GUI.Button(Rect(400,250,50,50),NewTexture[34]));
{
Change = true;
Clicks += 1;
GridNumber = 34;
}
if(GUI.Button(Rect(400,350,50,50),NewTexture[40]));
{
Change = true;
Clicks += 1;
GridNumber = 40;
}
if(GUI.Button(Rect(450,350,50,50),NewTexture[41]));
{
Change = true;
Clicks += 1;
GridNumber = 41;
}
if(GUI.Button(Rect(500,350,50,50),NewTexture[42]));
{
Change = true;
Clicks += 1;
GridNumber = 42;
}
if(GUI.Button(Rect(600,350,50,50),NewTexture[43]));
{
if(MouseTexture == Blank)
{
if(NewTexture[43] !=Blank)
{
JustClicked = true;
NewTexture[40] = Blank;
NewTexture[41] = Blank;
NewTexture[42] = Blank;
}
Change = true;
Clicks += 1;
GridNumber = 43;
}
GUI.EndGroup();
}
if(GUI.Button(Rect(100,550,65,65),NewTexture[35]))
{
Change = true;
Clicks += 1;
GridNumber = 35;
}
if(GUI.Button(Rect(165,550,65,65),NewTexture[36]))
{
Change = true;
Clicks += 1;
GridNumber = 36;
}
if(GUI.Button(Rect(230,550,65,65),NewTexture[37]))
{
Change = true;
Clicks += 1;
GridNumber = 37;
}
if(GUI.Button(Rect(295,550,65,65),NewTexture[38]))
{
Change = true;
Clicks += 1;
GridNumber = 38;
}if(GUI.Button(Rect(360,550,65,65),NewTexture[39]))
{
Change = true;
Clicks += 1;
GridNumber = 39;
}
}
}
function Update ()
{
if(Input.GetKeyDown(KeyCode.Alpha1))
{
HotBarActive = 35;
}
if(Input.GetKeyDown(KeyCode.Alpha2))
{
HotBarActive = 36;
}
if(Input.GetKeyDown(KeyCode.Alpha3))
{
HotBarActive = 37;
}
if(Input.GetKeyDown(KeyCode.Alpha4))
{
HotBarActive = 38;
}
if(Input.GetKeyDown(KeyCode.Alpha5))
{
HotBarActive = 39;
}
if(NewTexture[HotBarActive] == AllTextures[TextureNumber])
{
PrevTexture = TextureNumber;
ItemTransform[TextureNumber].active = true;
}
if(NewTexture[HotBarActive] != AllTextures[TextureNumber])
{
ItemTransform[PrevTexture].active = false;
TextureNumber += 1;
if(TextureNumber >= AllTextures.Length)
{
TextureNumber = 0;
}
}
{
if(NewTexture[40] == AllTextures[0] && NewTexture[41] == Blank && NewTexture[42] == AllTextures[0])
{
NewTexture[43] == AllTextures[3];
}
} //Added Bracket
if(Input.GetKeyDown(KeyCode.Tab))
{
InventoryOn = !InventoryOn; // Removed Bracket
if(AddingItems == true)
{
if(NewTexture[InventoryGrid] == Blank)
{
NewTexture[InventoryGrid]=item;
AddingItems = false;
InventoryGrid = 0;
}
else if(NewTexture[InventoryGrid] != Blank)
{
InventoryGrid += 1;
}
}
if(Clicks == 1)
{
MouseTexture = NewTexture[GridNumber];
PrevNo = GridNumber;
}
if(Clicks == 0)
{
if(NewTexture[42] != Blank)
{
MouseTexture = Blank;
}
}
if(Clicks == 2)
{
if(GridNumber < 42)
{
if(JustClicked == true);
{
JustClicked = false;
}
if(NewTexture[GridNumber] == Blank);
{
NewTexture[GridNumber] == MouseTexture;
NewTexture[PrevNo] = Blank;
Clicks = 0;
}
if(NewTexture[GridNumber] == MouseTexture)
{
Clicks = 0;
}
if(NewTexture[GridNumber] != MouseTexture)
{
Clicks = 1;
}
}
}
}
}
There's still a compiler error with material and itemnumber but you need to set the variable.
THAN$$anonymous$$ YOU SOOOOOOOOOO $$anonymous$$UCH! idk if its too much to ask but can you tell me what line 359 means? I have an array index out of range error there.
if(NewTexture[HotBarActive] == AllTextures[TextureNumber])
Thanks for all the help!
Hopefully you havnt seen my last comment yet...i figured out the error i was talking about.
Your answer
![](https://koobas.hobune.stream/wayback/20220613142910im_/https://answers.unity.com/themes/thub/images/avi.jpg)