Iam making a game, the error is that in the "d" loop (for...) the value "holeBalls" stays always the same.

for (d=holeNum;d<=holeBalls;d++)
  {
document.getElementById('hole'+d).value++
  }
 }

what i want is that holeBalls here, gets the value of "'hole'+id" because now what happens is that (this is a kalah game) when you click on a hole with 4 holeBalls, then the next hole has 5 holeBalls right? When you click on it, the balls will only spread out in 4 pieces, when the purpose is to give the next 5 holes one piece, but in this code i made, one piece gets lost...

// variables
gameStarted = false;
gemDif = 4;
function getGemDif()
{
gemDif = 4
var MySelect = document.getElementById("dif"); 
gemDif = MySelect.options[MySelect.selectedIndex].value;
document.getElementById("gemsAmount").value = gemDif;
}

function start()
{
gameStarted = true;
n = 1;
for (n=1;n<=12;n++)
 {
document.getElementById('hole'+n).value = gemDif;
document.getElementById('hole'+n).style.backgroundImage = 'url(img/hole_gem.png)';
 }
}

function move(hole)
{

if (gameStarted == true)
 {
changeSrc(hole)
holeID = hole.id
holeNum = holeID.replace(/hole/,'')
holeBalls = hole.value
hole.value = 0
holeNum++
holeBalls++
for (d=holeNum;d<=holeBalls;d++)
  {
document.getElementById('hole'+d).value++
  }
 }

if(gameStarted == false)
 {
alert('Select a difficulty and start the game!')
 }
}

function changeSrc(clicked)
{
clicked.style.backgroundImage = 'url(img/hole_empty.png)';
}

IF YOU WISH, I CAN SEND YOU THE WHOLE WEBPAGE SO THAT YOU TEST IT AND UNDERSTAND IT BETTER

> I am making a game, the error is that in the "d" loop (for...) the
> value "holeBalls" stays always the same.
It will remain the same because you never update it in the loop and always use it to perform the bound check.

Maybe something like this:

for (d=holeNum;d<=holeBalls;d++)
{
    var elem = document.getElementById('hole'+d);
    elem.value++;
    holeBalls = elem.value;
}

If not this, then maybe you should give us some live working version of the game so that we can understand your predicament.

Yes, Ill better give you the zip (attached below).

It is supposed that when you click a ball, the value has to be shared in equal quantities within the next (value) balls.

i.e.
if the hole has x balls, then, when the hole is clicked, the next x holes will have one more ball each. The clicked hole will have no more balls left.
x = amount of balls of the clicked hole

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.