• Hey! Guest! The 40th (!!!) GMC Jam will take place between February 25th, 12:00 UTC to March 1st 12:00 UTC. Why not join in this very special anniversary jam! Click here to find out more!

GMS 2.3+ Dialog Box

Hi

I'm trying to create a yes/no dialog box. If you selected yes a certain number of gems are subtracted from the player's gems and a character (bat) is unlocked. If you click on No then the dialogue should vanish..
There is something I'm missing and I was hoping somebody could give me a hand. The "No" part of the dialogue box isn't working. Wherever I click on the dialogue box it just unlocks the bat and the dialogue vanishes. Whether I click on
No or Yes it unlocks the bat and the dialogue vanishes.

Step:

GML:
if (mouse_x > 112 && mouse_y > 150 && mouse_x < 185 && mouse_y < 170 && query_batC == true)
    {
            
        show_debug_message("query bat no selected")
        query_batC = false;
        if (instance_exists(GemPackObject1)) { instance_destroy(GemPackObject1) }
        if (instance_exists(PurchaseMenuObject)) {    instance_destroy(PurchaseMenuObject) }
            
    }





if mouse_check_button(mb_left)
{
    //turn on menu
   if position_meeting(mouse_x, mouse_y, BatsFaceHiddenC)
   {
    //below doesn't execute
    show_debug_message("position meeting")
    //below doesn't execute
    
    show_debug_message("mouse check button")
    
    //Player.hasbatB = true;
    hasbatC = false
    query_batC = true;
   }

  //Unlock prompt? Below
 
    //clicked yes
     if mouse_check_button(mb_left)
     {
    
        //below yes clicked
        show_debug_message("Yes clicked on purchase object")
        if (mouse_x > 119 && mouse_y > 200 && mouse_x < 187 & mouse_y < 210 && query_batC == true)
        {
            //Yes selected
            show_debug_message("query bat yes selected"); //successful
            
            new_gems = global.gems - 1000
            if (new_gems > 0)
            {
                global.gems -= 1000
                
                global.select_bat = 3; //the bat to drop
                
                
                
                Player.hasbatC = true;
                query_batC = false;
                instance_destroy(GemPackObject1);
                if (!instance_exists(BatsFaceC))
                {
                    instance_create_depth(x, y, -1900, BatsFaceC)
                }
                instance_destroy(PurchaseMenuObject)
            }
            
            else
            {
                show_debug_message("Not enough gems")
                query_batC = false
                instance_destroy(GemPackObject1);
                if (last_menu_timer <= 0)
                {
                    draw_text_color(350, 650, "Not enough gems", c_black, c_black, c_black, c_black, 1)
                    last_menu_timer = room_speed
                }
            }
                    
            visible = false;
            //instance_destroy()
            
        
        }

 
        if (mouse_x > 112 && mouse_y > 150 && mouse_x < 185 && mouse_y < 170 && query_batC == true)
        {
            
            show_debug_message("query bat no selected")
            query_batC = false;
            if (instance_exists(GemPackObject1)) { instance_destroy(GemPackObject1) }
            if (instance_exists(PurchaseMenuObject)) {    instance_destroy(PurchaseMenuObject) }
            
        }
        
    }
}
Draw GUI:

Code:
/// @description Insert description here
// You can write your code in this editor


//print menu

  
//print menu
draw_set_font(Arial_Font_Modified)
if (query_batC == true && Player.hasbatC != true)
{
    
       /***********NEW CODE************/
 
 
    
    if (!instance_exists(GemPackObject1))
    {
       instance_create_depth(550,650,-1200,GemPackObject1);
    }
    
   if (!instance_exists(PurchaseMenuObject))
   {
       instance_create_depth(100, 200,-1200, PurchaseMenuObject);
   }
  
  draw_text_ext_transformed_color(100, 200, "3,000 Gems", 5, 300, 0.75, 0.75, 0, c_white, c_white, c_white, c_white, 1)

}

//}
/*
if (query_batB == false)
{
    show_debug_message("No query menu")
    if (instance_exists(GemPackObject1))
    {
        show_debug_message("Destroy gem pack")
        instance_destroy(GemPackObject1)
    }
}
*/
 
