P
Pixels_Everywhere
Guest
Im trying to count how many units I am selecting. I have been trying for about 3 hours and I haven't managed to get it to work. I have tried mostly arrays and for loops.
// Ship list
global.ship_list_i = instance_number(obj_ship); // this is the counter of unit instances
for (i = 0; i < global.ship_list_i; i += 1)
{
global.ship_list[i] = instance_find(obj_ship,i); // here id of the instance is saved in an array
}
var i = 0, j = 0, k = 0, l = 0;
for (i = 0; i < global.ship_list_i; i += 1)
{
if collision_circle(x,y,range,(global.ship_list[i]),false,true) // checks if the unit is in collision
{
if (global.ship_list[i]).player = player // checking if the unit belongs to the same player / is it friendly or not...
{
in_range_friend[j] = global.ship_list[i]; // save the id of friendly unit into friendly units array
j += 1; // increase friendly units counter
continue;
}
else
{
if (global.ship_list[i]).type = 1
or (global.ship_list[i]).type = 3 // checking if enemy unit is a fighting nit or not... variable "type" defines the type of unit the instance is "acting"
{
in_range_fighter[k] = global.ship_list[i]; // save the id of enemy fighter unit unit into array
k += 1;
continue;
}
else
{
in_range_nfighter[l] = global.ship_list[i]; // save the id of enemy non fighter unit unit into array
l += 1;
continue;
}
}
}
}
in_range_friend_i = j; // saving counter var - this is a number of in range friendly units...
in_range_fighter_i = k;
in_range_nfighter_i = l;
var i, j;
for (i = 0; i < global.ship_list_i; i += 1)
{
if (global.ship_list[i]).selected
{
j += 1;
}
}
selected_i = j;
Ok! If you'll have any problems with implementing my code let me know...Hi, Smiechu. thank you for replying! No, this is not my first time using GM. I have been using it for around 3 years. And dont worry, im not just copying and pasting code
Ok, im having a problem with the j var in your last little block of code. Even tho i am assigning it as a var, its still seems to think it doesnt exist. -.-Ok! If you'll have any problems with implementing my code let me know...
ahh... sorryOk, im having a problem with the j var in your last little block of code. Even tho i am assigning it as a var, its still seems to think it doesnt exist. -.-
var j=0;