- Home /
';' expected.Insert a semicolon at the end
I have an issue with my on GUI function when I compile I get this error and I don't see what I am doing wrong.
Could someone please help me? Am I missing something or not programming it right?
function OnGUI()
{
if(conActive)
{
for(t = 0; t < game.teamPlayerList.Count; t++)
{
TeamFPSPlayerNode = game.teamPlayerList[t] as TeamFPSPlayerNode;
}
}
}
would it help if I post the code I converted from ? Here it is:
for (int t = 0; t < game.playerList.Count; t++) { FPSPlayerNode go = game.playerList[t] as FPSPlayerNode; }
Answer by rutter · Apr 18, 2012 at 06:57 PM
Let's look at your first example:
TeamFPSPlayerNode = game.teamPlayerList[t] as TeamFPSPlayerNode;
I'm assuming here that "TeamFPSPlayerNode" is a type -- that it's a class you've built, somewhere? Some people helpfully suggested that you should declare a variable and give it a name, like so:
TeamFPSPlayerNode go = game.teamPlayerList[t] as TeamFPSPlayerNode;
But this has another problem: UnityScript doesn't declare variables in the same way that most "C family" languages do.
//C#
int x;
//UnityScript
var x : int;
You don't actually have to provide a type, in UnityScript, if the compiler can infer which type you want:
//these two lines do the same thing
var x : int = 2;
var x = 2; //the compiler can tell up front that you want an integer
If you want to declare a variable and assign it later? Then you'll need to specify a type. It's possible to get into some interesting shenanigans, there, anyway. It's always safer to specify a type, but it's nice to know sometimes that you don't always have to.
(C# has a similar feature using var
, actually, but I notice a lot of people get confused by it.)
So, getting back to your script, we need to change the syntax used when declaring your variable:
var go = game.teamPlayerList[t] as TeamFPSPlayerNode;
rutter thank you sooo much that fixed the issue which also saved me tons of time. You got the upvote
Answer by Lttldude · Apr 18, 2012 at 04:35 PM
Well it looks like all you are doing in the for loop is defining some object, so you need to have a variable in there like "go" to be the variable. You aren't doing anything with this variable, so I assume after you get this fixed you'll go on to doing something with that go variable.
function OnGUI()
{
if(conActive)
{
for(t = 0; t < game.teamPlayerList.Count; t++)
{
TeamFPSPlayerNode go = game.teamPlayerList[t] as TeamFPSPlayerNode;
}
}
}
yes I did do something with that go variable I didn't post it because thats not where my error was but here is the whole function.
function OnGUI()
{
if(conActive)
{
for(var t : int = 0; t < game.$$anonymous$$mPlayerList.Count; t++)
{
TeamFPSPlayerNode go = game.$$anonymous$$mPlayerList[t] as TeamFPSPlayerNode;
if(GUI.Button(new Rect(Screen.width - 150, 30 + (t*30),140,30),go.playerName))
{
selectNetPlayer = go.networkPlayer;
playerName = go.playerName;
playerSelected = true;
}
} } }
Compile errors will tell you which line failed, making it much easier to fix than having to guess.
If I had to guess, I would say "selectNetPlayer" or "playerName" or "playerSelected" are not defined correctly. Otherwise the function looks okay to me.
the error is the title and it falls into this code
for(var t : int = 0; t < game.$$anonymous$$mPlayerList.Count; t++)
{
TeamFPSPlayerNode go = game.$$anonymous$$mPlayerList[t] as TeamFPSPlayerNode;
}
and according to the compiler its right after the "a" of "game"
Yes would the whole script being posted help? I know some people don't like going through everything but this issue is affecting my whole game and I need this fixed. If you could help Great.
pragma strict
public var conActive : boolean;
public var game : TeamGameSetup;
public var playerSelected : boolean;
var playerName : String;
var selectNetPlayer : NetworkPlayer;
var chat : FPSChat;
function Start ()
{
game = GameObject.Find("GameScripts").GetComponent(TeamGameSetup);
chat = GameObject.Find("GameScripts").GetComponent(FPSChat);
}
function OnGUI()
{
if(conActive)
{
for( var t : int = 0; t < game.$$anonymous$$mPlayerList.Count; t++)
{
TeamFPSPlayerNode go = game.$$anonymous$$mPlayerList[t] as TeamFPSPlayerNode;
if(GUI.Button(new Rect(Screen.width - 150, 30 + (t*30),140,30),go.playerName))
{
selectNetPlayer = go.networkPlayer;
playerName = go.playerName;
playerSelected = true;
} } } if(playerSelected)
{ NextSetOf$$anonymous$$eys(playerName);
} }
Your answer
Follow this Question
Related Questions
How do I use a toolbar? 1 Answer
weird compilation error 2 Answers
Custom Build step before compilation 1 Answer
Errors are appearing but i don't know how to fix these... 1 Answer