Last edited:
I do "yes/no" prompts this way. You can reuse them for any behavior you want, with any label and message you want. The basics go like this, you should look into it.

GML:
//Obj_poup create event

global.in_popup = true;            //Flag so you cant click other **** when it's in a popup

str_message = "";                //Holds the message
parent_id = noone;                //Holds the instance id of the thing that spawned the popup

alarm[0] = 2;                    //Create the clickable yes/no button
The Alarm[0] event can look like this
GML:
var _yes_btn = instance_create_layer(x-100, y+100, "Top", obj_popup_btn);
with(_yes_btn){
    label = "Yes";  
    parent_id = other.parent_id;  
}

var _no_btn = instance_create_layer(x+100, y+100, "Top", obj_popup_btn);
with(_no_btn){
    label = "No";  
    parent_id = other.parent_id;
}
And the left_release of the yes/no buttons (obj_popup_btn)
GML:
switch(label){
    case "Yes":    //Trigger parent event
        with(parent_id){
            event_user(0);                    //This is the meat and potatoes of the behavior tou want of your button
            }  
    break;
               
    case "No":
        show_debug_message("Nevermind...");    //You can popup another popup with just 1 button here, if you wish
        break;
}

if(instance_exists(obj_popup)){
    with(obj_popup){
        alarm[2] = 2;                //Destroy the popup in 2 steps, because this will turn the global popup flag false
    }
}

//Destroy ourself
alarm[0] = 1;

So when creating a popup you can do
GML:
var _popup = instance_create_layer(room_width/2, room_height/2, "Top", obj_popup);

with (_popup){
    parent_id = other.id;
    str_message = "IS THIS A POPUP?";
}
 
I don't understand this line:

var _popup = instance_create_layer(room_width/2, room_height/2, "Top", obj_popup);

What does "Top" mean. I got an error thrown.
 
change it to whatever top-most layer you have in your editor, or add
GML:
var _layer = layer_create(-9999, "Top");
before it.
This argument points to the layer you want to create your stuff on, either by string or ID
 
So say I have a room named DIalogueRoom and in there an asset layer is there named Top would that work?

SO this is what I have so far:

Draw GUI event for BatsFaceHiddenC object::

GML:
var _layer = layer_create(-9999, "Top");
var _popup = instance_create_layer(room_width/2, room_height/2, "Top", obj_popup);

with (_popup){
    parent_id = other.id;
    str_message = "IS THIS A POPUP?";
}
obj_popup create event:

Code:
/// @description Insert description here
// You can write your code in this editor
//Obj_poup create event

global.in_popup = true;            //Flag so you cant click other **** when it's in a popup

str_message = "";                //Holds the message
parent_id = noone;                //Holds the instance id of the thing that spawned the popup

alarm[0] = 2;                    //Create the clickable yes/no button
obj_popup alarm 0

Code:
/// @description Insert description here
// You can write your code in this editor
var _layer = layer_create(-9999, "Yes?");
var _yes_btn = instance_create_layer(x-100, y+100, "Yes?", obj_popup_btn);
with(_yes_btn){
    label = "Yes?"; 
    parent_id = other.parent_id; 
}

var _layer = layer_create(-9999, "No!");
var _no_btn = instance_create_layer(x+100, y+100, "No!", obj_popup_btn);
with(_no_btn){
    label = "No!"; 
    parent_id = other.parent_id;
}
obj_popup_btn left released:

Code:
/// @description Insert description here
// You can write your code in this editor
switch(label){
    case "Yes?":    //Trigger parent event
        with(parent_id){
            event_user(0);                    //This is the meat and potatoes of the behavior tou want of your button
            } 
    break;
              
    case "No!":
        show_debug_message("Nevermind...");    //You can popup another popup with just 1 button here, if you wish
        break;
}

if(instance_exists(obj_popup)){
    with(obj_popup){
        alarm[2] = 2;                //Destroy the popup in 2 steps, because this will turn the global popup flag false
    }
}

