A very frustrating error

Doc requests, organization, and submissions

Moderators: dorpond, trevor, Azhrei

Post Reply
User avatar
Altrunchen
Giant
Posts: 135
Joined: Sun Dec 02, 2012 3:01 pm

A very frustrating error

Post by Altrunchen »

So I'm currently trying to make a macro that gets the relative location of a token to a city token. So far it's been going ok but there is one particular problem that makes no sense. I have no idea why the ">=" comparison spits out this error where other comparisons have not. The same comparison works other places in the macro and in other macros, but just not in this case. I am so frustrated with this, it makes no sense at all.

This is the code to the macro:

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]

[while (citycount >= counter,""),CODE:
{
	[h: xdist = listGet(dislist, counter)]
	[h: xname = listGet(citynamelist, counter)]

	[if(maxdist >= xdist),CODE:
	{
		[h: maxdist = xdist]
		[h: currentcity = xname]		
	};
	{};]

	[h: counter = counter +1]
}]
and this is the error message that appears:

Error in body of roll.       Statement options (if any): while (citycount >= counter,""),CODE       Statement Body (first 200 characters): { [h: xdist = listGet(dislist, counter)] [h: xname = listGet(citynamelist, counter)] [if(maxdist >= xdist),CODE: { [h: maxdist = xdist] [h: currentcity = xname] }; {};] [h: counter =

Does anyone have any idea what in the world is going on here? Because I have no idea right now.
Image

User avatar
aliasmask
RPTools Team
Posts: 9023
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: A very frustrating error

Post by aliasmask »

I don't think you can put
while (citycount >= counter,"")
Also, I recommend using a for ([for:]) loop.

User avatar
Altrunchen
Giant
Posts: 135
Joined: Sun Dec 02, 2012 3:01 pm

Re: A very frustrating error

Post by Altrunchen »

aliasmask wrote:I don't think you can put
while (citycount >= counter,"")
Also, I recommend using a for ([for:]) loop.
But I've changed the ">=" to something else and it worked fine, it's just not the comparison I need. It's only when I change the comparison to ">=" that it spits the error out.

EDIT: I'm referring to the ">=" down in the 'if' statement of course :X, and thanks, by the way, for your help.
Image

User avatar
aliasmask
RPTools Team
Posts: 9023
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: A very frustrating error

Post by aliasmask »

Altrunchen wrote:
aliasmask wrote:I don't think you can put
while (citycount >= counter,"")
Also, I recommend using a for ([for:]) loop.
But I've changed the ">=" to something else and it worked fine, it's just not the comparison I need. It's only when I change the comparison to ">=" that it spits the error out.
This is also bad syntax:
{};]
Perhaps it does work/ignore the bad syntax, but lets start off with writing it the correct way and go from there.

User avatar
Altrunchen
Giant
Posts: 135
Joined: Sun Dec 02, 2012 3:01 pm

Re: A very frustrating error

Post by Altrunchen »

I think that people have told me here before that '{};' is bad syntax, but I've found that the macro won't work unless I do that.
Image

User avatar
aliasmask
RPTools Team
Posts: 9023
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: A very frustrating error

Post by aliasmask »

Altrunchen wrote:I think that people have told me here before that '{};' is bad syntax, but I've found that the macro won't work unless I do that.
This is the correct syntax:

Code: Select all

[H, if(condition), code: {
   ...
};{}]
[H, if(condition), code: {
   ...
};{
   ...
}]
[H, if(condition): ... ]
If it doesn't work using that, then something else is wrong.

User avatar
Altrunchen
Giant
Posts: 135
Joined: Sun Dec 02, 2012 3:01 pm

Re: A very frustrating error

Post by Altrunchen »

aliasmask wrote:
Altrunchen wrote:I think that people have told me here before that '{};' is bad syntax, but I've found that the macro won't work unless I do that.
This is the correct syntax:

Code: Select all

[H, if(condition), code: {
   ...
};{}]
[H, if(condition), code: {
   ...
};{
   ...
}]
[H, if(condition): ... ]
If it doesn't work using that, then something else is wrong.
While I can understand that testing something like that would be normal procedure, I should let you know that all of my other macros do this and there hasn't been a problem yet. But just for good measure, I tested it and there was no change in the results unfortunately. I isolated the problem to the ">=" but I can't see why that comparison is a problem if when it is changed to something else like "!=" then no error is reported at all.
Image

User avatar
aliasmask
RPTools Team
Posts: 9023
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: A very frustrating error

Post by aliasmask »

Well, that specific example >= compares 2 numbers while != can compare 2 numbers or 2 strings. I suspect that your data may have blanks in it or even a string.

User avatar
Altrunchen
Giant
Posts: 135
Joined: Sun Dec 02, 2012 3:01 pm

Re: A very frustrating error

Post by Altrunchen »

aliasmask wrote:Well, that specific example >= compares 2 numbers while != can compare 2 numbers or 2 strings. I suspect that your data may have blanks in it or even a string.
How can I check that? I have been having the macro return the values for 'xdist' and there don't seem to be any spaces. And I know that the initial 'maxdist' has no spaces either. Isn't there a macro function that converts a string into a number? Would that work?
Image

User avatar
aliasmask
RPTools Team
Posts: 9023
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: A very frustrating error

Post by aliasmask »

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.

User avatar
Altrunchen
Giant
Posts: 135
Joined: Sun Dec 02, 2012 3:01 pm

Re: A very frustrating error

Post by Altrunchen »

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!
Image

Post Reply

Return to “Documentation Requests/Discussion”