• Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

JavaScript Why does this not work?

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

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();
    }
}
 

OldMan

King Coder
I'm gonna start by saying "I'm old school and this looks ECMAScript 6 so I maybe talking through my hat.".
I see this
Code:
   function startGame() {
        if(return1) {
            state = {}
            showTextNode(8)
        }
        else {
            state = {}
            showTextNode(1)
        }
    }
return1 needs to be true. I then went here:
Code:
   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)
    }
I would check the status of nextTextNodeId and nextTextNodeId and go from there.

I would also run a spell checker on your code. Here is what I saw:
<div id="text1">ALright I have unlocked it for you go craft a stoen furnace and come back.</div>
S/B
<div id="text1">Alright I have unlocked it for you to craft a stone furnace and come back.</div>

text: 'ALright I have unlocked it for you go craft a stoen furnace and come back.',
S/B
text: 'ALright I have unlocked it for you to craft a stone furnace and come back.',

text: 'Thanks! I can find Quartz, emeralds, rubys, and may more!',
S/B
text: 'Thanks! I can find Quartz, emeralds, rubies, and many more!',
 
Top