Es formatv

From EventScripts Community Encyclopedia


Overview

Syntax: es_formatv <variable> <format-string> [token1] [token2] [token3] [...] [token9]

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

Formats a string according to the format-string and stores it into the variable.

Parameters

  • variable - Variable to store the string into.
  • format-string - String that you would like to place the parameters into. Will place tokenX in format-string in place of %X.
  • tokenX - Tokens that will be placed in the string. The tokens must be variable names! Can have any number of tokens from 0 to 9.


Examples

This example demonstrates the usage of es_formatv and shows the difference between es_format and es_formatv:

es_xsetinfo myvar 0
es_xsetinfo param1 "is"
es_xsetinfo param2 "string"
es_xsetinfo param3 "results from placing"
es_xsetinfo param4 "the format-string."
// Using es_format:
es_format myvar "This %1 the %2 that %3 the tokens into %4" server_var(param1) server_var(param2) server_var(param3) server_var(param4)
es_msg server_var(myvar)
 
// Using es_formatv:
es_xformatv myvar "This %1 the %2 that %3 the tokens into %4" param1 param2 param3 param4
es_msg server_var(myvar)
 
//will display in both cases: This is the string that results from placing the tokens into the format-string. 


Notes

  • The maximum number of tokens supported are nine.
  • This is basically the same command as es_format except that this command only takes server variables as parameters and expands them inside the command, so usually you don't need to have server_var keyword on the line at all.
  • Supports only server variables; event variables are not supported. To use event_vars with this command, save them to a server variable first:
es_set temp event_var(userid)
es_xformatv result "Userid is %1" temp
  • The advantage over es_format is that the variable expansion is a bit faster and less prone to console limitations. Usually you would want to use es_xformatv when outer variable expansion is not needed.
  • You can add quotes to strings with es_formatv by using eventscripts_quote variable as one of the parameters.
  • Useful to bring 2 vars together:
es_xsetinfo var1 "ro"
es_xsetinfo var2 "fl"
es_xsetinfo format 0
es_xformatv format "%1%2" var1 var2
es_msg server_var(format)
 
// Will display: rofl 
  • Useful to add words to a string:
es_xsetinfo string "hello"
es_xsetinfo word1 "world"
es_xformatv string "%1 %2" string word1
es_msg server_var(string)
 
// Will display: "Hello World" 
  • First time available in EventScripts v1.5


See also


External links

es_xformatv


{{{category}}}

blog comments powered by Disqus