3
\$\begingroup\$

I have a list of if functions (checking if various spots in the room are empty) in one event. I want to check them ALL with an else statement (if none of the spots are cleared), and display a message. How would I do this?enter image description here

\$\endgroup\$

2 Answers 2

2
\$\begingroup\$

I do not know about game maker, but if it is as in the other programming languages, you must nest all the ifs, one inside the other.

Your former approach was:

If there is an object
    Start
    Create Instance
    End
If there is an object
    Start
    Create Instance
    End
//.... 
Else
    Start
    Do Something else
    End

You should try:

If there is an object
    Start
    Create Instance
    End
Else
    Start
    If there is an object
        Start
        Create Instance
        End
    Else
        Start
        If there is an object
            Start
            Create Instance
            End
        End
        Else
            Start
                Do Something Else.
            End
    End
//....
\$\endgroup\$
0
\$\begingroup\$

Gustavo Maciel wrote right answer. But I want add one more solution (sometime it can be very useful).

Using code it can be something like this:

var result = false;
if (statement)
{
    // action 1;
    result = true;
}
...
if (statement)
{
    // action N;
    result = true;
}

// no actions
if !result             // same with: if (result = false)
{
    // else action
}

P.S. I advise nevertheless to use a code, but not buttons. Solution of Gustavo Maciel via code:

if position_meeting(pos_x, pos_y, your_object)
{
    instance_create(pos_x, pos_y, blockObject);
    result = true;
}
else if position_meeting(pos_x, pos_y, your_object)
{
    instance_create(pos_x, pos_y, blockObject);
    result = true;
}
...
else if position_meeting(pos_x, pos_y, your_object)
{
    instance_create(pos_x, pos_y, blockObject);
    result = true;
}
else
{
    show_message("Your message");
}

Of course, here need to change all coords and object names.

btw,

else if (statement)
{
}

it same with

else
{
    if (statement)
    {
    }
}
\$\endgroup\$
1
  • \$\begingroup\$ Yep, this is it, but I tried to answer it only using "event" kinda code, like I saw in the Screenshot! If gamemaker has else ifs, then go for it! \$\endgroup\$ Jun 2, 2015 at 0:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .