0

relevant code:

function stepNetwork() {
    for(i = 0; i<maxNeurons; i++) {
        if(neuronArray[i].charge >= neuronArray[i].threshhold) {
            var elapsed = ((new Date()).getTime()) - neuronArray[i].lastFired;
            if(elapsed >= 5000){
                fireNeuron(i);
            }
        }
    }
}

function fireNeuron(n){
    //get number of outputs on this neuron
    var outs = neuronArray[n].outputs.length;
    for(p = 0; p < outs; p++) {
        sendChargeTo = neuronArray[n].outputs[p];
        addCharge(sendChargeTo);
    }
    neuronArray.charge = 0;
    neuronArray.lastFired = ((new Date()).getTime());
}

function addCharge(n) {
    neuronArray[n].charge++;//HERES THE ERROR!!
}

Here is what firebug is telling me:

neuronArray[n] is undefined ///then why can I see its value in the scripts->watch tab?
addCharge(n=100)js_operation.php (line 73)
fireNeuron(n=73)js_operation.php (line 66)
stepNetwork()

The thing that gets me is that when I pass a number it works, and when I evaluate neuronArray, neuronArray[n], neuronArray[n]. charge etc in the scripts pane (watch area), it always is able to reference it.

2
  • 1
    the fact that you have neuronArray.charge and neuronArray[n].charge might show problems. Commented Jan 30, 2011 at 0:43
  • good catch, fixed, same issue :( Commented Jan 30, 2011 at 2:46

2 Answers 2

1

Maybe this is the problem:

sendChargeTo = neuronArray[n].outputs[p];
addCharge(sendChargeTo);

You're not sending addCharge an index, you're sending it neuronArray[n].outputs[p].

Sign up to request clarification or add additional context in comments.

2 Comments

typeof(sendChargeTo);//returns "number"
actually...var sendChargeTo = neuronArray[n].outputs; sendChargeTo[p]++; worked... so you were right. thank you.
0

Apart from Raynos's comments about the last two lines in fireNeuron I can't see an obvious problem.

Perhaps you have a globals problem? I think that variables i, p, and sendChargeTo should be declared local with var.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.