M
mtski
Guest
Hi everyone,
I am trying to build a quick prototype game for learning purposes without the need for tutorials to encourage free based thinking, however, I have been stuck the last few days trying to find a solution to checking multiple units being selected and following mouse input commands.
Basically, I have a parent object named (obj_unit) and the only child at the moment named (obj_boxy). I am attempting to have a single (obj_mouse) object handle all the code to issue instructions to individual instances of the child objects by using the parent object for reference. ie "with(obj_unit)"
I have been able to detect collisions using the collision_rectangle function to turn on a variable named "selected" within the individual instances, but I am unable to get them to move independently of one another. All I have been able to accomplish with this is to get all instances to move when one particular instance was selected(I think the instance with the lowest number id_number 100001).
I have looked into this and have seen posts about using arrays or ds_lists to keep track of selected instances, but have no idea how to implement this. Which option would be most efficient and how can I separate commanding the id of instances rather than all instances of the parent?
Code is provided below within the "Draw Event" of obj_mouse. Thank you for reading my post and for any guidance.
------------------------------------------------------------------------------------------------------------------------
NVM! I was able to resolve using arrays to assign instances within.
I am trying to build a quick prototype game for learning purposes without the need for tutorials to encourage free based thinking, however, I have been stuck the last few days trying to find a solution to checking multiple units being selected and following mouse input commands.
Basically, I have a parent object named (obj_unit) and the only child at the moment named (obj_boxy). I am attempting to have a single (obj_mouse) object handle all the code to issue instructions to individual instances of the child objects by using the parent object for reference. ie "with(obj_unit)"
I have been able to detect collisions using the collision_rectangle function to turn on a variable named "selected" within the individual instances, but I am unable to get them to move independently of one another. All I have been able to accomplish with this is to get all instances to move when one particular instance was selected(I think the instance with the lowest number id_number 100001).
I have looked into this and have seen posts about using arrays or ds_lists to keep track of selected instances, but have no idea how to implement this. Which option would be most efficient and how can I separate commanding the id of instances rather than all instances of the parent?
Code is provided below within the "Draw Event" of obj_mouse. Thank you for reading my post and for any guidance.
------------------------------------------------------------------------------------------------------------------------
Code:
/// @description Insert description here
// You can write your code in this editor
var mx = mouse_x
var my = mouse_y
var c = c_black
if mouse_check_button_pressed(mb_left) {
mxt = mx;
myt = my;
}
if (mouse_check_button(mb_left) and mouseCommand = 0) {
draw_rectangle_color(mxt,myt,mx,my,c,c,c,c,1)
}
if (mouse_check_button_released(mb_left) and mouseCommand = 0) {
var sa_mxt = mxt
var sa_myt = myt
var sa_mx = mx
var sa_my = my
var instcount = instance_number(obj_unit)
show_debug_message("instcount = " + string(instcount))
with (obj_unit) {
var inst = collision_rectangle(sa_mxt,sa_myt,sa_mx,sa_my,id,0,0)
if (inst = id) {
selected = 1
}
else selected = 0
}
if (inst != noone) mouseCommand = 1
}
NVM! I was able to resolve using arrays to assign instances within.
Last edited by a moderator: