Shoutbox

Public variables... - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Thread: Public variables... (/showthread.php?tid=78737)

Public variables... by Toneo on 11-04-2007 at 06:45 PM

Hi, I need help...

I have a variable declared outside of my function. However, it reads this variable from inside the function but in that function or any other function it won't change it. I have a boolean...

allow = true;

function blahBlah()
{
...stuff
if (stuff) { if (allow = true) { stuff } else { stuff } }
}

function otherStuff()
{
allow = false;
}

So when I do blahBlah() it works perfectly, When I change it however to false using otherStuff, and then use blahBlah, it still thinks that allow is true. Which it shouldn't be..


RE: Public variables... by roflmao456 on 11-04-2007 at 06:54 PM

try "var allow = true"

and also, in your if statement, it should be == and not = otherwise it will always return true. ;)


RE: Public variables... by Toneo on 11-04-2007 at 06:55 PM

I already have var in front.

Ha, I'm such an idiot. I should have == not =. I always make those mistakes... :D


RE: Public variables... by FlashTato on 11-04-2007 at 07:18 PM

As said by roflmao456, if you use the EQUAL (=) operator that will return always true as you are going to assign a value to the var.

For comparing 2 vars you should use the IS_EQUAL operator (==).

code:
var foo = true;  //Declare a variable statement

if(foo == true){ //or simply if(foo)...
//Your code
}


quote:
I already have var in front.

That doesn't matter. ;)
RE: Public variables... by Toneo on 11-04-2007 at 07:21 PM

Yes. I hate making these mistakes. Heh, Thanks for pointing it out though. Works perfectly.

= is the variable assignment operator
== checks equality of one to the other