• Hey! Guest! The 37th GMC Jam will take place between May 28th, 12:00 UTC and June 1st, 12:00 UTC. Why not join in! Click here to find out more!

How to connect two objects?

omid

Member
What do I need to do to connect the objects and the line between them?
for skill tree game

if mouse_check_button_pressed(mb_left)
{
i=instance_nearest(x,y,Cyc)
draw_line_width_color(Cyc.x,Cyc.y,i.x,i.y,2,random(c_blue),random(c_red));
}
 

FrostyCat

Member
You're doing an awful job describing what you want, as I have no idea what a "skill tree game" is. Until you explain yourself better, I can only rehash your broken code.

Create:
Code:
inst_linked = noone;
Step:
Code:
if (mouse_check_button_pressed(mb_left)) {
  inst_linked = instance_nearest(x, y, Cyc);
}
Draw:
Code:
if (instance_exists(inst_linked)) {
  draw_line_width_color(x, y, inst_linked.x, inst_linked.y, 2, c_blue, c_red);
}
Also, you need to read this article: What's the difference: Objects and instances
NEVER access a single instance by object ID if multiple instances of the object exist. This includes attempts to reference or set object.variable (which is inconsistent across exports) and using with (object) to apply actions to it (this encompasses all instances of the object instead of just the one you want). Verbally, "Dog's colour" makes sense with one dog, but not with multiple dogs.

Corollary: NEVER set or use an instance's own variables with object.variable. An instance's own variables can be referenced as-is without dot prefixes. DO NOT use self. If multiple instances of the object exists, you might end up setting the value for all instances or for some other instance (depending on the export).
 
Top