• 💀 Happy Halloween! 💀 It's time to vote for the best terrain! Check out the entries to Hive's HD Terrain Contest #2 - Vampire Folklore.❗️Poll closes on November 14, 2023. 🔗Click here to cast your vote!
  • 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • 🏆 HD Level Design Contest #1 is OPEN! Contestants must create a maze with at least one entry point, and at least one exit point. The map should be made in HD mode, and should not be openable in SD. Only custom models from Hive's HD model and texture sections are allowed. The only exceptions are DNC models and omnilights. This is mainly a visual and design oriented contest, not technical. The UI and video walkthrough rules are there to give everyone an equal shot at victory by standardizing how viewers see the terrain. 🔗Click here to enter!

Script not working?

Status
Not open for further replies.
Level 17
Joined
Dec 11, 2014
Messages
2,008
Hey there hive! I Hope you have a nice day.
It's the second day I'm trying to learn some ways to write scripts, So I'm a n00b.
Anyways, on one of my JavaScript Scripts, I encountered a Problem:

The main Idea is supposed to be Something like Hidden tags, To show screenshots when a button is clicked, and Hide when clicked again. I Used some variables and If/then/elses, they didn't work out... So any help would be appreciated.


The button things
Code:
<button onclick="displayScreenshots()">Screenshots</button>
The script:
Code:
function displayScreenshots() {
    var boolScreenies = "false";
    var ScreenshotString;
    if (boolScreenies = false) {
         boolScreenies = "true";
         ScreenshotString = "Daiee"
    } else {
         boolScreenies = "false";
         ScreenshotString = "";
    }
    document.getElementById("ScreenshotsHere").innerHTML = ScreenshotString;
}



And don't hurt me, I'm a noob :D

I also tried inspecting the Hidden tags in the Hive, understood Nothing :(
 
Level 29
Joined
Jul 29, 2007
Messages
5,174
You have three different errors.

First of all, you are mixing the assignment operator (=) and the equality operator (==, but you'd usually want to use ===, to be extra safe).

The second issue is that you are using a string, but comparing it to a boolean.
"false" is a string, false is a boolean.

Finally, the last error is a logical one - you are checking if a variable you just set at the beginning of the function call is a certain value.
You just set it - the value will always be "false".
You probably meant to use a global variable, just declare it outside of the function.

With all of these changes, it should be something like this:
JavaScript:
var boolScreenies = false;

function displayScreenshots() {
    var ScreenshotString;
	
    if (boolScreenies === false) {
         boolScreenies = true;
         ScreenshotString = "Daiee";
    } else {
         boolScreenies = false;
         ScreenshotString = "";
    }
	
    document.getElementById("ScreenshotsHere").innerHTML = ScreenshotString;
}
 
Status
Not open for further replies.
Top