TinTin++ Mud Client The TinTin++ message board

 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
TinTin++ Mud Client

How to get the farthest room ?

 
Post new topic   Reply to topic    The TinTin++ message board Forum Index -> Script Help
View previous topic :: View next topic  
Author Message
szhairui



Joined: 16 Jan 2013
Posts: 13

PostPosted: Tue Jan 13, 2015 4:07 am    Post subject: How to get the farthest room ? Reply with quote

To get the farthest room from a room list returned by a #map list command, i wrote the following codes,

Code:

392 #function {getFarthestRoom}
393 {
394         #nop ============================================================;
395         #nop Get the farthest room from the room list;
396         #nop The parameter is the room list;
397         #nop ============================================================;
398
399         #var rl %0;
400         #var fk 0;
401         #foreach {$rl[]} {rk}
402         {
403                 #if {"$fk" == "0"}
404                 {
405                         #var fk $rk;
406                 }
407                 {
408                         #if {$rl.$rk > $rl.$fk}
409                         {
410                                 #var fk $rk;
411                         }
412                 };
413         };
414         #var result $fk;
415 };


However, I only can get the first room in the list instead of the room as expected.
Can anyone tell me what's wrong with my codes?
Embarassed
Back to top
View user's profile Send private message
szhairui



Joined: 16 Jan 2013
Posts: 13

PostPosted: Tue Jan 13, 2015 7:26 am    Post subject: Reply with quote

I have figured out the reason by myself and fixed the codes to :
Code:
#function {getFarthestRoom}
{
   #nop ============================================================;
   #nop Get the farthest room from the room list;
   #nop The parameter is the room list;
   #nop ============================================================;

   #var rl %0;
   #var fk 0;
   #foreach {$rl[]} {rk}
   {
      #if {"$fk" == "0"}
      {
         #var fk $rk;
      }
      {
         #var d1 $rl.$rk;
         #var d2 $rl.$fk;
         #if {$d1 > $d2}
         {
            #var fk $rk;
         }
      };
   };
   #var result $fk;
};


It seems tintin++ can not parse the expression
Code:
$rl.$rk > $rl.$fk


although it seems should work.
Back to top
View user's profile Send private message
szhairui



Joined: 16 Jan 2013
Posts: 13

PostPosted: Tue Jan 13, 2015 7:29 am    Post subject: Reply with quote

Another question is that since the parameter of the funtion is a list.
I should call it as
Code:
@getFarthestRoom{{$lst}}
and use %0 to point to the list within the function.

But I am not sure that is a right way.
Back to top
View user's profile Send private message
Scandum
Site Admin


Joined: 03 Dec 2004
Posts: 3844

PostPosted: Tue Jan 13, 2015 8:28 am    Post subject: Reply with quote

Using an extra set of braces should be alright.

$rl.$rk is the equivalent of $rl[$rk]
Back to top
View user's profile Send private message Send e-mail
Slysven



Joined: 10 Apr 2011
Posts: 375
Location: As "Jomin al'Bara" in WoTMUD or Wiltshire, UK

PostPosted: Thu Jan 15, 2015 3:01 pm    Post subject: Reply with quote

Be aware that for #MAP LIST/FIND there is (or was last I checked) a limit to how far away TinTin++ will look for connected rooms {the MAP_SEARCH_DIST value compiled in as a #define in mapper.c}. I think it was 1000, chosen I guess as a compromise between looked at as many possible rooms as possible verses the time it takes to build the distances graph using what I suspect is Dijkstra's Alogrithm...
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    The TinTin++ message board Forum Index -> Script Help All times are GMT - 5 Hours
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
Get TinTin++ Mud Client at SourceForge.net. Fast, secure and Free Open Source software downloads Get TinTin++ Mud Client at SourceForge.net. Fast, secure and Free Open Source software downloads
TinTin++ Homepage

Powered by phpBB © 2001, 2002 phpBB Group