- Home /
beginner question- several errors
I've been attempting a tutorial on creating an achievement system, however, the tutorial is not taking #pragma strict into consideration, and as a beginner, it is causing many difficulties. I would probably be better off turning off pragma strict and following the tutorial as it was done originally, however, I do not wish to learn improperly! My latest errors are as follows:
Assets/Scripts/AchievementManagement.js(13,10): BCE0044: expecting (, found 'playerMoved'. Assets/Scripts/AchievementManagement.js(14,1): BCE0044: expecting :, found '{'.
the two scripts are as follows:
Movement.js
#pragma strict
var achievementManagerScript: AchievementManagement;
var speed: int = 5;
private var cc: CharacterController;
function Start ()
{
cc = GetComponent(CharacterController);
}
function Update ()
{
if(Input.GetAxis("Horizontal") || Input.GetAxis("Vertical"))
{
achievementManagerScript.playerMoved();
}
cc.Move(-Vector3(Input.GetAxis("Horizontal") * speed * Time.deltaTime, 0,
Input.GetAxis("Vertical") * speed * Time.deltaTime));
}
function OnTriggerEnter(col: Collider)
{
if(col.gameObject.tag == "Coins")
{
Destroy(col.gameObject);
}
}
and the final one is: AchievementManagement.js
#pragma strict
var firstStepTex: Texture;
private var firstStepTaken:boolean;
private var edgeMargin;
function Start()
{
edgeMargin = Screen.width * .05;
{
function playerMoved()
{
if(!firstStepTaken)
{
unlockAchievement(firstStepTex);
firstStepTaken = true;
}
}
function unlockAchievement(achievementTex:Texture)
{
var go:GameObject = new GameObject("Achievement Object");
go.transform.position = Vector3(0,0,0);
go.transform.localScale = Vector3(0,0,0);
var guitex: GUITexture = go.AddComponent(GUITexture) as GUITexture;
guitex.texture = achievementTex;
guitex.pixelInset.width = achievementTex.width;
guitex.pixelInset.width = achievementTex.height;
guitex.pixelInset.x = Screen.width - achievementTex.width - edgeMargin;
guitex.pixelInset.y = Screen.height - achievementTex.height - edgeMargin;
}
Any help to find the errors, and any advice for avoiding further errors is greatly appreciated!
Answer by clunk47 · Dec 16, 2012 at 01:16 AM
You had a backwards bracket for function Start, like so:
function Start()
{
{
Then you didn't define edgemargin as a float, the system thought it was an object. That's about it, otherwise everything seems fine. Try replacing AchievementManagement.js with this.
#pragma strict
var firstStepTex: Texture;
private var firstStepTaken:boolean;
private var edgeMargin : float;
function Start()
{
edgeMargin = Screen.width * .05;
}
function playerMoved()
{
if(!firstStepTaken)
{
unlockAchievement(firstStepTex);
firstStepTaken = true;
}
}
function unlockAchievement(achievementTex:Texture)
{
var go:GameObject = new GameObject("Achievement Object");
go.transform.position = Vector3(0,0,0);
go.transform.localScale = Vector3(0,0,0);
var guitex: GUITexture = go.AddComponent(GUITexture) as GUITexture;
guitex.texture = achievementTex;
guitex.pixelInset.width = achievementTex.width;
guitex.pixelInset.height = achievementTex.height;
guitex.pixelInset.x = Screen.width - achievementTex.width - edgeMargin;
guitex.pixelInset.y = Screen.height - achievementTex.height - edgeMargin;
}
Thank you so much! The error messages were really confusing. I probably never would have found that without your help!
No problemo. If you don't $$anonymous$$d, you can also vote up the answer (thumbs up icon) :)