# Crappy actionscript bug

**URL:** <https://forum.kirupa.com/t/crappy-actionscript-bug/251339>\
**Category:** programming\
**Created:** [February 7, 2008, 3:43pm UTC](https://forum.kirupa.com/t/crappy-actionscript-bug/251339 "2008-02-07T15:43:24Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ArmoredSandwich](https://avatars.discourse-cdn.com/v4/letter/a/3e96dc/32.png) [@ArmoredSandwich](https://forum.kirupa.com/u/ArmoredSandwich)\
**Post date:** [February 7, 2008, 3:43pm UTC](https://forum.kirupa.com/t/crappy-actionscript-bug/251339/1 "2008-02-07T15:43:24Z")

</div>

Alright, I’m working on the AI of my game. I’ve thought up a specific system that _should_ work perfectly.

I have an AI object, that object has several objects among those are tankTeam and buildTeam.

When the AI builds a new tank or builder references of the objects are added to the tankTeam and buildTeam.

Now here is the strange thing, builders are just… not there…

Here’s some code of the ai class:

```auto

if (type == "tank")
            {
            team = whatNeedsResupplyMost();
            team.addUnit ( new Tank (factory.xTarget, factory._y + factory._height, factory.xTarget, factory._y + factory._height + 120, _root.tankSpeed, 2 ));
            }
        else if (type == "builder")
            {
            builders.addUnit ( new Builder(factory.xTarget, factory._y + factory._height, factory.xTarget, factory._y + factory._height + 120, _root.builderSpeed, 2 ));
            }

```

There are more tankTeams, there for it decides in what team the tank should be added. There’s only one buildTeam, that would be builders.

Here’s the method of the buildTeam class (builders.addUnit();

```auto

    public function addUnit (unit:Builder):Void
        {
        members.push (unit);
        }

```

The code for a new tank is working PERFECTLY. However, with the builders things get messed up. This shouldn’t happen as a builder is exactly the same, with the same parameters as an tank. Another strange thing is that the builder is working correctly. There is nothing wrong with it, I can control it when I create it the same way for my team. But when I trace (unit), it traces _undefined_!

Can anyone please tell me WHY a reference of an object would just… dissapear, lose it’s value.

It makes NO SENSE!

Any help greatly appreciated,  
ArmoredSandwich aka ImWithNoob.
