| View previous topic :: View next topic |
| Author |
Message |
ixle
Joined: 15 Sep 2011 Posts: 134 Location: United States
|
Posted: Tue Apr 10, 2012 11:43 pm Post subject: Put vnums from #map list into a variable |
|
|
| I would like to store information from #map list (particularly the vnums returned) into a list variable. The trouble I'm having is that tintin doesn't seem to be able to capture that data. Any tips? |
|
| Back to top |
|
 |
Slysven
Joined: 10 Apr 2011 Posts: 260 Location: As "Jomin al'Bara" in WoTMUD or Wiltshire, UK
|
Posted: Wed Apr 11, 2012 9:00 am Post subject: |
|
|
Well I've had a go at doing this already, by adding a 7th (?) argument to the #MAP LIST command which puts a semicolon separated list into the given variable name (which is then parseable by the #FORALL/#FOREACH command)... Cross reference to topic in "Feature Requests"
This works well for me and is very much faster than a script solution (examining each room in order, in a TinTIn++ script to see if it matches) one thing I would warn you about, that is equally applicable to the original #MAP LIST command is that if you have multi-line descriptions with say "\n" as the line break marker I have found that searching for things in the description (3rd argument) does not work well unless, I think, you use a | Code: | | #LINE {SUB} {ESC} {#MAP LIST ... {<thing to search for in description>} ...} | form.
Compile and enjoy!  |
|
| Back to top |
|
 |
ixle
Joined: 15 Sep 2011 Posts: 134 Location: United States
|
Posted: Wed Apr 11, 2012 9:46 am Post subject: |
|
|
Thanks, I'll probably take the dive and try hacking my code for the first time for your referenced DO_MAP function. Nice that it also lists the area.
Looping through 30k rooms (or more as I continue to map) doesn't seem like a practical solution for accessing #MAP LIST data.
Again, thank you very much for this. Hopefully Scandum would see fit to make this an included upgrade to #MAP LIST in the future. |
|
| Back to top |
|
 |
ixle
Joined: 15 Sep 2011 Posts: 134 Location: United States
|
Posted: Wed Apr 11, 2012 10:03 am Post subject: |
|
|
Ok, I didn't change anything regarding the red edit about "20" instead of "%20s" but I added the rest of the DO_MAP(map_list) code, compiled and tried it out.
The area listing seemed to work fine without using the variable argument.
| Code: | #map list {Guard Room}
vnum: 11424 distance: 35.000 area: stone name: Guard Room
vnum: 11425 distance: 35.000 area: stone name: Guard Room
vnum: 24016 distance: 41.000 area: newthalos name: Guard Room
vnum: 24017 distance: 42.000 area: newthalos name: Guard Room
vnum: 26076 distance: 23.000 area: dread name: Guard Room
vnum: 26077 distance: 23.000 area: dread name: Guard Room
vnum: 29693 distance: 50.000 area: jenny name: Guard Room
vnum: 31858 distance: -1.000 area: fortress name: Guard Room
vnum: 31864 distance: -1.000 area: fortress name: Guard Room
|
However, when I add the variable argument, not only does it suppress the output (intended?) but it only stores a semicolon and the last vnum in the provided variable string.
| Code: | #map list {Guard Room} {} {} {} {} {} {test}
#var test
#VARIABLE {test}={;31864}
|
Am I doing something wrong? |
|
| Back to top |
|
 |
Slysven
Joined: 10 Apr 2011 Posts: 260 Location: As "Jomin al'Bara" in WoTMUD or Wiltshire, UK
|
Posted: Wed Apr 11, 2012 2:00 pm Post subject: |
|
|
Um, I made an error that I had fixed in my copy at home but not posted out to the forum. The code there now SHOULD work as intended, which does include not putting up on screen the list of rooms and some other details if a variable is to get the room vnumbs.  |
|
| Back to top |
|
 |
ixle
Joined: 15 Sep 2011 Posts: 134 Location: United States
|
Posted: Wed Apr 11, 2012 6:08 pm Post subject: |
|
|
| Thanks that fixed it. I'm gonna try and plug it in to the 2.00.9 code in a bit. I'll report back later on the results. |
|
| Back to top |
|
 |
ixle
Joined: 15 Sep 2011 Posts: 134 Location: United States
|
Posted: Wed Apr 11, 2012 7:24 pm Post subject: |
|
|
| Works fine in 2.00.9 |
|
| Back to top |
|
 |
Scandum Site Admin
Joined: 03 Dec 2004 Posts: 3281
|
Posted: Thu Apr 12, 2012 7:07 am Post subject: |
|
|
| You can also making an alias using #loop and #map at to go through all the vnums. |
|
| Back to top |
|
 |
Slysven
Joined: 10 Apr 2011 Posts: 260 Location: As "Jomin al'Bara" in WoTMUD or Wiltshire, UK
|
Posted: Sat Apr 14, 2012 10:07 am Post subject: |
|
|
No disrespect intended Mr. Scandum whilst what you suggest is thoeretically correct and applicable to ALL users of [T,W]intin++, there IS a performance benefit by doing this in the executable code rather than a script; and for large maps, say >10K rooms, I feel this difference is visible, despite the effort necessary to "roll your own" executable tt++(.exe)!  |
|
| Back to top |
|
 |
ixle
Joined: 15 Sep 2011 Posts: 134 Location: United States
|
Posted: Thu Apr 26, 2012 11:38 am Post subject: |
|
|
So after implementing your code Slysven, I've finally gotten around to try and write some stuff off it, but I noticed the data stored in the variable is just a string.
I want to be able to access the vnums returned individually. Do I need to work out some way to split the string into a list on the semicolons or is there a better way? Could the code store it in a list by default? |
|
| Back to top |
|
 |
Slysven
Joined: 10 Apr 2011 Posts: 260 Location: As "Jomin al'Bara" in WoTMUD or Wiltshire, UK
|
Posted: Sat Apr 28, 2012 11:27 am Post subject: |
|
|
Just use a | Code: | | #FORALL {$variable returned from #MAP LIST} {...do something with each room (which will be &0 here) ...} | or | Code: | | #FOREACH {$variable returned from #MAP LIST} {room} {...do something with each room (which will be $room here) ...} | You can of course convert it to a LIST variable with I think: | Code: | | #LIST {list variable name} {CREATE} {$variable returned from #MAP LIST} | which means you can count the number of rooms returned with "&{list variable name[]}" PROVIDED as with other commands that return a result in a given variable that there IS a result - if not then the variable returned from the #MAP LIST is NOT touched so if it previously had something in it that will not be changed...
There may be a small gotcha - if the list of rooms to return is VERY long - like say EVERY room in your map then theoretically the defined [BUFFER_SIZE] limit for the ${variable returned from #MAP LIST} could be exceeded - and of course trying to stuff more into a 'C' character array (string) than there is space for IS a well known way of crashing or otherwise messing up a program... ... Humm, maybe that's why I keep getting a crash under a particular sitaution on my system, let me check that out in more detail after I grab a fresh cup of coffee  |
|
| Back to top |
|
 |
|