Clicking a set of objects and making another appear.

C

celiaak

Guest
I am very new to Game Maker and don't seem to find the right way to solve this:
I have 5 objects in a room, and need another object (or text) to appear only after all 5 were clicked (as, per example, a clickable object to move to another room).
What is the better way to do this?
 

XirmiX

Member
Well, you could have an integer-value variable, which would start out at 0 and increment each time you click an object that hasn't already been clicked with an if statement (whether an object has been clicked, you could determine through having a boolean variable for each clickable object, which would be set to true at first and false).

Create event for the 6th text object
Code:
texts_clicked = 0;
Create event for the 1st - 5th text object(s)
Code:
clickable = true;
Step event for the 1st - 5th text object(s)
Code:
if [mouse cursor clicks on instances of certain object(s). This isn't actually a code part within the square brackets, but because this is a bit complex, I'd rather if you let me know whether you'd want me to elaborate on this]
{
    if clickable != false
    {
        [6th text object instance name/position*].texts_clicked++;
    }
}
*Position of an instance name can be deciphered through setting a variable (can be a temporary var variable in this scenario, I think) as instance_number() and text

If you ever wanted to know whether a piece of text was clicked, you could then make a check on whether that object's (or, I'm guessing, rather the instance's) variable is set to true, or may be false instead, and then have something be done afterwards like:

Step event for the 1st - 5th text object(s)
Code:
if clickable == false
{
    //whatever you want to happen next
}
I may be wrong on some of these and there may be more effective methods to do this, but this is just off the top of my head. Hope this helps :)
 
C

celiaak

Guest
Hi, thank you so much for your help.

I did this for Step event for the 1st - 5th text object(s):

if mouse_check_button_pressed(mb_left)
{
if clickable != false
{
(obj_seta).texts_clicked++;
}

}


Have not added the code
if clickable == false
{
//whatever you want to happen next
}

because I don't want nothing to happen.

When I run the game, I have this error when I click any objects:


___________________________________________
############################################################################################
FATAL ERROR in
action number 1
of Step Event0
for object obj_heart:

Unable to find any instance for object index '18' name 'obj_seta'
at gml_Object_obj_heart_StepNormalEvent_1 (line 5) - (obj_seta).texts_clicked++;
############################################################################################


I have created obj_seta as the 6th object that will appear after all other were clicked. For the moment it only has the code
texts_clicked = 0;

I'm not sure what is missing.
 
Top