# Functions

**URL:** <https://forum.kirupa.com/t/functions/245636>\
**Category:** Uncategorized\
**Created:** [December 2, 2007, 6:18am UTC](https://forum.kirupa.com/t/functions/245636 "2007-12-02T06:18:19Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![leonthelion](https://avatars.discourse-cdn.com/v4/letter/l/58956e/32.png) [@leonthelion](https://forum.kirupa.com/u/leonthelion)\
**Post date:** [December 2, 2007, 6:18am UTC](https://forum.kirupa.com/t/functions/245636/1 "2007-12-02T06:18:19Z")

</div>

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

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

```

I tried basing it off this saving game one:

```php
 
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
