If(true){ doesnt work?

I have a game, and I want it to be pausable, so I put all of the game’s code into an if statement, and I noticed it malfunctioned. I then changed the if statement to if(true){ yet the code still didn’t work properly. Putting code within if(true){ should be the same as not putting it in, yet the code acts differently! Does anyone know why?

Putting [font=monospace]true[/font] as the boolean in a condition means it will always evaluate to [font=monospace]true[/font], and therefore always execute. So, putting [font=monospace]if (false) {}[/font] is probably what you’re looking for (the code will then not be executed at all).

No, I want the code to execute… I put it in if(true){ because it didn’t work when I put it in if(active){, whicle active was set to true. When I put it in if(active){, it didn’t work correctly, which doesn’t make sense… it behaves the same way if I put it in if(true){, which makes even less sense!

Does the containing block execute? Try producing some output in the containing code.

What is the containing code, anyways?

[quote=Jeff Wheeler;2334507]Does the containing block execute? Try producing some output in the containing code.

What is the containing code, anyways?[/quote]

the code is bassically like this (it’s within an onClipEvent(enterFrame){, and active is defined within an onClipEvent(load){)

if(active){
draws stage…
allows user to control character…
etc…
}

active is [U]currently[/U] always set to true, so logically the code should execute as it would without the if statement, yet it doesnt… the stage doesnt get loaded and the character starts behaving abnormally!

trace active before the IF construct, and trace within it to find out the values of what’s going on within it, if anything at all.

doing so only returns true, but that’s besides the point. The problem is that even if(true){, which SHOULD be the same as nothing at all, modifies the way the code works!

Well, I still don’t understand the problem, but I was able to find a decent solution.
I put:

if(!active){
return;
}

I put the code I want to be accessed ONLY while active after if, and code that can be accessed while active or !active before it!

Does anyone know if this method can cause any problems?

that’s the same as if(false) as !true = false. (! means not)

i dont think that you should simply put if(true) but more along the lines of
if(running==true) that way you can easily change the paused value easily.

that was only used for him to test.