# Function glitch

**URL:** <https://forum.kirupa.com/t/function-glitch/260474>\
**Category:** Uncategorized\
**Created:** [May 16, 2008, 12:13am UTC](https://forum.kirupa.com/t/function-glitch/260474 "2008-05-16T00:13:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![RebuiltJorge](https://avatars.discourse-cdn.com/v4/letter/r/94ad74/32.png) [@RebuiltJorge](https://forum.kirupa.com/u/RebuiltJorge)\
**Post date:** [May 16, 2008, 12:13am UTC](https://forum.kirupa.com/t/function-glitch/260474/1 "2008-05-16T00:13:46Z")

</div>

I have an object that I push onto the stage every 5 seconds called Rock, when the rock is added, I pull its speed from a function called globalSpeed, it then returns a random number, however, the first time this function is called, it gets an undefined number and causes my rock to freeze, but everything else after that works, trace looks like:

undefined  
40  
35  
67  
etc

what could be causing this

```
ActionScript Code:
[LEFT][COLOR=#000000] **var** [/COLOR] myRock:Rock = [COLOR=#000000] **new** [/COLOR] Rock[COLOR=#000000]([/COLOR]globalSpeed[COLOR=#000000]([/COLOR]myRock[COLOR=#000000])[/COLOR][COLOR=#000000])[/COLOR];

```

[COLOR=#000000] **function** [/COLOR] globalSpeedCOLOR=#000000[/COLOR][COLOR=#000000]{[/COLOR]  
[COLOR=#0000FF]if[/COLOR][COLOR=#000000]([/COLOR]thisObj is Rock[COLOR=#000000])[/COLOR][COLOR=#000000]{[/COLOR]  
[COLOR=#0000FF]return[/COLOR] [COLOR=#0000FF]Math[/COLOR].[COLOR=#0000FF]random[/COLOR]COLOR=#000000[/COLOR]\*[COLOR=#000080]40[/COLOR]+[COLOR=#000080]50[/COLOR];  
[COLOR=#000000]}[/COLOR]

[COLOR=#000000]}[/COLOR]  
[/LEFT]

---

<div class="post-metadata">

**Author:** ![Felixz](https://avatars.discourse-cdn.com/v4/letter/f/ecb155/32.png) [@Felixz](https://forum.kirupa.com/u/Felixz)\
**Post date:** [May 16, 2008, 11:35am UTC](https://forum.kirupa.com/t/function-glitch/260474/2 "2008-05-16T11:35:59Z")

</div>

```auto
var myRock:Rock = new Rock(globalSpeed(myRock));

```

firstly u are creating variable myRock then u are passing empty var to globalSpeed function, then u create new rock.  
U have created an “impass”
