Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
killunix
Beginner


Joined: 18 Nov 2007
Posts: 28

PostPosted: Thu Jan 28, 2010 10:15 am   

Please help to check this script,thanks!
 
hi,all.
I need use the %roomflags to mark the rooms that have the same name but difference location on a zone. I write the followin script to do it.
Code:

#call %mapfilter("")
roomschecked=""
#CALL %mapfilter(%concat("ZoneID=",%zonenum()))
#loop %numrooms {
  #additem roomschecked %roomvnum(%mapvnum(%i));
  $a=1
  #loop 1,%numitems(@roomschecked) {
  #if %roomname(@roomschecked,$a)=%roomname(%mapvnum(%i)) {
     roomflags=%roomflags(%item(@roomschecked,$a))+1
     #call %roomflags(%mapvnum(%i),@roomflags)
     } {#noop}
     #math $a $a+1
     #say $a
    }
   }


But it do nothing.please help me to check what's wrong with it.
Thank you very much.
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Thu Jan 28, 2010 2:46 pm   
 
First, I have a few tips. These are not wrong in your code, but may be easier to understand or code.
First tip: you do not need the {#noop}. The ELSE statement of #IF is optional.
Second tip: "#math $a $a+1" could be written more clearly as "$a=$a+1". The #MATH command is no longer needed for anything, but retained for backwards compatibility.
Third tip: I think you could use local variables instead of global variables for @roomschecked and @roomflags.
Fourth tip: instead of tracking the iteration of the second loop with $a, you could use %j. %i tracks the iteration of an outer loop, %j works for an inner loop, and I think %k is available for a tertiary loop.
Fifth tip: you could use a #FORALL construction instead of your second loop. That way you won't have to use "%item(@roomschecked,$a)" to find the element in the stringlist.

I see several bugs in your code. The first problem is "%roomvnum(%mapvnum(%i))". The documentation states that %roomvnum() is the same as %mapvnum(). They are identical. So, you are converting the filter number into a vnum, and then converting that into a new vnum. I think you only need "%roomvnum(%i)". Your current code is trying to change the roomflags on the wrong room numbers.

The second problem I see is that "%roomname( @roomschecked, $a)" should be "%roomname(%item(@roomschecked, $a))".

The third problem is that when you find a match, you are changing the room flags on only one room. If room 1 and 2 have identical names, you are only changing the flag on room 2.

I hope that helps you!

[edited] fixed $item to %item


Last edited by Rahab on Thu Jan 28, 2010 9:27 pm; edited 1 time in total
Reply with quote
nexela
Wizard


Joined: 15 Jan 2002
Posts: 1644
Location: USA

PostPosted: Thu Jan 28, 2010 4:31 pm   
 
Also if you are not running this script in map mode it will not work unless you toggle %maplocked()
_________________
Zmud Support Library
Zmud Knowledge Base
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Thu Jan 28, 2010 9:21 pm   
 
Actually, I just reexamined the logic for incrementing the room flags. As you have it currently set up, here is what happens if you have rooms 1 through 4 all with the same name, as it tests each room:
room(1) matches room(1), so roomflag(1) becomes 1. Note that this means every room will be flagged with at least a value of 1!
room(2) matches 1 and 2, so roomflag(1)=2, roomflag(2)=1
...

End result: roomflag(1)=4, roomflag(2)=3, roomflag(3)=2,roomflag(4)=1.

I don't think this is what you intended. I can think of three possible things you might have meant to do:
(A) every roomflag equal the number of rooms which match this room name, not counting this room
(B) every roomflag equal the number of rooms which match this room name, counting this room
(C) every roomflag be 1 or greater (TRUE) if there are duplicate room names, or 0 or blank (FALSE) if the room name is unique in the zone

If you need help creating a code logic for whichever of these you meant, just let us know which one you want.
Reply with quote
killunix
Beginner


Joined: 18 Nov 2007
Posts: 28

PostPosted: Fri Jan 29, 2010 4:42 am   
 
Rahab wrote:
Actually, I just reexamined the logic for incrementing the room flags. As you have it currently set up, here is what happens if you have rooms 1 through 4 all with the same name, as it tests each room:
room(1) matches room(1), so roomflag(1) becomes 1. Note that this means every room will be flagged with at least a value of 1!
room(2) matches 1 and 2, so roomflag(1)=2, roomflag(2)=1
...

End result: roomflag(1)=4, roomflag(2)=3, roomflag(3)=2,roomflag(4)=1.

I don't think this is what you intended. I can think of three possible things you might have meant to do:
(A) every roomflag equal the number of rooms which match this room name, not counting this room
(B) every roomflag equal the number of rooms which match this room name, counting this room
(C) every roomflag be 1 or greater (TRUE) if there are duplicate room names, or 0 or blank (FALSE) if the room name is unique in the zone

If you need help creating a code logic for whichever of these you meant, just let us know which one you want.


Sorry, I did not describe the demand clearly。
This is my map:
Code:
A-B-B-B-C-D-D-D-D

1.The room A or room C has the unique name on the map.so their roomflag should be 1.
2.The are 3 rooms called B, they have the same name but diffrent vnumber. I need set the first room B's roomflag as 1.the second room B as 2,the third one as 3.
3.The room D as same as B
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Fri Jan 29, 2010 2:45 pm   
 
Interesting. So you do in fact want different values there. That didn't occur to me. Very Happy I guess this is to distinguish rooms with identical names from each other (but why not just use the vnum?). In that case, you can ignore Problem 3 in my first posting--your logic does just fine inserting differing numbers. See whether fixing problems 1 and 2 makes it work for you.
Reply with quote
killunix
Beginner


Joined: 18 Nov 2007
Posts: 28

PostPosted: Fri Jan 29, 2010 4:15 pm   
 
Rahab wrote:
Interesting. So you do in fact want different values there. That didn't occur to me. Very Happy I guess this is to distinguish rooms with identical names from each other (but why not just use the vnum?). In that case, you can ignore Problem 3 in my first posting--your logic does just fine inserting differing numbers. See whether fixing problems 1 and 2 makes it work for you.


I use the trigger to capture the room name in the game,and use the name to locate where am i on the map, But there are many room has the same name but diffrence room vnum.So i need use the roomflag to mark them. Use the room name and vnumber can't get the real position indeed.

I modify this script as follows, but it still can't work.

Code:
#call %maplocked(0)
roomschecked=""
#CALL %mapfilter(%concat("ZoneID=",%zonenum()))
#loop %numrooms {
  #additem roomschecked %roomvnum(%i);
  #forall @roomschecked {
      #if %roomname(%mapvnum(%i))=%roomname(%roomvnum(%j)) {
      #if %mapvnum(%i)<>%roomvnum(%j) {
      roomflags=%roomflags(%roomvnum(%j))+1
      #call %roomflags(%mapvnum(%i),@roomflags)   
     }
   }
  }
}

can you give me some other advise for this demand?

Thank you[/quote]
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Sat Jan 30, 2010 12:34 am   
 
You are using #FORALL now. That means that %j will be the actual element of the stringlist, not the position of the element. When you added elements to @roomschecked, the element you put in was the vnum. Replace all instances of %roomvnum(%j) with %j.
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
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 vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net