RPTools.net

Discussion and Support

Skip to content

It is currently Tue Oct 24, 2017 6:29 am 






Reply to topic  [ 11 posts ] 

Previous topic | Next topic 

  Print view

Author Message
User avatar  Offline
Giant
 
Joined: Sun Dec 02, 2012 3:01 pm
Posts: 127
 Post subject: A very frustrating error
PostPosted: Sun Dec 01, 2013 7:54 pm 
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:
[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


Top
 Profile  
 
User avatar  Offline
Deity
 
Joined: Tue Nov 10, 2009 6:11 pm
Posts: 7890
Location: Bay Area
 Post subject: Re: A very frustrating error
PostPosted: Sun Dec 01, 2013 8:08 pm 
I don't think you can put
Quote:
while (citycount >= counter,"")

Also, I recommend using a for ([for:]) loop.

_________________
Downloads:


Top
 Profile  
 
User avatar  Offline
Giant
 
Joined: Sun Dec 02, 2012 3:01 pm
Posts: 127
 Post subject: Re: A very frustrating error
PostPosted: Sun Dec 01, 2013 8:10 pm 
aliasmask wrote:
I don't think you can put
Quote:
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


Top
 Profile  
 
User avatar  Offline
Deity
 
Joined: Tue Nov 10, 2009 6:11 pm
Posts: 7890
Location: Bay Area
 Post subject: Re: A very frustrating error
PostPosted: Sun Dec 01, 2013 8:14 pm 
Altrunchen wrote:
aliasmask wrote:
I don't think you can put
Quote:
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:
Quote:
{};]

Perhaps it does work/ignore the bad syntax, but lets start off with writing it the correct way and go from there.

_________________
Downloads:


Top
 Profile  
 
User avatar  Offline
Giant
 
Joined: Sun Dec 02, 2012 3:01 pm
Posts: 127
 Post subject: Re: A very frustrating error
PostPosted: Sun Dec 01, 2013 8:22 pm 
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


Top
 Profile  
 
User avatar  Offline
Deity
 
Joined: Tue Nov 10, 2009 6:11 pm
Posts: 7890
Location: Bay Area
 Post subject: Re: A very frustrating error
PostPosted: Sun Dec 01, 2013 8:29 pm 
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:
[H, if(condition), code: {
   ...
};{}]
[H, if(condition), code: {
   ...
};{
   ...
}]
[H, if(condition): ... ]

If it doesn't work using that, then something else is wrong.

_________________
Downloads:


Top
 Profile  
 
User avatar  Offline
Giant
 
Joined: Sun Dec 02, 2012 3:01 pm
Posts: 127
 Post subject: Re: A very frustrating error
PostPosted: Sun Dec 01, 2013 8:39 pm 
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:
[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


Top
 Profile  
 
User avatar  Offline
Deity
 
Joined: Tue Nov 10, 2009 6:11 pm
Posts: 7890
Location: Bay Area
 Post subject: Re: A very frustrating error
PostPosted: Mon Dec 02, 2013 12:56 am 
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.

_________________
Downloads:


Top
 Profile  
 
User avatar  Offline
Giant
 
Joined: Sun Dec 02, 2012 3:01 pm
Posts: 127
 Post subject: Re: A very frustrating error
PostPosted: Mon Dec 02, 2013 12:59 am 
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


Top
 Profile  
 
User avatar  Offline
Deity
 
Joined: Tue Nov 10, 2009 6:11 pm
Posts: 7890
Location: Bay Area
 Post subject: Re: A very frustrating error
PostPosted: Mon Dec 02, 2013 1:05 am 
There are a bunch of ways to post the value before the if. Here is a quick way:

Code:
[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.

_________________
Downloads:


Top
 Profile  
 
User avatar  Offline
Giant
 
Joined: Sun Dec 02, 2012 3:01 pm
Posts: 127
 Post subject: Re: A very frustrating error
PostPosted: Mon Dec 02, 2013 1:23 am 
aliasmask wrote:
There are a bunch of ways to post the value before the if. Here is a quick way:

Code:
[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:
[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:
[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:
[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


Top
 Profile  
 
Display posts from previous:  Sort by  
Reply to topic  [ 11 posts ] 

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:

Who is online

In total there are 2 users online :: 1 registered, 0 hidden and 1 guest (based on users active over the past 5 minutes)
Most users ever online was 243 on Sun Nov 04, 2012 6:14 am

Users browsing this forum: Exabot [Bot] and 1 guest





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group

Style based on Andreas08 by Andreas Viklund

Style by Elizabeth Shulman