Foreach token

From EventScripts Community Encyclopedia


Overview

Syntax: foreach token <variable> <string> <separator> <command>

Note: Command parameters are described inside the < and > characters. Optional parameters are contained within [ and ] characters.

Variation of this command that doesn't expand variables: {{{x}}}

Description

Runs a command on every token part of a string you provide. It stores the token in variable. You can also use it with an es before it.

Note: It doesn't expand server variables!


Parameters

  • variable - a variable where you wish to store the token
  • string - the string that is used to loop on each token
  • separator - the separator that is between each token
  • command - the command that will be looped, use es_* commands in it to expand variables.


Examples

 // display all alphabetical letters
 es_xsetinfo temptoken 0
 foreach token temptoken "a-s-d-f-g-h-j-k-l-m-n-o-p-q-r-s-t-u-v-w-x-y-z" "-" "es_msg server_var(temptoken) is a part of the token."
 
 // example with es
 es_xsetinfo tempstring "1-6-3-9-2"
 es_xsetinfo tempcmd "es_tell server_var(temptoken) Hello, you are listened in a string."
 es foreach token temptoken server_var(tempstring) "-" server_var(tempcmd)


Notes

  • The variable you defined with <variable> will be set to the current token-part from the loop. You can access it with server_var(<variable>)


See also

External links

foreach

{{{category}}}

blog comments powered by Disqus