! i can't get rid of 3 errors in my script!

i need help on my script i get 3 errors. one is
-player health.js(78,1): BCE0043: Unexpected token: yield.
-player health.js(78,6): UCE0001: ‘;’ expected. Insert a semicolon at the end.
-player health.js(90,1): BCE0044: expecting EOF, found ‘}’.

i can’t get rid of it here is my scripts:

    var curHealth : int = 100;
    var maxHealth : int = 100;
     
    var healthtext : GUIText;
    
    var curXp :  int = 0;
    var maxXp : int = 500;
    
    var xptext : GUIText;
    
    var level : int = 1;
     
function Start ()
{
    healthRegen();    
}
     
function Update ()
{
    healthtext.text = curHealth + " / " + maxHealth;
    xptext.text = "Level" + level + "XP" + curXp + " / " + maxXp;
     
    if(curXp == maxXp)
    {
       levelUpSystem();
    }
    if(curHealth < 0 )
    {
       curHealth = 0;
    }
    if(curHealth > maxHealth)
    {
       curHealth = maxHealth;
    }
    if(Input.GetKeyDown("e"))
    {
       curHealth -= 10;
    }
    if(Input.GetKeyDown("r"))
    {
       curXp += 10;
    }     
}
     
function healthRegen ()
{
    for(i=1;i>0;i++);
    {
       yield WaitForSeconds(0.5);
     
       if(curHealth < maxHealth)
       {
          curHealth++;
       }
    } 
}
         
function levelUpSystem ()
{
   curXp = 0;
   maxXp = maxXp +50;
   level ++;
   maxHealth += 100;
}

not that any of us could tell with that formatting, but you're missing a or have too many { or } or ; somewhere before the first line it's complaining about.

–

Next time you post code, could you please use the code formatting button on it, it makes the code much easier to read.

–

oh my god juste repair my error thanks

–

2 Answers

2

The problem is on the for loop in healthRregen(). You put in a extra semicolon at the end of the for()…

//Correct
 for(i=1;i>0;i++)
    
    //Incorrect extra semicolon at end parenthesis
    for(i=1;i>0;i++);

im sorry it juste i didn’t know how to put it in a code format but the thing is that at first i didn’t put the semicolon but unity put me a error saying that it needs a semicolon at the end. then i put it and it was one error down. and there a redo of my script.

var curHealth : int = 100;
var maxHealth : int = 100;
 
var healthtext : GUIText;

var curXp :  int = 0;
var maxXp : int = 500;

var xptext : GUIText;

var level : int = 1;
 
function Start () {
 
 
healthRegen();
 
}
 
 
 
 
 
function Update () {
 
 
healthtext.text = curHealth + " / " + maxHealth;
 xptext.text = "Level" + level + "XP" + curXp + " / " + maxXp;
 
 
 if(curXp == maxXp){
 
 levelUpSystem();
 
 }
 
 
 
if(curHealth < 0 ) {
 
curHealth = 0;
 
 
}
 
 
if(curHealth > maxHealth) {
 
 
curHealth = maxHealth;
 
 
}
 
 
 
if(Input.GetKeyDown("e")) {
 
curHealth -= 10;
 
}
 
 if(Input.GetKeyDown("r")){
 curXp += 10;
 
}
 
 
}
 
function healthRegen () {
 
 
for(i=1;i>0;i++); {
 
 
 
yield WaitForSeconds(0.5);
 
if(curHealth < maxHealth) {
 
curHealth++;
 
}
 
 
}
 
 
}




function levelUpSystem () {


curXp = 0;
maxXp = maxXp +50;
level ++;
maxHealth += 100;



}