Unknown identifier Error

Hi, its my first message in this forum.
i look at a youtube tutorial about pong game.
At the “game GUI” script, i did all same with the tutorial, but unity gives error,
Unity says Assets/game GUI.js(8,42):BCE0005: Unknown identifier:‘Ball’ .
How can i solve this problem, thanks.

my script

#pragma strict

var pScore:GUIText;
var eScore:GUIText;

function OnGUI()
{
pScore.text = "Player Score: " + Ball.playerScore;
eScore.text = "Enemy Score: " + Ball.enemyScore;
}

I am trying to quickly review the video as I’m typing this and can’t say for sure yet, but it doesn’t look as if the variable Ball has actually been set anywhere, so the script is complaining because it doesn’t know what that object is. I would try something like this…

 var Ball : GameObject;
var pScore:GUIText;
var eScore:GUIText;

function OnGUI()
{
	pScore.text = "Player Score: " + Ball.playerScore;
	eScore.text = "Enemy Score: " + Ball.enemyScore;
}

And then drag/drop the Ball object from your hierarchy onto the “Ball” slot of this object in the Inspector.

Let me know if that helps any :slight_smile:

i did all, but another error

Hmm… I’m not sure off the top of my head. Obviously it’s still not finding something that it’s looking for… I’ll go through the two-part Pong tutorial myself and let you know what I find shortly.

i saw your game project and i could help as internship 3d modeller. I use Blender, photoshop and illustrator.

I still haven’t had a moment to go through the videos (hectic day here), but I did take a look at the example project that the author made… For the life of me, I have no idea how he’s getting the player enemy scores without telling the script where the Ball object is, but it seems to work in the example. Have you tried loading the author’s Pong.UnityPackage and testing it? If you don’t have the same problems with his premade code, double check it against your own code and see if there are any differences. I’ll try and toy with it myself in a bit too and will let you know what I figure out, if anything.

I could certainly use some help with 2D and 3D character creation, thanks so much! At the moment, I’m not sure just what I’d have you do, unless you’re comfortable enough in Blender to try creating/rigging the Night Of The Living Dead cast. After my own initial frustrations with it, I’ve slowed things down and am now trying to create some simple 2D side scroller games… and even those are giving me more headaches than I’d like, haha. One thing I could use right now would be an animated child character (boy or girl) for my latest 2D project who can walk, run and jump (animation wise). 2D or 3D in this instance would be fine, and I’m not terribly concerned with the art style at the moment… Anything would be better than the placeholder cartoon zombie I’m using now, which I created for another project.

I’ll be back again soon, hopefully with a decent answer for you.

Edited to add: You can find the Pong tutorial author’s Unity Package here:
https://www.dropbox.com/sh/4zuaj3wgcui22z1/XwELLC7Ig5/Unity3D%20Tutorial%20Series/Pong/PongTutorial.unitypackage

I haven’t looked at the tutorial for specifics but…

A GameObject does not have .playerScore or .enemyScore member variables. It should be a different type (or Ball (a script) should have static variables)

The Ball script does have static variables for playerScore and enemyScore. Now at least I understand why/how the script is actually able to function in the demo :wink: Still new at all this myself, so don’t expect much haha.

Alright, I’ve gone through both videos for the Pong tutorial and all I can really assume is that this guy’s talking way too quick for you to follow… There are lots of little things going on that he either glosses over or doesn’t even bother to mention (for instance, at no point does he actually say to assign “w” to the UP input, he just does it and continues)… My guess is that you’ve probably missed one of these glib little references somewhere in the video… Again, have a look at the example project that he’s created and double check to make sure that yours is in line with it. This doesn’t mean just looking over the scripts, but looking over the in-game objects and their settings in the Inspector as well. Somewhere along the line, you missed something, That’s all I can really tell you. Sorry I can’t be of more help, but that would basically involve you posting all of your code and me having to pour over it comparing it to the original tutorial authors’ code… and well, you can do that for yourself - it’s good for ya :wink:

Sorry, really was hoping to provide you with a solid solution, but I’ve recreated and tested the whole thing myself… It works just fine.

Hopefully you’ve already figured this out, but just in case, it occurred to me last night that DanielQuick was probably on the right track… Double check your Ball.js script and make sure that both playerScore and enemyScore are set to be static variables… If they’re set to just var or private var, your other script won’t know what to do with them.

static var playerScore:int = 0;
static var enemyScore:int = 0;

Can’t believe I didn’t consider that a bit earlier, especially after DQ’s response, lol. It’s been one of those weeks :slight_smile: