Skip to content
everloot

Lore archive · Warcraft Wiki, 2023 dump

API RunScript

Last wiki revision 2022-07-22

Executes a string of Lua code. RunScript(script)

  • script: - The code which is to be executed.
  • To define a function dynamically you could do:

local retExpr = '"Hello " .. UnitName("target")'; RunScript("function My_GetGreeting return " .. retExpr .. ";end");

  • The My_GetGreeting function will be defined to return Hello followed by the name of your target.
  • This function is NOT recommended for general use within addons for a number of reasons:
  • 1. It'll do whatever you tell it, that includes calling functions, setting variables, whatever.
  • 2. Errors in the script string produce the error popup (at least, they produce the UI_ERROR_MESSAGE event).
  • On the other hand, it's invaluable if you need to run code that is input by the player at run-time, or do self-generating code.
  • The standard Lua function API loadstring, which can overcome all of the problems of RunScript described above.

Source

https://warcraft.wiki.gg/wiki/API_RunScript · retrieved 2023-11-13 · CC BY-SA 4.0

Converted from wikitext with templates, tables and images removed, so some sentences may be missing values.

This archive predates WoW: Forever. For collected gameplay facts see the Forever database. Search the archive.