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

1.99.7 beta nested lists issue

 
Post new topic   Reply to topic    The TinTin++ message board Forum Index -> Bug Reports
View previous topic :: View next topic  
Author Message
Shaiith



Joined: 11 Jul 2009
Posts: 64

PostPosted: Thu Aug 13, 2009 8:08 pm    Post subject: 1.99.7 beta nested lists issue Reply with quote

1.99.7 beta

getting an error when I try to delete bar.

Code:
#VARIABLE {__events}={{bar}{{baz}{boo}}}
#list __events DEL bar
#LIST DEL: Invalid index: bar


I'm sure I'm doing something wrong. How should I restructure?
Back to top
View user's profile Send private message
Scandum
Site Admin


Joined: 03 Dec 2004
Posts: 3796

PostPosted: Thu Aug 13, 2009 9:26 pm    Post subject: Reply with quote

List only takes numeric arguments.

You'll probably want to use:

Code:

#var {__events} {{bar}{1}{baz}{1}{boo}{1}}

#unvar __events[bar]


The {1} is so $__events[baz] reports something other than 0, which is the default for non existent nested variables.
Back to top
View user's profile Send private message Send e-mail
Shaiith



Joined: 11 Jul 2009
Posts: 64

PostPosted: Thu Aug 13, 2009 9:40 pm    Post subject: Reply with quote

What's the point of associative lists if you can't directly look them up by the extended name? You have to find the index and then access that?
Back to top
View user's profile Send private message
Scandum
Site Admin


Joined: 03 Dec 2004
Posts: 3796

PostPosted: Thu Aug 13, 2009 9:57 pm    Post subject: Reply with quote

The #list command is exclusively for associative arrays that behave like normal arrays.

What is it exactly you're trying to do?
Back to top
View user's profile Send private message Send e-mail
Shaiith



Joined: 11 Jul 2009
Posts: 64

PostPosted: Fri Aug 14, 2009 4:53 pm    Post subject: Reply with quote

Is this intended behavior? foreach on an empty list, I'd expect to be the same as #nop.

Code:
#var __events {}
#OK. VARIABLE {__events} HAS BEEN SET TO {}.

#foreach ${__events[]} {item} {#showme $item}
0

#var __events;
#VARIABLE {__events}={}


It looks like this actually runs the foreach an extra iteration. Note: I haven't put in the defensive safeguards in the below yet.

Code:
#ali event_raise
{
  #foreach {${_events[%1]}} {handler}
  {
    #showme EVENT_RAISE ${_events[%1][$handler]} %0;
    ${_events[%1][$handler]} %0;
  }
}


Code:
#var _events
#VARIABLE {_events}={{test}{{testecho}{#showme test run}}}

event_raise test                               
EVENT_RAISE #showme test run test
test run test
EVENT_RAISE 0 test
#NO SESSION ACTIVE. USE: #session {name} {host} {port} TO START ONE.

event_raise unfound
EVENT_RAISE 0 unfound
#NO SESSION ACTIVE. USE: #session {name} {host} {port} TO START ONE.
]
Back to top
View user's profile Send private message
Shaiith



Joined: 11 Jul 2009
Posts: 64

PostPosted: Fri Aug 14, 2009 5:15 pm    Post subject: Reply with quote

Followup thought. It might make some sense to define a null (or nil or whatever) constant instead of having 0 or "" serve for undefined.

Excel has this problem and I constantly have to help people understand that 0, an empty cell, and "" are three different things.

#if {${_events[bar]} == 0} (it's a pain to code around the cases where you want the value of 0 to have different meaning from undefined, returning an empty string just changes it to difficulty in seperating "" and undefined)

#if {${_events[bar]} == null} would avoid this issue evaluates to true ONLY if ${_events[bar]} is undefined, #var x null does not assign null, it assigns "null".
Back to top
View user's profile Send private message
Shaiith



Joined: 11 Jul 2009
Posts: 64

PostPosted: Fri Aug 14, 2009 5:22 pm    Post subject: Reply with quote

Solved it, the odd behavior was due to not having an additional [] in the foreach.

Code:
#ali event_raise
{
  #foreach {${_events[%1][]}} {handler}
  {
    ${_events[%1][$handler]} %0;
  }
}


was what I wanted.
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 -> Bug Reports 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