//Destroy ourself
alarm[0] = 1;
Nothing is happening though,. Thoughts?
 
Last edited:
https://dropmb.com/j98vB I made you a little package, just import in in a fresh project first to get your head around the process, then import it in your project.
You could basically do an idle clicker with just these things, lol

I would create the layer dynamically, honestly... a little bit more setup, but cleaner all in all, I think. Ensures there's no unwanted overlapping, and stuff..

By the way, press Enter to pop a popup!
 
https://dropmb.com/j98vB I made you a little package, just import in in a fresh project first to get your head around the process, then import it in your project.
You could basically do an idle clicker with just these things, lol

I would create the layer dynamically, honestly... a little bit more setup, but cleaner all in all, I think. Ensures there's no unwanted overlapping, and stuff..

By the way, press Enter to pop a popup!
That link sure has a lot of ads on it. Where is the direct link?
 
There's no ad on my end, and it downloads in like 0.2 seconds (but I use Norton, so it may block things). What file host website do you want?
 

TailBit

Member
There's no ad on my end, and it downloads in like 0.2 seconds (but I use Norton, so it may block things). What file host website do you want?
Pages like that makes sure not to give the uploader adds, so you would have to either look at your link in incognito or from another IP to see what it really shows.

@Master Cabalist Your original code didn't work right because of this line:
if (mouse_x > 119 && mouse_y > 200 && mouse_x < 187 & mouse_y < 210 && query_batC == true)
more specific, this part:
187 & mouse_y
..as the binary operator & is executed before comparing operations

Why not use:
if (point_in_rectangle(mouse_x,mouse_y,119,200,187,210) && query_batC)
.. just to avoid a few possible miss typos ?
 

Tyg

Member
Do you want something like this i just made
If you want it , i can give you the code
It has a mini-state machine
when you mouse over he asks if you want to buy a bat..i assumed a flying bat not a baseball bat...lol
when you click on him yes/no buttons come on
if you dont respond he times out
if no respond with your loss
if yes, gems are checked
if enough gem they are subtracted and the bat is sold
if not enough gems he responds
if you move the mouse off him dialogue dissapears
 

Attachments

Do you want something like this i just made
If you want it , i can give you the code
It has a mini-state machine
when you mouse over he asks if you want to buy a bat..i assumed a flying bat not a baseball bat...lol
when you click on him yes/no buttons come on
if you dont respond he times out
if no respond with your loss
if yes, gems are checked
if enough gem they are subtracted and the bat is sold
if not enough gems he responds
if you move the mouse off him dialogue dissapears
Sounds pretty neat. I'd like to try using your code for the dialogue.
 
Having some debugging problems:
GML:
Object: SellerObj Event: Create at line 2 : Cannot set a constant ("State") to a value
Object: NoObj Event: Left Pressed at line 5 : Assignment operator expected
Object: SellerObj Event: Create at line 4 : Cannot set a constant ("Gems") to a value
Object: SellerObj Event: Alarm 0 at line 3 : Cannot set a constant ("State") to a value
Object: SellerObj Event: Alarm 1 at line 3 : Cannot set a constant ("State") to a value
Object: SellerObj Event: Step at line 27 : Cannot set a constant ("State") to a value
Object: SellerObj Event: Left Pressed at line 5 : Cannot set a constant ("State") to a value
Object: SellerObj Event: Mouse Enter at line 3 : Cannot set a constant ("State") to a value
Object: SellerObj Event: Mouse Enter at line 7 : Cannot set a constant ("State") to a value
Changing State to MyState seems to have worked.

Now its giving me an error about a nonexistant sprite since there is a draw_self and no sprite assigned to the seller object?

@Tyg So in the whole scheme of things what role does Seller take? Do I drag it into the scene? How is everything hooked up?

@Tyg I'm getting this message when I start the game:

