| | |
js math function help
Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
Iam making a game, the error is that in the "d" loop (for...) the value "holeBalls" stays always the same.
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...
IF YOU WISH, I CAN SEND YOU THE WHOLE WEBPAGE SO THAT YOU TEST IT AND UNDERSTAND IT BETTER
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
for (d=holeNum;d<=holeBalls;d++) { document.getElementById('hole'+d).value++ } }
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
// 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:
If not this, then maybe you should give us some live working version of the game so that we can understand your predicament.
> 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:
javascript Syntax (Toggle Plain Text)
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.
Last edited by ~s.o.s~; Jul 2nd, 2007 at 6:08 am.
I don't accept change; I don't deserve to live.
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
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
![]() |
Similar Threads
- Time function (C)
- Insertion Sort Problem (C++)
- Algorithm to Boolean Math Function (Computer Science)
- Sorting Algorithms using Time (C++)
- Command line calculator (C)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: Hit counter
- Next Thread: highlighting text in the text area
| Thread Tools | Search this Thread |
acid2 ajax ajaxexample ajaxjspservlets array beta box browser captchaformproblem cart child close codes column css date debugger decimal dependent design disablefirebug dom download element embed engine enter error events ext file firefox focus form forms frameworks getselection google gwt gxt hiddenvalue highlightedword hint html ie7 ie8 iframe index java javascript javascripthelp2020 jquery jsp jump libcurl listbox maps masterpage math media menu microsoft mimic mp4 onerror onmouseoutdivproblem onmouseover onreadystatechange paypal pdf php position post problem programming prototype rated rating redirect safari scale scriptlets scroll search security select software star starrating synchronous toggle unicode variables w3c web webservice window windowofwords xml \n






