Functions

I was wondering how do functions work? I tried making a function but it didn’t work :frowning:

 
 function darkarcherstatset(){
_root.dalv=_global.darkarcherlv+random(3)
_root.dahp=_global.darkarcherbasehp+lv*30}

I tried basing it off this saving game one:

 
function savegame(){
 myLSO = SharedObject.getLocal("Xin_Chapter1");
 if(myLSO.data.myObj == undefined){ // No object exists
     trace("Saved Game");
 }
 else{
     trace("Overwrote Saved Game");
 }
     myObj = {}; 
     myObj.objArray = new Array();
  myObj.objArray[0] = hp;
  myObj.objArray[1] = mp;
  myObj.objArray[2] = maxhp;
  myObj.objArray[3] = maxmp;
  myObj.objArray[4] = atk;
  myObj.objArray[5] = def;
  myObj.objArray[6] = sp;
  myObj.objArray[7] = maxsp;
  myObj.objArray[8] =  xp;
  myObj.objArray[9] =  maxxp;
  myObj.objArray[10] = maxatk
  
  myLSO.data.myObj = myObj;
}

but when I use darkarcherstatset() and make a dynamic text with the variable dahp it says nan what am I doing wrong? Thanks