Code:
Object: SellerObj Event: Step at line 6 : Cannot set a constant ("Bubble_text") to a value
Object: SellerObj Event: Create at line 5 : Cannot set a constant ("Bubble_text") to a value
Object: SellerObj Event: Step at line 9 : Cannot set a constant ("Bubble_text") to a value
Object: SellerObj Event: Step at line 12 : Cannot set a constant ("Bubble_text") to a value
Object: SellerObj Event: Step at line 13 : Cannot assign to "Bubble_text" - it's a constant
Object: SellerObj Event: Step at line 31 : Cannot set a constant ("Bubble_text") to a value
Object: SellerObj Event: Step at line 34 : Cannot set a constant ("Bubble_text") to a value
Object: SellerObj Event: Step at line 37 : Cannot set a constant ("Bubble_text") to a value
Object: SellerObj Event: Step at line 41 : Cannot set a constant ("Bubble_text") to a value
Object: SellerObj Event: Step at line 44 : Cannot set a constant ("Bubble_text") to a value
 
Last edited:
@Tyg Problem with the code. When I click "No" the dialogue box disappears like its supposed to. When I click Yes though, it just disappears. So, this is

GML:
show_debug_message("MyState = buying")
Seller.MyState = "buying";
with(Seller) {
alarm_set(0, -1);
alarm_set(1, -1);
}
with(No) instance_destroy();

//
if (position_meeting(mouse_x, mouse_y, Yes))
{
    Seller.MyState = "buying"
}

if (instance_exists(Seller))
{

instance_destroy(Seller);
}

instance_destroy();
And this is Seller step event:

Code:
/// @description Insert description here
// You can write your code in this editor
switch(MyState)
{
case "idle":
B_text = "HEY BUDDY!\n Wanna buy a bat?";
break;
case "selecting":
B_text = "What'll it be?";
break;
case "waiting":
B_text = "Hmmm ?";
B_text += "\nCome on man,\nHaven't got all day!";
break;
case "buying":
    show_debug_message("Buying state case");
    if(global.gems >= 1000)
    {
        if(instance_exists(Bat))
        {
        with(Bat) instance_destroy();
        }
        global.gems += -1000; // Bye bye Gems
        show_debug_message("Subtracted Gems");
        MyState = "sold";
        show_debug_message("MyState set to sold")
        if (!instance_exists(BatsFaceB))
        {
            instance_create_depth(280,40,-2100, BatsFaceB)
        }
        else
        {
            MyState = "too_poor";
        }
    }
break;
case "too_poor":
B_text = "Your haven't got\nthe beans Man!";
break;
case "no_buy":
B_text = "Your loss, Man!";
break;
case "sold":
B_text = "Allright...\nShe's all yours\nenjoy";
SOLD = true;
break;
case "times_up":
B_text = "Maybe another time\nCYA Dude!";
break;
case "closed":
B_text = "What do you want?\nI sold you my best\nBAT (sniffle)";
break;
}
The debug message "Buying state case" in seller doesn't fire.
But the debug message "MyState = buying" in Yes does fire.?

(edit)

Ok. It seems to be working better. When I click the "Yes" on the button it subtracts gems and thanks you. But it doesn't unlock the bat. It shows a picture of the batface but when you click on the batface it doesn't do anything.

GML:
case "buying":
    show_debug_message("Buying state case");
    if(global.gems >= 1000)
    {
        if(instance_exists(Bat))
        {
        with(Bat) instance_destroy();
        }
        global.gems += -1000; // Bye bye Gems
        show_debug_message("Subtracted Gems");
        MyState = "sold";
        show_debug_message("MyState set to sold")
        //if (instance_exists(BatsFaceHiddenB))
        //{
        //    instance_destroy(BatsFaceHiddenB)
        //}
        if (!instance_exists(Bats2))
        {
            instance_destroy(BatsFaceHiddenB)
            inst = instance_create_depth(280,40,-3000, Bats2)
            inst.visible = true
            instance_destroy()
        }
        
        else
        {
            MyState = "too_poor";
        }
        instance_destroy(Yes)
        instance_destroy(No)
        instance_destroy(Seller)
    }
break;
 
Last edited:

Nidoking

Member
You're setting a variable in the Seller and then destroying the Seller. This is about the same as writing information in a notebook and then throwing the notebook in a fire. The information is gone. If there's something you want a Seller to do, it has to exist long enough to do that.
 
  • Like
