| View previous topic :: View next topic |
| Author |
Message |
new_to_tin_tin
Joined: 05 Jan 2011 Posts: 16
|
Posted: Thu Apr 26, 2012 6:26 pm Post subject: Nested arrays in a list |
|
|
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 |
|
 |
Scandum Site Admin
Joined: 03 Dec 2004 Posts: 3274
|
Posted: Thu Apr 26, 2012 6:58 pm Post subject: |
|
|
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 |
|
 |
new_to_tin_tin
Joined: 05 Jan 2011 Posts: 16
|
Posted: Fri Apr 27, 2012 6:01 pm Post subject: |
|
|
Thanks, that did the trick.
I much prefer this method. Much cleaner, especially when dealing with deletes and inserts. |
|
| Back to top |
|
 |
Slysven
Joined: 10 Apr 2011 Posts: 254 Location: As "Jomin al'Bara" in WoTMUD or Wiltshire, UK
|
Posted: Sat Apr 28, 2012 12:38 pm Post subject: |
|
|
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...  |
|
| Back to top |
|
 |
|