# If(true){ doesnt work?

**URL:** <https://forum.kirupa.com/t/if-true-doesnt-work/261940>\
**Category:** Uncategorized\
**Created:** [June 2, 2008, 1:18am UTC](https://forum.kirupa.com/t/if-true-doesnt-work/261940 "2008-06-02T01:18:06Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ph03nix](https://avatars.discourse-cdn.com/v4/letter/p/a8b319/32.png) [@Ph03nix](https://forum.kirupa.com/u/Ph03nix)\
**Post date:** [June 2, 2008, 1:18am UTC](https://forum.kirupa.com/t/if-true-doesnt-work/261940/1 "2008-06-02T01:18:06Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Jeff\_Wheeler](https://avatars.discourse-cdn.com/v4/letter/j/59ef9b/32.png) [@Jeff\_Wheeler](https://forum.kirupa.com/u/Jeff_Wheeler)\
**Post date:** [June 2, 2008, 1:19am UTC](https://forum.kirupa.com/t/if-true-doesnt-work/261940/2 "2008-06-02T01:19:46Z")

</div>

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).

---

<div class="post-metadata">

**Author:** ![Ph03nix](https://avatars.discourse-cdn.com/v4/letter/p/a8b319/32.png) [@Ph03nix](https://forum.kirupa.com/u/Ph03nix)\
**Post date:** [June 2, 2008, 1:22am UTC](https://forum.kirupa.com/t/if-true-doesnt-work/261940/3 "2008-06-02T01:22:15Z")

</div>

> [@Jeff Wheeler;2334504](#):
>
> Putting [FONT=monospace]true[/FONT] as the boolean in a condition means it will _always_ evaluate to true, and thus 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!

---

<div class="post-metadata">

**Author:** ![Jeff\_Wheeler](https://avatars.discourse-cdn.com/v4/letter/j/59ef9b/32.png) [@Jeff\_Wheeler](https://forum.kirupa.com/u/Jeff_Wheeler)\
**Post date:** [June 2, 2008, 1:23am UTC](https://forum.kirupa.com/t/if-true-doesnt-work/261940/4 "2008-06-02T01:23:40Z")

</div>

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

What is the containing code, anyways?

---

<div class="post-metadata">

**Author:** ![Ph03nix](https://avatars.discourse-cdn.com/v4/letter/p/a8b319/32.png) [@Ph03nix](https://forum.kirupa.com/u/Ph03nix)\
**Post date:** [June 2, 2008, 1:26am UTC](https://forum.kirupa.com/t/if-true-doesnt-work/261940/5 "2008-06-02T01:26:47Z")

</div>

[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!

---

<div class="post-metadata">

**Author:** ![McGuffin](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/mcguffin/32/408_2.png) [@McGuffin](https://forum.kirupa.com/u/McGuffin)\
**Post date:** [June 2, 2008, 1:36am UTC](https://forum.kirupa.com/t/if-true-doesnt-work/261940/6 "2008-06-02T01:36:37Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Ph03nix](https://avatars.discourse-cdn.com/v4/letter/p/a8b319/32.png) [@Ph03nix](https://forum.kirupa.com/u/Ph03nix)\
**Post date:** [June 2, 2008, 1:39am UTC](https://forum.kirupa.com/t/if-true-doesnt-work/261940/7 "2008-06-02T01:39:27Z")

</div>

> [@McGuffin;2334511](#):
>
> 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!

---

<div class="post-metadata">

**Author:** ![Ph03nix](https://avatars.discourse-cdn.com/v4/letter/p/a8b319/32.png) [@Ph03nix](https://forum.kirupa.com/u/Ph03nix)\
**Post date:** [June 2, 2008, 9:00pm UTC](https://forum.kirupa.com/t/if-true-doesnt-work/261940/8 "2008-06-02T21:00:19Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![nathan99](https://avatars.discourse-cdn.com/v4/letter/n/96bed5/32.png) [@nathan99](https://forum.kirupa.com/u/nathan99)\
**Post date:** [June 3, 2008, 1:08am UTC](https://forum.kirupa.com/t/if-true-doesnt-work/261940/9 "2008-06-03T01:08:11Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![cooldude88](https://avatars.discourse-cdn.com/v4/letter/c/e0b2c6/32.png) [@cooldude88](https://forum.kirupa.com/u/cooldude88)\
**Post date:** [June 3, 2008, 3:37am UTC](https://forum.kirupa.com/t/if-true-doesnt-work/261940/10 "2008-06-03T03:37:12Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![nathan99](https://avatars.discourse-cdn.com/v4/letter/n/96bed5/32.png) [@nathan99](https://forum.kirupa.com/u/nathan99)\
**Post date:** [June 3, 2008, 11:26pm UTC](https://forum.kirupa.com/t/if-true-doesnt-work/261940/11 "2008-06-03T23:26:15Z")

</div>

that was only used for him to test.
