- Edited
I don't get it why am I having the error ? Here is my Handlers.js
import { updateGold, checkInitCompleted, updateProducerList } from "./functions.js";
export const handleKeyPress = (term, state) => {
return (name, matches, data) => {
const key = String.fromCharCode(data.code);
if (key === 'g' || key === 'G') {
state.gold++
}
for (let i = 0; i<state.producers.length; i++) {
if (key === `${state.producers[i].id}` && state.gold >= state.producers[i].cost) {
state.gold -= state.producers[i].cost
state.producers[i].cost *= state.producers[i].growthRate
state.producers[i].count++
state.productionRate+=state.producers[i].baseProduction
state.isProducerListUpdated = false
}
}
for (const q in state.producers) {
if (state.producers[q].count > 0 && state.isProducerListUpdated === false ) {
term.moveTo(25, 3);
term.green(state.productionRate.toFixed(2));
}
}
if (state.gold >= state.producers[0].cost && !state.isInitCompleted) {
checkInitCompleted(term, state)
}
if (state.isProducerListUpdated == false) {
updateProducerList(term, state)
}
}
}
export const handleStateChange = (term, state) => {
return () => updateGold(term, state)
}