Hello. I’ve been recommended this forum by some people at my university as somewhere that can help me when my n00b flash skills aren’t up to the job. :}
I am writing a game with a Civ style tech tree. When the player discovers a technology on the tree, it opens up other technologies for research.
The technologies are held in a multidimensional array. Here’s a simplified version of it
// The [0] element is the name of the technology
// The [1] element is how much research the player must accumulate to discover it
// The [2] element is whether it has been discovered yet (true or false)
technologies[["NameOfTech1", 1000, true], ["NameOfTech2" 1500, false]] //and so on
As the player researches something, a variable called remainingSci1 decreases, and the idea is, when it gets to zero, the current technology has been discovered. The variable decrements properly
Here is the function I am trying to use, that is going partially wrong.
function checkDiscoveries()//checks to see if researchProject has been discovered
{
for (var i=0; i<technologies.length; i++)// walk through the technologies array
{
if (researchProject ==technologies*[0] && remainingSci1<1) //if the current project matches the technology name and has accumulated enough science to be discovered
{
technologies *[2] = true; //set the technology to true - ie discovered
}//end if
}//end for
}//end function
This works fine immediately after the technology has been discovered. The tech does indeed go to true and opens up other technologies, but as soon as I click on one of the other technologies, the variable remainingSci1 is no longer < 1 and so the technology reverts back to undiscovered again.
I can see why this happens, but I am stuck on the code design that makes technologies[2]=true* a permanant change. I am desperate not to have to program a paragraph for each technology as there are over 160 of them and it would be a very inelegant solution.
Can anyone save my weekend and suggest a way that I can do this using my array.
Thanks all.