aliasmask wrote:There are a bunch of ways to post the value before the if. Here is a quick way:
Code: Select all
[dialog("D"): {[r: maxdist],[r: dislist]}]
This only works within 1 code level, not 2. You can also use input or just put [r: varName] if you don't have the block with hidden output, but that only works if it doesn't error.
Ok so here is the code as it stands now, currently it does not produce an error and that only happens after I took the if statement out.
Code: Select all
[h: citylist = getWithStateNames("City")]
[h: target = "The Party"]
[h: dislist = ""]
[h: citynamelist = ""]
[h, foreach(city, citylist, ""),CODE:
{
[h: distance = getDistance(target, 1, city, "NO_GRID")]
[h: distance = round(distance,0)]
[h: dislist = listAppend(dislist,distance,",")]
[h: citynamelist = listAppend(citynamelist,city,",")]
}]
[h: counter = 0]
[h: citycount = listCount(citylist)]
[h: currentcity = ""]
[h: maxdist = 24500]
[h: currentcity = ""]
[r, while (citycount >= counter),CODE:
{
[h: xdist = listGet(dislist, counter)]
[h: xname = listGet(citynamelist, counter)]
[h: xdist = number(xdist)]
[h: maxdist = number(maxdist)]
[dialog("D"): {[r: maxdist], [r: dislist]}]
[h: counter = counter +1]
}]
Now I am positive that the numbers are indeed numbers at this point. But the problem is that even so, the following code produces an error:
Code: Select all
[h: citylist = getWithStateNames("City")]
[h: target = "The Party"]
[h: dislist = ""]
[h: citynamelist = ""]
[h, foreach(city, citylist, ""),CODE:
{
[h: distance = getDistance(target, 1, city, "NO_GRID")]
[h: distance = round(distance,0)]
[h: dislist = listAppend(dislist,distance,",")]
[h: citynamelist = listAppend(citynamelist,city,",")]
}]
[h: counter = 0]
[h: citycount = listCount(citylist)]
[h: currentcity = ""]
[h: maxdist = 24500]
[h: currentcity = ""]
[r, while (citycount >= counter),CODE:
{
[h: xdist = listGet(dislist, counter)]
[h: xname = listGet(citynamelist, counter)]
[h: xdist = number(xdist)]
[h: maxdist = number(maxdist)]
[if(maxdist >= xdist),CODE:
{
[maxdist = xdist]
[currentcity = xname]
};
{}]
[h: counter = counter +1]
}]
With that error reading: Error in body of roll. Statement options (if any): r, while (citycount >= counter),CODE Statement Body (first 200 characters): { [h: xdist = listGet(dislist, counter)] [h: xname = listGet(citynamelist, counter)] [h: xdist = number(xdist)] [h: maxdist = number(maxdist)] [if(maxdist >= xdist),CODE: { [maxdist = xdi
EDIT: Found the problem!
Code: Select all
[h: citylist = getWithStateNames("City")]
[h: target = "The Party"]
[h: dislist = ""]
[h: citynamelist = ""]
[h, foreach(city, citylist, ""),CODE:
{
[h: distance = getDistance(target, 1, city, "NO_GRID")]
[h: distance = round(distance,0)]
[h: dislist = listAppend(dislist,distance,",")]
[h: citynamelist = listAppend(citynamelist,city,",")]
}]
[h: counter = 0]
[h: citycount = listCount(citylist)]
[h: currentcity = ""]
[h: maxdist = 24500]
[h, while (citycount > counter),CODE:
{
[h: xdist = listGet(dislist, counter)]
[h: xname = listGet(citynamelist, counter)]
[h: xdist = number(xdist)]
[h: maxdist = number(maxdist)]
[if(maxdist >= xdist),CODE:
{
[maxdist = xdist]
[currentcity = xname]
};
{}]
[h: counter = counter +1]
}]
[r: currentcity]
[r: maxdist]
Turns out the while loop just needed to be set from ">=" to ">" because the counter started at 0 and the city count started at 1. Woopsies ^^;. Thanks again for your help!