Jump to content


Photo

Tooltip - Detecting if mouse is on an object


  • Please log in to reply
5 replies to this topic

#1 jhawks

jhawks

    GMC Member

  • GMC Member
  • 257 posts
  • Version:GM:HTML5

Posted 30 March 2012 - 08:30 AM

Hi all,

I have a working tooltip where if the mouse is on any object, it first checks if it has a description to show. If it does, it runs a script which displays the object's description.

Now, in order to do this, I had this code:

with (all)
{
    if (mouse_x >= x and mouse_x <= x + real(sprite_width) and mouse_y >= y and mouse_y <= y + real(sprite_height))
    {
        //For equipment
        if (description == "ITEM")
        {
            showItemTooltip(adjective, type, noun, effectType, value);
        }
        else
        {
            //For other objects
            if (description != "")
            {
                showTooltip(description, info);
            }
        }
    }
}

As you can see, this checks with ALL objects whether the mouse is on them or not.

However, sometimes, the game errors, saying that it cannot find the "description" variable. However, I went through EVERY object I had to ensure they had the "description" variable.

So... can anyone help me figure out what else could be the problem? I know it's something to do with this code, the way it checks if the mouse is on an object but I can't seem to figure it out.

Thanks.
  • 0

#2 amiel

amiel

    GMC Member

  • GMC Member
  • 1117 posts
  • Version:Unknown

Posted 30 March 2012 - 08:34 AM

with (all)

that's the problem,cause that applies to all of object and game maker checks for all object that hover with the mouse.
To solve it...Make a parent object only for those object that has a variable description.
OR you can also check first if variable description exists from within an object before applying it,so you don't get that error message.
so it should be like this:
with (tooltip_parent)
    if (mouse_x >= x and mouse_x <= x + real(sprite_width) and mouse_y >= y and mouse_y <= y + real(sprite_height))
    {
        if (description == "ITEM")
            showItemTooltip(adjective, type, noun, effectType, value);
        else
            if (description != ""
                showTooltip(description, info);
    }

:whistle:

Edited by amiel, 30 March 2012 - 08:42 AM.

  • 0

#3 greep

greep

    Menaces with Spikes

  • GMC Member
  • 2297 posts
  • Version:GM7

Posted 30 March 2012 - 08:42 AM

How about post the code on an object that supposedly doesn't have description but actually does? Keep in mind, if you're using var to declare a variable, it only exists in that code block.
  • 0

#4 jhawks

jhawks

    GMC Member

  • GMC Member
  • 257 posts
  • Version:GM:HTML5

Posted 30 March 2012 - 08:43 AM

Yeah I know. That's why every single object in my game has:

description = "";

I wanted to avoid it but the people here said that it wasn't a bad thing to insert that variable on each object.

BTW, I'm using HTML5 with latest update and in case anyone asks, despite what the wiki says... "sprite_width" does not returns a 0.

EDIT:

@amiel
How do you check if a variable exists?

@greep
Sure

[CREATE EVENT]
description = "";

Edited by jhawks, 30 March 2012 - 08:45 AM.

  • 0

#5 greep

greep

    Menaces with Spikes

  • GMC Member
  • 2297 posts
  • Version:GM7

Posted 30 March 2012 - 08:46 AM

haha okay. Well to check if the variable exists, just do variable_local_exists()
  • 0

#6 jhawks

jhawks

    GMC Member

  • GMC Member
  • 257 posts
  • Version:GM:HTML5

Posted 30 March 2012 - 08:51 AM

@greep
Ah that seems to have fixed the problem! Lucky there was one instance where I could consistently repeat the error (despite it being tedious)

Thanks a lot for that guys ^_^
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users