Reactions: Tyg

Tyg

Member
Sorry, yes just drag the object in the room and assign a seller sprite to it(like the dino stand), No the seller stays, the bat is destroyed once sold
and yes/no dialogue is destroyed after selected, the text_bubble is just a sprite that gets activated when you enter the area
Hopefully that explains it

it is just an example that was whipped up and notice the "with (bat)" before the destroy
 
Last edited:

Tyg

Member
notice the "with (Bat)" in the original code i supplied, don't know what your trying to do
if it destroy the seller after the bat is sold then it would be destroyed right after the bat
if there are more bats then dont set the sold state or make another state sold out
 
Last edited:
Hi

Background: There is a bar at the top that is populated with good guy "Bats" The enemy that is spawned is the "Brains".

Dialogue Box: In the first level if you click on the locked Bats it shows dialogue box. You can click yes on the dialogue box and it unlocks the locked dialogue box.

Problem: First level works properly. However, in the second level when I click on the "Wind Bat" instead of dropping a bat it jumps to another level (level 5 i believe)

That's the jist of it. I'm not sure which code would help debug this, so let me know.

-TWRaven

(edit)

Could this code help?

GML:
/// @description Insert description here
// You can write your code in this editor
switch(MyState)
{
case "idle":
B_text = "HEY BUDDY!\n Wanna buy a bat?";
break;
case "selecting":
B_text = "What'll it be?";
break;
case "waiting":
B_text = "Hmmm ?";
B_text += "\nCome on man,\nHaven't got all day!";
break;
case "buying":
    show_debug_message("Buying state case");
    if(global.gems >= 1000)
    {
        if ((global.gems - 1000) <= 0)
        {
            MyState = "too_poor";
            instance_destroy(SellerC)
        }
        if(instance_exists(Bat))
        {
        with(Bat) instance_destroy();
        }
       
        global.gems += -1000; // Bye bye Gems
        show_debug_message("Subtracted Gems");
        MyState = "sold";
        show_debug_message("MyState set to sold")
        //if (instance_exists(BatsFaceHiddenB))
        //{
        //    instance_destroy(BatsFaceHiddenB)
        //}
        //if (!instance_exists(Bats2))
        //{
        instance_destroy(BatsFaceHiddenC)
        inst = instance_create_depth(480,40,-2100, BatsFaceC)  
        Player.hasbatC = true;
       
        //inst = instance_create_depth(280,40,-3000, BatsFaceHiddenB)
        //inst.visible = true
       
        //}
       
       
        instance_destroy(YesC)
        instance_destroy(NoC)
        instance_destroy(SellerC)
    }
break;
case "too_poor":
B_text = "Your haven't got\nthe beans Man!";
break;
case "no_buy":
B_text = "Your loss, Man!";
break;
case "sold":
B_text = "Allright...\nShe's all yours\nenjoy";
SOLD = true;
break;
case "times_up":
B_text = "Maybe another time\nCYA Dude!";
break;
case "closed":
B_text = "What do you want?\nI sold you my best\nBAT (sniffle)";
break;
}
Above is the step event for the Seller object.

Again, the problem is that when I click on the third bat (the wind bat) it brings up the dialogue box. If click on any part of the dialogue box instead of unlocking anything
it just jumps to the Jungle Level (level 5). However, clicking the wind bat in the first level works perfectly fine. I tried to copy the code from the first bat (that works) over
to the the wind bat but the problem endures.
 
Last edited:
@Tyg: I actually accidently created another thread so hopefully someone will merge them. (Done! ~Tsuk)
I'm having issues with the dialogue box. I have two levels involved.. The first level everything works fine. If I'm in the second level though, and click on my wind bat icon the dialogue pops up. If I click on the dialogue for the second level wind bat it just jumps me to level 5.

(edit)

So, it appeares that the bat bar (where you get your bats) is the only level that doesn't have some form of jumping. So if someone could help me and I fix the posted error
I think it will fix the other jumping errors.

(edit)

