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

Nested arrays in a list

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



Joined: 05 Jan 2011
Posts: 16

PostPosted: Thu Apr 26, 2012 6:26 pm    Post subject: Nested arrays in a list Reply with quote

I am trying to track a lot of data over a day it seems a list with an array would be a good way. Had considered one list for each data item but I prefer a array inside a list.

I tried this code, but I can't access it using showme or var. I thought maybe messed up brackets but no combo I tried seems to work.

Guess my questions are:
Is this possible?

If so
How do I create a row with a nested array?
0nce created, how do I access the data in aliases and such?
Code:
 #list {daily_info_tracked} {insert} {1} {
                        {qps_onhand}{%%1}{qps_earned}{%%2}
                        };
Back to top
View user's profile Send private message
Scandum
Site Admin


Joined: 03 Dec 2004
Posts: 3274

PostPosted: Thu Apr 26, 2012 6:58 pm    Post subject: Reply with quote

It's storing it as plain data, not sure if this can be fixed. You could try:

Code:

#list {daily_info_tracked} {insert} {1} {}

#var {daily_info_tracked[1]} {{qps_onhand}{%%1}{qps_earned}{%%2}}
Back to top
View user's profile Send private message Send e-mail
new_to_tin_tin



Joined: 05 Jan 2011
Posts: 16

PostPosted: Fri Apr 27, 2012 6:01 pm    Post subject: Reply with quote

Thanks, that did the trick.

I much prefer this method. Much cleaner, especially when dealing with deletes and inserts.
Back to top
View user's profile Send private message
Slysven



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

PostPosted: Sat Apr 28, 2012 12:38 pm    Post subject: Reply with quote

It's also handy to keep associated data in one group, for instance I use it to keep track of character status information, with the "outermost" grouping that of my current character ("alt") name, eg:
Code:
#VARIABLE {character} {Jath}
#VARIABLE {status} {{Alice}{{maxhp}{200}{maxsp}{0}}{Bob}{{maxhp}{150}{maxsp}{100}}{Jath}{{maxhp}{350}}}

#SHOWME {Current maximum health: $status[$character][maxhp]}
Current maximum health: 350

#ALIAS {^show_status_all$}
{
    #LIST {characters} {CREATE} $status[];
    #FORMAT {text} {%-12s  %+5s %+5s} {Character} {MaxHp} {MaxSp};
    #SHOWME {$text};
    #FOREACH {${characters[]}} {i}
    {
        #IF {&{status[$characters[$i]][maxsp]}}
        {
            #FORMAT {text} {%-12s %+5s %+5s} $characters[$i] $status[$characters[$i]][maxhp] $status[$characters[$i]][maxsp]
        };
        #ELSE
        {
            #FORMAT {text} {%-12s %+5s      } $characters[$i] $status[$characters[$i]][maxhp]
        };
        #SHOWME {$text}
    };
    #UNVARIABLE text;
    #UNVARIABLE i;
    #UNVARIABLE characters
}

show_status_all
Character     MaxHp MaxSp
Alice          200    75
Bob            150   100
Jath           350
Suppose Jath has just joined the wizard guild, so he gains some spell points, and Alice has been banished from the same organisation!:
Code:
#VARIABLE {status[Jath]} {100}
#UNVARIABLE {status[Alice][maxsp]}

show_status_all
Character     MaxHp MaxSp
Alice          200
Bob            150   100
Jath           350   100
Needless to say things can get quite complicated and having multiple levels of nesting can get difficult to read as all the data is stored in one line in script files, e.g. as it stands the status variable is now:
Code:
#VARIABLE {status}={{Alice}{{maxhp}{200}}{Bob}{{maxhp}{150}{maxsp}{100}}{Jath}{{maxhp}{350}{maxsp}{100}}}
Anyhow, enjoy it if you can get your head around it... Use your Head
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