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

convert list to variable

 
Post new topic   Reply to topic    The TinTin++ message board Forum Index -> General Discussion
View previous topic :: View next topic  
Author Message
dawang10



Joined: 14 Feb 2015
Posts: 66

PostPosted: Mon Mar 06, 2017 5:14 pm    Post subject: convert list to variable Reply with quote

#var tmp {e;w;n}
#list tmp create $tmp

so tmp becomes {{1}{e}{2}{w}{3}{n}}

But how to convert {{1}{e}{2}{w}{3}{n}} to {e;w;n} or {{e}{w}{n}}

trying to locate current place in a map by exits information, but #map find {roomexits}{{1}{e}{2}{w}{3}{n}} doesn't work, only #map find {roomexits}{e;w;n} or #map find {{e}{w}{n}} works
Back to top
View user's profile Send private message
wstopek



Joined: 27 Dec 2012
Posts: 19

PostPosted: Tue Mar 07, 2017 2:03 am    Post subject: Reply with quote

Try this.
#echo {$tmp[%*]}
Back to top
View user's profile Send private message
dawang10



Joined: 14 Feb 2015
Posts: 66

PostPosted: Tue Mar 07, 2017 2:40 am    Post subject: Reply with quote

seems always followed by {} if the size is an odd number

here, it shows {e}{w}{n}{}
Back to top
View user's profile Send private message
PowerGod



Joined: 04 Aug 2014
Posts: 306

PostPosted: Tue Mar 07, 2017 6:00 am    Post subject: Reply with quote

Try this

Code:

#var {tmp} {{1}{e}{2}{w}{3}{n}};

#var {tmp2} {};
#foreach $tmp[%*] cnt {#var {tmp2} {$tmp2;$cnt}};
#replace {tmp2} {^;} {};

#var {tmp} {$tmp2};
Back to top
View user's profile Send private message
dawang10



Joined: 14 Feb 2015
Posts: 66

PostPosted: Tue Mar 07, 2017 7:58 am    Post subject: Reply with quote

Thanks a lot. it works

curious you are up at this time. Smirk
Back to top
View user's profile Send private message
PowerGod



Joined: 04 Aug 2014
Posts: 306

PostPosted: Tue Mar 07, 2017 5:53 pm    Post subject: Reply with quote

Out of curiosity seems like I found another workaround

Code:

#var {tmp} {{1}{e}{2}{w}{3}{n}};

#var {tmp3} {{$tmp[%*]}};
#line substitute variables #map find {roomexits} $tmp3[];


- Note the double curly brackets around the called variable during the declaration, this will create a variable with 2 elements, the first one will contain all the directions, and the second one will be empty

- When calling the variable with #map it must NOT have curly brackets around, the substitution already adds them when getting the first element

a debug session may explain better what's happening
Code:

#var {tmp3} {{$tmp[%*]}}
[02] variable {tmp3} {{$tmp[%*]}}
#OK. VARIABLE {tmp3} HAS BEEN SET TO {{{e}{w}{n}}{}}.
#line substitute variables #map find {roomexits} $tmp3[]
[02] line substitute variables #map find {roomexits} $tmp3[]
[02] map find {roomexits} {{e}{w}{n}}
Back to top
View user's profile Send private message
dawang10



Joined: 14 Feb 2015
Posts: 66

PostPosted: Wed Mar 08, 2017 7:25 am    Post subject: Reply with quote

Good
create a new empty element by plus a more }

didn't think of using #line.

By the way, #line substitute variable will replace all the variables in #map find? So it will cause the replacement of other variables, like $roomname, etc.
Back to top
View user's profile Send private message
Scandum
Site Admin


Joined: 03 Dec 2004
Posts: 3749

PostPosted: Wed Mar 08, 2017 8:45 am    Post subject: Reply with quote

dawang10 wrote:
seems always followed by {} if the size is an odd number

here, it shows {e}{w}{n}{}


It will only do that if you save $tmp[%*] to a variable because it will save it as a table with key-value pairs. The following works:

Code:

#var {tmp} {{1}{e}{2}{w}{3}{n}};

#map find {roomexits} {$tmp[%*]};
Back to top
View user's profile Send private message Send e-mail
dawang10



Joined: 14 Feb 2015
Posts: 66

PostPosted: Wed Mar 08, 2017 1:29 pm    Post subject: Reply with quote

great, it's much simpler
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 -> General Discussion 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