I’m currently writing a little web based point-and-click adventure, when I call to load in the 4th room (function alley4) by clicking the coresponding map in the previous room, it should check for an item in the localstorage and change the image map based on if you have the item or not, allowing for different interactions, this has worked in the past with other rooms but for some reason this one always loads the “localStorage.getItem(“radio”) == 2″ if statement (which should only trigger after placing the item), so it ends up thanking the player for their help before they’ve done anything, even if localstorage is completely clear of all items. For the life of me I cannot figure out why this is happening, by my eye this code should give the player the option to place the item before the character thanks them.
thank you for taking the time to read through my awfully written code <3
(Hopefully I included enough of my code to be useful, if theres any questions or requests for additional context code, don’t hesitate to ask. I included Alley2 html for context, as it triggers alley4() but it shouldn’t be relevent to issue)
/*Get eyeR*/
function alley4() {
audio = document.getElementById('walk'),
audio.volume = 0.7;
audio.play();
if (localStorage.getItem("radio") == 1) {
event.preventDefault();
audio.addEventListener('ended', function(){
let image = document.getElementById("party");
image.src ="/pics/alley4.png"
party.useMap = "#placeradio";
document.getElementById("alley4btn")
.style.display = "none";
document.body.removeChild(alley2box);
document.title = "...";
audio = document.getElementById('convo');
document.getElementById("convo").loop = true;
audio.play();
})
}
else if (localStorage.getItem("radio") == 2){
event.preventDefault();
audio.addEventListener('ended', function(){
let image = document.getElementById("party");
image.src ="/pics/alley4radio.png"
party.useMap = "#partymap";
document.getElementById("alley4btn")
.style.display = "none";
document.body.removeChild(alley2box);
document.title = "...";
audio = document.getElementById('convo');
document.getElementById("convo").loop = true;
audio.play();
snd = document.getElementById('radio');
snd.play();
})
}
else {
event.preventDefault();
audio.addEventListener('ended', function(){
let image = document.getElementById("party");
image.src ="/pics/alley4.png"
party.useMap = "#noradio";
document.getElementById("alley4btn")
.style.display = "none";
document.body.removeChild(alley2box);
document.title = "...";
audio = document.getElementById('convo');
document.getElementById("convo").loop = true;
audio.play();
})
}
}
/*Place Radio*/
function placeradio() {
let image = document.getElementById("party");
image.src ="/pics/alley4radio.png"
party.useMap = "#radiothanks";
document.getElementById("placeradiobtn")
localStorage.setItem("radio", "2");
audio = document.getElementById('convo');
audio.pause();
snd = document.getElementById('radio');
snd.play();
}
<!--Alley 2-->
<div id="alley2box">
<img id="alley2" src="" usemap="#alley2" class="center">
<map name="alley2">
<area id="shop1btn" class="cursor-click" onclick="shop1()" coords="333,288,673,536" shape="rect">
<area id="alley3btn" class="cursor-click" onclick="alley3()" coords="0,0,84,669" shape="rect">
<area id="alley4btn" class="cursor-click" onclick="alley4()" coords="1005,1,921,669" shape="rect">
</map>
</div>
<!--Alley 4-->
<div id="partybox">
<img id="party" src="" usemap="" class="center">
<map name="noradio">
<area id="boring" class="cursor-click" coords="625,329,747,502" shape="rect">
</map>
<map name="placeradio">
<area id="placeradiobtn" class="cursor-click" onclick="placeradio()" coords="433,455,726,608" shape="rect">
</map>
<map name="radiothanks">
<area id="thanks" class="cursor-click" coords="625,329,747,502" shape="rect">
</map>
<map name="partymap">
<area id="party" class="cursor-click" coords="654,336,718,397" shape="rect">
<area id="radiobtn" class="cursor-click" coords="416,397,696,567" shape="rect">
</map>
</div>
I’ve tried everything short of rewritting the logic for this room, i’ve tried tinkering with function and localstorage names, shifting around the order of the if statements, along with other attempts im not remembering rn, but nothing.


