Idle Commander - The Dev
Coder
I'm trying to make it so that when you exit a quest/popup and click to activate it again it starts on a certain step. But my thing is not working why? I see no error in the console either. To see the HTML CSS just go to Link and click on quests and do free the crafter and click the correct ones (They are pretty obvious) And when you get to "What are you waiting for go craft a furnace." click go and click on the quest box again it should bring you to id 8 but its not.
JS
JS
JavaScript:
let return1 = false;
function quest2() {
if (stoneAmt >= 25) {
quest2Popup();
const textElement = document.getElementById('text1')
const optionButtonsElement = document.getElementById('option-buttons1')
let state = {}
function startGame() {
if(return1) {
state = {}
showTextNode(8)
}
else {
state = {}
showTextNode(1)
}
}
function showTextNode(textNodeIndex) {
const textNode = textNodes.find(textNode => textNode.id === textNodeIndex)
console.log(textNode)
textElement.innerText = textNode.text
while (optionButtonsElement.firstChild) {
optionButtonsElement.removeChild(optionButtonsElement.firstChild)
}
textNode.options.forEach(option => {
if (showOption(option)) {
const button = document.createElement('button')
button.innerText = option.text
button.classList.add('btn')
button.addEventListener('click', () => selectOption(option))
optionButtonsElement.appendChild(button)
}
})
}
function showOption(option) {
return option.requiredState == null || option.requiredState(state)
}
function selectOption(option) {
const nextTextNodeId = option.nextText
if (nextTextNodeId < 0) {
if (nextTextNodeId == -2) {
return1 = true;
document.getElementById("craftitem").style.display = "block";
quest2Popup();
}
return quest2Popup();
}
state = Object.assign(state, option.setState)
showTextNode(nextTextNodeId)
}
const textNodes = [
{
id: 1,
text: "Anvils are Black \n Handles are Wood \n And crafting is a Joy!",
options: [
{
text: 'Anvils?',
nextText: 2
},
{
text: 'I hate poems',
nextText: 12
}
]
},
{
id: 2,
text: 'You don\'t know anvils?',
options: [
{
text: 'I don\'t',
nextText: 3
}
]
},
{
id: 3,
text: 'They are used for crafting.',
options: [
{
text: 'What is this \'crafting\'',
nextText: 4
},
{
text: 'Ah I know what this is',
nextText: 5
}
]
},
{
id: 4,
text: 'Crafting is the procces of making useful items by using pther items.',
options: [
{
text: 'I get it now',
nextText: 5
}
]
},
{
id: 5,
text: 'Good! \n you look smart maybe I can teach you it.',
options: [
{
text: 'Yes Please',
nextText: 7
},
{
text: 'NO',
nextText: 6
}
]
},
{
id: 6,
text: 'Fine.',
options: [
{
text: 'End',
nextText: -1
}
]
},
{
id: 7,
text: 'ALright I have unlocked it for you go craft a stoen furnace and come back.',
options: [
{
text: 'Ok',
nextText: 13
}
]
},
{
id: 8,
text: 'Thanks! I can find Quartz, emeralds, rubys, and may more!',
options: [
{
text: 'End',
nextText: 0
},
{
text: 'What is "many more?"?',
nextText: 9
}
]
},
{
id: 9,
text: 'As I said before, I can find Quartz, emeralds, rubys.',
options: [
{
text: 'Continue',
nextText: 10
}
]
},
{
id: 10,
text: 'The rest is a secret only if I find it I will tell you.',
options: [
{
text: 'Done',
nextText: 0
}
]
},
{
id: 12,
text: 'Well that hurt my feelings',
options: [
{
text: 'End',
nextText: -1
}
]
},
{
id: 13,
text: 'What are you waiting for go craft a furnace.',
options: [
{
text: 'Go',
nextText: -3
}
]
}
]
startGame();
}
else {
failQuestspopo();
}
}