GameMaker "Look Command" How to succesfully draw a string from collision_point_list?

I've been trying to implement a look command in my game, similar to what you'd find in Dwarf Fortress. An X appears on the screen, moves around just like the player, and whatever is underneath the X, has it's name displayed in the top left.

I've tried numerous different codes, each yielding different results. I didn't think to save some of them unfortunately, so this is the only one I got to show for. But this is in my Draw GUI event for my "X Cursor" object:

Code:
if !place_empty(x,y,all){
var obj,notme,i;
    obj = all;
    notme = true;
    global.ObjList = ds_list_create();

    i = collision_point_list(x,y,obj,false,notme,global.ObjList,true);
    ds_list_add(global.ObjList,i);

    if obj == noone {
    ds_list_empty(global.ObjList);
    show_debug_message("Empty")
}

// now actually draw the items
if collision_point_list(x,y,obj,false,notme,global.ObjList,false) != noone {
for(var j=0; j < ds_list_size(global.ObjList); j += 1){
    if variable_instance_exists(global.ObjList,"Name") {
    draw_text(50, 30, string(global.ObjList.Name)) 
    show_debug_message("Text Drawn");
    }
}
}
}
All of my objects have a variable in them named "Name". And name, always gives out a string with their name, as in Name = "Skeleton". So great, but this code only flashes 1 string of "Skeleton" in the upper left screen before disappearing immediately. In my debug window, it also displays "Text Drawn" twice, and only ever twice. Never does it display "Empty". So this is all very confusing to me.

I tried using global.ObjList[|j] or [|i], but that actually makes it worse. It doesn't even display "Text Drawn" or flash the string.

I'm trying to make it so that, whenever my X is highlighted over no object at all, no text is displayed. and when it IS highlighting an object, it'll display the string from every object in that positions Name variable. I'd really appreciate some help, thanks!

GMS2 IDE v2.2.5.481 Runtime v.2.2.5.378
 
Last edited:

woods

Member
something like this?

each object you want to have the popup displayed, would have a variable

name = whatever

and in the object draw event
GML:
// wouldnt this draw a "name popup" when the mouse hovers over the object?

if (position_meeting(mouse_x, mouse_y, id))
{
draw_text(x,y,""+string(name));
}
else
{
draw_self();
}
 
something like this?

each object you want to have the popup displayed, would have a variable

name = whatever

and in the object draw event
GML:
// wouldnt this draw a "name popup" when the mouse hovers over the object?

if (position_meeting(mouse_x, mouse_y, id))
{
draw_text(x,y,""+string(name));
}
else
{
draw_self();
}
Close, but no cigar. It's similar to my first attempt, and I still tried just to see for kicks but it gave me this error:

Variable obj_Selector.Name(100017, -2147483648) not set before reading it.
at gml_Object_obj_Selector_Draw_0 (line 6) - draw_text(x,y,""+string(id.Name));

Tried using both just: string(Name) and string(id.Name). Same error. I've gotten this error other times before, and I get that it's gamemaker saying, since there's no Name variable in my cursor selector object, it's null. But that's the problem. I'm trying to get the Name variable from every other object, not my cursor.
 

woods

Member
a simple text on hover, shouldnt be complicated ;o)

are you putting this bit in the selector or in all the other objects?
how i see this working is having this bit of code in the objects to be hovered on... and simply checking collision from the mouse/selector object.


i dont see how this DOESNT work ..haha

obj_thing
create event
Code:
name = "whatever";
obj_thing
draw event
Code:
/// draw on hover

if (place_meeting(x,y, obj_selector))
{
draw_text(x,y,"name: "+string(name));
}
draw_self();
edit:
im a dumbazz ;o) forgot the quotes around the string in the create event

edit edit:
also switch position meeting for place meeting... position meeting recognizes just the x/y point.. not the whole sprite ;o)
 
Last edited:
a simple text on hover, shouldnt be complicated ;o)

are you putting this bit in the selector or in all the other objects?
how i see this working is having this bit of code in the objects to be hovered on... and simply checking collision from the mouse/selector object.


i dont see how this DOESNT work ..haha

obj_thing
create event
Code:
name = whatever;
obj_thing
draw event
Code:
if (position_meeting(x,y, obj_selector))
{
draw_text(x,y,""+string(name));
}
else
{
draw_self();
}
Oh wow, I feel dumb now haha. I hadn't even thought of putting code in each object. Yes! That works really nice, thank you so much. Although I see some problems that might come out of this. The text is all drawn in the same position in each of the codes, so what if I wanted to display multiple names? As in theres 3 different enemies on the same tile? My plan, is this selector object is used for multiple commands that require selecting another object. So talking, looking, attacking, etc. The general consistent bit behind all of those, is you have a cursor, can hover over objects to see what they are, and potentially scrolling through the list displayed/selecting one. I think that's where I'd have to create a DS_List, and iterate through it, no?
 

woods

Member
yea i can see where stacking units would be an issue..
my standard mode of operation is get it working with one.. then adjust to get it working with two.
unfortunately i am deff not the guy to talk to about arrays and lists and such.. i can muck thru some things.. but am not qualified in that dept.
hopefully somebody with more experience comes thru and helps us out ;o)
 
yea i can see where stacking units would be an issue..
my standard mode of operation is get it working with one.. then adjust to get it working with two.
unfortunately i am deff not the guy to talk to about arrays and lists and such.. i can muck thru some things.. but am not qualified in that dept.
hopefully somebody with more experience comes thru and helps us out ;o)
That's alright I getcha. Like you said though, that first step helps out a lot already so I'll try and mess with arrays and lists. Thanks again đź‘Ť
 
Top