• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

need help with chainbolt script

A

AlexZ

Guest
Dear smart people, pls help me to figured out how I can achieve this chainbolt script.

By chainbolt I mean an object that hits the neares instance of a certain type (I'll refert to this as "target"), interacts with it and then goes for the next one.

My Problem here is that instance_nearest will refert to the same target that the chainbolt already hit, what I need is a script that returns the second nearest instance.

My approach is the following:

-create an array to store all possible targets id, x, y and distance to the chainbolt object during its creation.
-create a ds_list to store the distances and sort it, so i can get its second position somehow

what I've done so far is written below, but:
1. I'm afraid it has errors, because I don't fully understand how Instance_id works
2. I can't figure out how to store the actual instances in an array instead of just their ID
3. The ds_lists sorts the distances to the chain bolt origin, but I have no Idea how i can let those reference back to the actual instance
4. How do I even let my for-loop only count the instances of a certain parent object instead of just any instance? I found the command instance_id in the documentation without any reference to an object and didnt really understand the example

this script is to be called in the creation event of the chainbolt if the attack has already hit a target

/// scr_chainbolt_target

var target_array
var target_dslist = ds_list_create;

for (i = 0; i < instance_number(obj_enemyparent) ; i++)
{

with obj_enemyparent.instance_id
{
target_array[i, 0] = x;
target_array[i, 1] = y;
target_array[i, 2] = abs(other.x - x) + abs(other.y - y);

target_dslist[|i] = abs(other.x - x) + abs(other.y - y);


};

};

ds_list_sort(target_dslist, true);
/// everything here is totally wrong
return target_dslist[|1];



I really appreciate any help, this game is a small scale action shooter that is already gonna be much fun and that I wanna upload for free when its finished. but i still need to learn a ton about gml.
 
Top