Tengo diferentes botones y dependiendo de qué botón se presione, quiero que cambien las variables en mi función.
CSS:
.build{ border-radius:50%; height:85px; width:85px; position:absolute; background-color: transparent; cursor: pointer; border: 1px solid transparent; } #build1{ margin-left:372px; margin-top:320px; }html:
<button class="build" id="build1"></button>El resto es javascript
algunas variables
var build1EL=document.querySelector("#build1"); var buildtower1=false; var click1=false; var a1=false; var mynter=100; build1EL.addEventListener("click",clicktower);Una función
function clicktower(){ if(byggtaarn1===false){ if(coins>=75){ coins-=75; byggtaarn1=true; a1=true; } } if(click1===true){ click1=false; a1=false; } if(a1===true){ click1=true; } tower1(); a1=true; }Entonces esto funciona perfectamente bien, tower1() es otra función y el interior de la función es un poco desordenado, pero funciona. Pero debo hacer esto 5 veces más, pero con diferentes botones y una torre de construcción correspondiente, haga clic y una variable
Entonces, manteniendo las mismas variables para el primer botón, cambie la función y agregue eventlistener a esto:
build1EL.addEventListener("click", function(){ clicktower(buildtower1, click1,a1); });
function clicktower(buildtower,click,a){ if(buildtower===false){ if(coins>=75){ coins-=75; buildtower=true; a=true; } } if(click===true){ click=false; a=false; } if(a===true){ click=true; } taarn1(); a=true;}Pero esto no funciona, probé diferentes formas de hacer que addeventlistener funcione con argumentos, pero ninguna funcionó.