0

I'm trying to make a program that would draw bones that are connected to each other at their ends, just by recursively running through that bone's children. The issue is that when a bone has more than two children it attempts to draw the second one an infinite number of times.

var bones={
    torso:{
        attached:["arm","arm2"]
    },
    arm:{
        attached:[]
    },
    arm2:{
        attached:[]
    }
}

drawBone("torso")
function drawBone(bone){
    console.log(bone)
    let attBones = bones[bone].attached;
    for(i = 0; i < attBones.length; i++){
        drawBone(attBones[i])
    }
}

From what I've found, i inside the for loop gets stuck at 1 somehow. I'm not super familiar with recursion, so there might be something fundamentally wrong I'm doing.

TheLazySquid
  • 69
  • 1
  • 8

0 Answers0