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

How to properly pass an array to an alias?

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



Joined: 01 May 2017
Posts: 10

PostPosted: Thu May 11, 2017 1:44 pm    Post subject: How to properly pass an array to an alias? Reply with quote

Objective: have a an ALIAS that can receive an associative array and display the keys and values on a formatted line using ECHO. The array passed can come from multiple places and will vary in content.

Questions:
1. How can I properly pass an array to the ALIAS? I am having difficulty doing it.

2. The looping structure works (tested by defining the array within the ALIAS instead of passing it in). But is this the best way to read and write key/value pairs? Did I do it right and efficiently?

3. BONUS: In regards to #2 above, it prints out the items in the array in reverse order from which they were added. Is there a way to loop backwards or sort the array/list?

Code:
Code:

#VAR message[MobCount] $mobCount;
#VAR message[MobAttacking] $isMobAttacking;
#VAR message[MobHealth] $mobHealth;
#VAR message[MobName] $mobName;
printStatus $message;


#ALIAS {printStatus} {
        #VAR mess {%1}; #NOP mess isn't assigned an array;
        #LIST {keys} {create} $mess[];
        #FORMAT {text} {%c==STATUS: %c}{<fca>}{<099>};

        #FOREACH {${keys[]}} {i} {
                #FORMAT {text} {%s %c%s:%c %s%c} {$text}{<fca>}{$keys[$i]}{<fac>}{$mess[$keys[$i]]}{<099>};
        };
        #SHOWME $text;
};
Back to top
View user's profile Send private message
dorian



Joined: 29 Jul 2012
Posts: 62

PostPosted: Thu May 11, 2017 2:32 pm    Post subject: Reply with quote

take look at this post

http://tintin.sourceforge.net/board/viewtopic.php?t=2380
Back to top
View user's profile Send private message
oneor11



Joined: 01 May 2017
Posts: 10

PostPosted: Fri May 12, 2017 6:18 am    Post subject: Reply with quote

Thanks for the link. Much of that was a bit over my head. However, I got #1 and #3 of my questions answered through experimentation.

1. If I wrap the $message in braces like {$message} then it operates as an array when passed to the alias. I don't conceptually understand why this is so. Now it leaves me wondering when I should use braces and when I shouldn't, much like when I should use a semicolon and when I shouldn't.

2. To solve the backwards readout problem I replaced the #FOREACH with a #LOOP and looped from the top element down. #LOOP &message[] 1.
Back to top
View user's profile Send private message
PowerGod



Joined: 04 Aug 2014
Posts: 306

PostPosted: Fri May 19, 2017 5:29 pm    Post subject: Reply with quote

1. Mainly is always better to use braces, so you will not have issues with spaces.
The situations when you don't use them mainly are the ones where you are really hacking the scripting system.
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