Error With GUI.Box and Function Script


For this game we need to have different windows pop up at the same time so I wrote this script.

I would like the text in the windows to be variables so I used a function because it will make it a lot easier and more simple.

also I realize that all of the windows will appear on top of each other. I will change the position of the windows after all the errors are fixed.

This is my javascript…

#pragma strict

var shipWindow = function (shipname, shipPrice,  length, width, spacingX, spacingY,  damage, health, speed, summary)  

function () OnGUI; { 

		(GUI.Button (Rect (length,width,spacingX,spacingY), shipName))
	GUI.Box (Rect (Screen.width - 100,0,100,50), print (shipName)  )
	GUI.Box (Rect (Screen.width - 100,0,100,50), print (shipPrice) )
	GUI.Box (Rect (Screen.width - 100,0,100,50), print ("Damage :" " " damage) )
	GUI.Box (Rect (Screen.width - 100,0,100,50), print ("Health :" " " health) )
	GUI.Box (Rect (Screen.width - 100,0,100,50), print ("speed :" " " speed) )
	GUI.Box (Rect (Screen.width - 100,0,100,50), print ("summary :" " " print) )

The script is going to be used for a store menu where you can purchase different ships.

I get this error

   Assets/My Scripts/ShipPurchaseWindow.js(9,18): BCE0044: expecting :, found '{'.

And I am not sure what to do.

Any help is great,

Thank You

There are many problems here. You can’t put functions inside other functions, and “function () OnGUI; {” is incorrect syntax. You must always declare the type of variables, either explicitly, or implicitly by supplying a value, so “var shipWindow = function (shipname, shipPrice,...” is also incorrect. All the variables must be typed. Also you can’t put “print” inside a GUI.Box command; the second parameter must be a string. Finally, your GUI.Button won’t do anything since it’s not used in a conditional.

At the risk of seeming rude, I think you’d be better off doing some tutorials and reading the docs for a while so you can get up to speed on the basics of scripting, since what you have right now is mostly a bunch of random syntax that can’t work. Programming is very precise, and you can’t just throw together code that “vaguely looks sort of like something” together.