ID:138850   Oct 18 2011, 11:25 am Code: ``` New() // New Proc ..() // Biz as usual src.AI() // Begin AI AI() // AI Code var/obj/Gold/T // Define T var/X = 100 // Define X to be 100 for(var/obj/Gold/A in world) // Loop through gold in world if(X > get_dist(src,A)) // If it's closer than the current X value (Changes with target) T = A // Make Target that gold mine X = get_dist(src,A) // Define X as the distance if(isnull(T)) // If T is null world << "[src] was unable to find a target!" // Debug else // If T is not null src.Target = T // Define Target to be that gold mine world << "[src] has targetted the [src.Target]" // Debug walk_towards(src, src.Target, 0, src.MoveDelay) // Walk to it world << "[src] is walking" return ``` Problem description: I have 3 rocks on the map, it should be able to find at least one target, but target is always null. Any ideas on why?
 <-> Oct 18 2011, 11:54 am Lugia319 wrote: Code: ```> New() // New Proc> ..() // Biz as usual> src.AI() // Begin AI>> AI() // AI Code> var/obj/Gold/T // Define T> var/X = 100 // Define X to be 100> for(var/obj/Gold/A in world) // Loop through gold in world> if(X > get_dist(src,A)) // If it's closer than the current X value (Changes with target)> T = A // Make Target that gold mine> X = get_dist(src,A) // Define X as the distance> if(isnull(T)) // If T is null> world << "[src] was unable to find a target!" // Debug> else // If T is not null> src.Target = T // Define Target to be that gold mine> world << "[src] has targetted the [src.Target]" // Debug> walk_towards(src, src.Target, 0, src.MoveDelay) // Walk to it> world << "[src] is walking"> return> ``` Problem description: I have 3 rocks on the map, it should be able to find at least one target, but target is always null. Any ideas on why? Doesn't for() choose the closest target by default?
 <-> Oct 18 2011, 12:42 pm In response to Kumorii ``` AI() // AI Code var/X = 100 // Define X to be 100 for(var/obj/Gold/A in world) // Loop through gold in world if(X > get_dist(src,A)) // If it's closer than the current X value (Changes with target) X = get_dist(src,A) // Define X as the distance if(!A) // If T is null world <
 <-> Oct 18 2011, 5:06 pm Yeah I can't see anything immediately wrong with it. I assume already that the gold is within 100 steps of the AI as well. Try just after the for loop finding gold/A, just having another debug message announcing it has found something, and if it has then the issue is with the algorithm (but again I don't see anything wrong with it), and otherwise its just flat out not finding gold.
 <-> Oct 19 2011, 4:58 pm In response to Trickykitty Turns out my original code was good, yours is wrong. Yours isn't wrong, but there are some unnecessary bits. Turns out the problem was in the New() procedure for the Miner.
 <-> Oct 20 2011, 8:07 am In response to Kumorii You're probably thinking of looping through view()-type procs, which return a list of atoms in order of distance. A for(x in list) statement simply loops from the beginning of a list. Also, just throwing this out there. ```var obj/Gold/Tfor(T in range(100, src)) breakif(T) Target = T walk_to(src, Target, 0, MoveDelay) ```