[Trigger] Can I explode an entered string?

Level 6
Joined
Jan 8, 2009
Messages
140
I know in PHP at least if I have a string separated by spaces for example I can have it returned as an array of its parts like "one two three four" would be returned as word[0] = one, word[1] = two, etc. Can I do this in wc3? I assume I might need to use jass which I'm not very familiar with. This is mostly in the context of handling player commands so I can check for each part rather than checking between variable length substrings
 

NEL

NEL

Level 6
Joined
Mar 6, 2017
Messages
113
You can do this in Zinc or vJass using StringIterator.

Example:
JASS:
//! zinc
library Sample 

    requires 
        StringIterator 

{
    private function onInit() {
        trigger tr = CreateTrigger();
        TriggerRegisterPlayerChatEvent(tr, Player(0), "", false);
        TriggerAddAction(tr, function(){
            // Get the Entered Chat Message
            string s = GetEventPlayerChatString();
           
            // Create StringIterator
            StringIterator iter = StringIterator.create(s);
           
            // whitespace as delimiter
            iter.setDelims(" ");
           
            // Print the result
            BJDebugMsg("Message inserted by player:\n");
            while( !iter.end ) {
                BJDebugMsg(iter.read());
            }
        });
       
        tr = null;
    }
}
//! endzinc
 
Level 6
Joined
Jan 8, 2009
Messages
140
that's exactly what I was after thanks a lot. As somewhat of a novice though I can't seem to get this working in the way I need on my own... How do I modify the script so that I can call the function in custom script in GUI and pass through a string variable and have it return the list of strings to an array variable? I tried playing around with it but I just getting syntax errors lol
 
Last edited:
Top