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

saving variables

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



Joined: 29 Jul 2012
Posts: 66

PostPosted: Mon Oct 08, 2012 6:23 am    Post subject: saving variables Reply with quote

is there any way to save variable into a separate files? i case of ie. list of item/friends for different characters ?
Back to top
View user's profile Send private message
Slysven



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

PostPosted: Mon Oct 08, 2012 12:00 pm    Post subject: Reply with quote

I had exact this issue recently when I had an associated array (called "roomcoding" with over a hundred entries each with around 7 sub-elements) that I use to define symbols for my map. Editing it outside of TinTin++ in a script file was horrendous but I found that I could write it out using #LINE LOG to write out each sub-element on it's own line, and using \x7b and \x7d for the '{' and '}' that TinTin++ uses around those elements when it writes them to a file - I could then edit individual elements and then reimport them into a live, running instance of TinTin++ with a #READ {<filename>}.

For a single value variable you can simply use:
Code:
#line {log} {<filename>} {#VARIABLE \x7b<variable name>\x7d \x7b${variable name}\x7d}
where <variable name> is exactly that, no '$' prefix, no '{' '}'s and <filename> is whatever you want though a .tt or .tin ending is suggested.

For a more complex case involving arrays with numeric indexes and also associative arrays with named sub-elements you need to iterate through those sub-elements - for my case where each outer element of my variable has several (in this case the same repeated list of sub-elements but this need not be the case) I can dump the entire thing in an easier to edit form with:
Code:
#ALIAS        {^dumproomcoding$}
{
   #line {log} {<filename>} {#VARIABLE \x7broomcoding\x7d \x7b};
   #list {outer_keys} {CREATE} {$roomcoding[]};
   #loop {1} {&{outer_keys[]}} {outer_index}
   {
      #line {log} {<filename>} {\x7b$outer_keys[$outer_index]\x7d\x7b};
      #variable {element} ${roomcoding[$outer_keys[$outer_index]]};
      #list {inner_keys} {CREATE} {$element[]};
      #loop {1} {&{inner_keys[]}} {inner_index}
      {
         #line {log} {<filename>} {    \x7b$inner_keys[$inner_index]\x7d\x7b$roomcoding[$outer_keys[$outer_index]][$inner_keys[$inner_index]]\x7d}
      };
      #line {log} {<filename>} {\x7d}
   };
   #line {log} {<filename>} {\x7d};
   #unvariable {outer_keys};
   #unvariable {inner_keys};
   #unvariable {outer_index};
   #unvariable {inner_index}
}
{5}
Note that the secret here is to create a #LIST of the values or keys that go inside the '['']' for each bit of $<variable>[<outer_key>][inner_key] so the results for me is:
Code:
#VARIABLE {roomcoding} {
{aggroveg}{
    {a}{V__}
    {c}{Vegetation}
    {f}{0}
    {m}{⚘}
    {n}{Vegetation: Aggressive!}
    {p}{⚘;}
    {t}{Unspecified(Hostile)}
    {w}{10.00}
}
{ancient}{
    {a}{T_A}
    {c}{Vegetation}
    {f}{0}
    {m}{ A}
    {n}{Tree(s): Ancient.}
    {p}{ A}
    {t}{Tree(Ancient)}
    {w}{2.00}
}
{angry}{
    {a}{T_A}
    {c}{Vegetation}
    {f}{0}
    {m}{ A}
    {n}{Tree(s): Angry.}
    {p}{ A}
    {t}{Tree(Angry)}
    {w}{2.00}
}
{armoury}{
    {a}{A $}
    {c}{Shop}
    {f}{0}
    {m}{A ⌂}
    {n}{Armoury: all types for sale here.}
    {p}{∫ ⌂}
    {t}{Armour}
    {w}{1.00}
}
...
lots more elements not shown...!
...
{writhing}{
    {a}{G__}
    {c}{Vegetation}
    {f}{0}
    {m}{}
    {n}{Vegetation: writhing (aggressive) grass, so don't walk on it!}
    {p}{;;;}
    {t}{Grass}
    {w}{20.00}
}
}
One note of caution I would offer is that if you are handling strings of text contain color codes you will have to get a bit clever to preserve them in a <999> type form - maybe by using a replace to change '<' and '>' into their \x## forms (the values "escapes" me for the moment Laughing ) if a regexp detects a "<###>" in the sub-element.

I hope that this gives you a starting point - you may also consider whether #CLASSes could offer an alternative solution to your requirements... Coffee
Back to top
View user's profile Send private message
Azirek



Joined: 29 Jan 2012
Posts: 28

PostPosted: Wed Oct 10, 2012 4:20 am    Post subject: Reply with quote

dorian: How read variable from file?
_________________
GNU Linux Slackware Current, Tintin++ 2.00.7 and 2.00.9
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