A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: 'else' encountered without matching 'if'?

  1. #1
    Member
    Join Date
    Jul 2012
    Posts
    71

    'else' encountered without matching 'if'?

    I attempted to make my own code....
    but ran into a problem...
    heres my code:

    Actionscript Code:
    on(release)
    {
     hp += 50;
    day += 1;
    {
    if (day=30)
    {
    else
    this.enabled = false;
    }
    }
    }

  2. #2
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    I think you might mean something like this

    Actionscript Code:
    on (release) {
        if (day == 30)
        {
            hp += 50;
            day += 1;
        }
        else
        {
            this.enabled = false;
        }
    }

  3. #3
    Member
    Join Date
    Jul 2012
    Posts
    71
    thank you
    but do you know why my button isn't working? I added this code to my button:
    on (release)
    {
    if (exp == 0)
    {
    hp -= 10;
    _root.gotoAndPlay("talk 1");
    }
    else if(hp<10)
    {
    _root.gotoAndPlay ("no hp left");
    }
    }

    but when I test my game, the button doesn't go to the talk frame....

  4. #4
    Senior Member Steven FN's Avatar
    Join Date
    Mar 2010
    Location
    CA, USA
    Posts
    276
    Your code looks like it should work. My only guess is that the variable "exp" is not being set to the value of 0. Trace out the variables to make sure they are correct - trace(exp);
    Last edited by Steven FN; 08-27-2012 at 05:44 PM.

  5. #5
    Member
    Join Date
    Jul 2012
    Posts
    71
    thank you, the problem was that I hadn't even declared my exp variable

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center