if(global.gems >= 1000)
{
if ((global.gems - 1000) <= 0)
{
MyState = "too_poor";
instance_destroy(SellerC)
}
if(instance_exists(Bat))
{
with(Bat) instance_destroy();
}

global.gems += -1000; // Bye bye Gems
show_debug_message("Subtracted Gems");
MyState = "sold";
show_debug_message("MyState set to sold")
//if (instance_exists(BatsFaceHiddenB))
//{
// instance_destroy(BatsFaceHiddenB)
//}
//if (!instance_exists(Bats2))
//{
//instance_destroy(BatsFaceHiddenC)
inst = instance_create_depth(480,40,-2100, BatsFaceC)
Player.hasbatC = true;
//crashing after it creates the BatsFaceC

//inst = instance_create_depth(280,40,-3000, BatsFaceHiddenB)
//inst.visible = true

//}

show_debug_message("Crafted BatsFaceC and at instance destroys")
instance_destroy(YesC)
instance_destroy(NoC)
instance_destroy(SellerC)
show_debug_message("Completely destroyed Seller")
}
 
Last edited:

Tyg

Member
Oh, if there is more than one bat type it would, because the sold flag was set after the first bat was sold, you could have another state, sold_out
when everything is sold, or have each bat have its own sold state
why are you destroying the seller if he has more to sell?
Sorry im not sure what your trying to do here anymore, the state logic flow works fine as well as the diagram i gave
Not sure what you mean by jumping, that would be a state on the player
 
Last edited:
Oh, if there is more than one bat type it would, because the sold flag was set after the first bat was sold, you could have another state, sold_out
when everything is sold, or have each bat have its own sold state
why are you destroying the seller if he has more to sell?
Sorry im not sure what your trying to do here anymore, the state logic flow works fine as well as the diagram i gave
Not sure what you mean by jumping, that would be a state on the player
Yeah there is more than one bat type. I'm not sure what you mean by setting the sold flag?
Ok. This might be complicated. Let me explain. First of all, the Seller has a sprite that is the background for the dialogue. So, when the Seller is created, the dialogue background and yes/no buttons are created. There is a unique Seller, Yes, and No objects for each type of bat. For example, the Lightning bat has a SellerB, YesB, and NoB. The next one over is the wind bat. It has a SellerC, YesC, and NoC. So the jumping behavior is this. I click on the greyed out bat face and it opens the dialogue box but then when I click on it then actual level jumps. What I mean by that is that you are suddenly (jump) transported to another part of the game. For example, if you click on the dialogue box while in the Forest Level it warps you to the Jungle Level.

I hope this makes sense. I destroy the Seller object because it has all the logic for the dialogue box.
The seller purchase is a one time thing for each bat. For example, once you click on the greyed out bat face the dialogue pops up for that bat, say lightning bat, and prompts you asking you if you want to buy. If you click yes, the bat face light up and the bat is visible for yes. You only need to unlock once.

Let me know if you need my code.

Thanks

Ted
 

Tyg

Member
Ah OK, so maybe make 3 separate seller objects, its the wind one that is giving you trouble?
each can have its unique code
you should only need one yes/no object as they just set a state. the yes/no can also be put right on the seller i just separated them for clarity and destroy when not needed
 
Yeah well I have 8 separate seller objects, one for each bat. The wind one is the one give. me trouble. That's the third one over (SellerC),
The bat B seems to work in every level so I tried to copy that code over to the BatC (wind bat) but it still is misbehaving.

(edit)

@Tyg I'm screwed. All my backups have your dialog code in them and I can't figure out what the issue is?
 
Last edited:
Ok. I'm completely stuck. I don't know how to proceed. Sometimes when I click the wind bat it drops the bat, sometimes it warps me to another level?? Is there behavior that this is indicative of.
 

Nidoking

Member
This is probably the result of a call to room_goto or room_goto_next. You'll need to find which call to one of those functions is happening when this happens, and then figure out why it's being called. Put a unique debug message before every call to either of those functions, everywhere. Don't leave a single one out. Then make the problem happen and see which message you get. Then trace backwards from there.
 
Top