# Logic making my life terrible

**URL:** https://forum.kirupa.com/t/logic-making-my-life-terrible/282629
**Category:** Uncategorized
**Created:** [February 24, 2009, 12:26pm UTC](https://forum.kirupa.com/t/logic-making-my-life-terrible/282629 "2009-02-24T12:26:28Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![grandpaw\_broon](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/grandpaw_broon/32/3985_2.png) [@grandpaw\_broon](https://forum.kirupa.com/u/grandpaw_broon)
#### Post date: [February 24, 2009, 12:26pm UTC](https://forum.kirupa.com/t/logic-making-my-life-terrible/282629/1 "2009-02-24T12:26:28Z")

</div>

Hi all,

I have been here for 2 weeks now attempting a project and im still here after countless restarts and it all comes down to what i thought was initially simple.

To simplify this, consider the Node class is a simple circle sprite with mouse events enabled. A user clicks on a Node instance, moves the mouse and then clicks to create a new Node.

Once a new node is created, a Pair class instance is created. A Pair takes a reference to what node was originally clicked as well as the newly created node. It draws a line between these nodes.

Lets say i have 3 nodes (n) and therefor 2 Pairs(—).

```auto
n1 n2 n3
o-----o-----o

```

I also have a pairsArray and a nodesArray containing these objects.

Double click means destroy, so n2 is double clicked. My problem now comes from dealing with the pairs.

This is what i have.

```auto
function onNodeDoubleClick(e:MouseEvent)void
{
    var node:Node = e.target as Node;

    for (var i:int = 0; i < pairsArray.length; i++)
    {
        var pair:pair = pairsArray* as Pair;
        
        if (node == pair.node1 || node == pair.node2)
        {
            var trash:Pair = pairsArray.splice(pairsArray.indexOf(pair));
            trash.destroy();
        }
    }    
}

```

I have redone this whole class about 10 times and no matter what i do it always comes to these Pairs letting me down. Am i using arrays incorrectly or is it my logic failing me?

Thanks for reading.
