WoW:API CreateMacro: Difference between revisions

From AddOn Studio
Jump to navigation Jump to search
m (Move page script moved page API CreateMacro to API CreateMacro without leaving a redirect)
 
(2 intermediate revisions by 2 users not shown)
Line 2: Line 2:
Creates a new macro command/button.
Creates a new macro command/button.


CreateMacro("name", iconIndex, "body", perCharacter, local)
  CreateMacro(name, iconFileName, body, perCharacter)


== Arguments ==
== Arguments ==
:(name, icon, body, perCharacter, local)
:(name, iconFileName, body, perCharacter)


; name : String - The name of the macro to be displayed in the UI. The current UI imposes a 16-character limit.
; name : String - The name of the macro to be displayed in the UI. The current UI imposes a 16-character limit.


; icon : Numeric - A 1-based iconTextureId (index of icon textures as displayed in "Change Name/Icon" UI). Check the current number if icon textures available by calling [[API GetNumMacroIcons|GetNumMacroIcons()]].
; iconFileName : String , The icon name.


; body : String - The macro commands to be executed. If this string is longer than 255 characters, only the first 255 will be saved.
; body : String - The macro commands to be executed. If this string is longer than 255 characters, only the first 255 will be saved.


; perCharcter : Numeric - nil will create a "General" saved macro, 1 will save it as "Per Character"
; perCharcter : Numeric - nil will create a "General" saved macro, 1 will save it as "Per Character"
; local : 1 if the macro is to be saved on the server, nil if saved locally in the user's WTF folder


== Returns ==
== Returns ==
Line 23: Line 21:
== Example ==
== Example ==
; General (All Character) Macros :
; General (All Character) Macros :
  local macroId = CreateMacro("MyMacro", 12, "/script CastSpellById(1);", nil, 1);
  local macroId = CreateMacro("MyMacro", "INV_MISC_QUESTIONMARK", "/script CastSpellById(1);", nil);
local macroId = CreateMacro("MyMacro", 12, "/script CastSpellById(1);", nil, nil);


; perChar (Per Character) Macros :
; perChar (Per Character) Macros :
  local macroId = CreateMacro("MyMacro", 12, "/script CastSpellById(1);", 1, 1);
  local macroId = CreateMacro("MyMacro", "INV_MISC_QUESTIONMARK", "/script CastSpellById(1);", 1);
local macroId = CreateMacro("MyMacro", 12, "/script CastSpellById(1);", 1, nil);


== Notes ==
== Notes ==
* As of 3.0 with Macros saving serverside (default) the API has changed. perCharacter, and local have switched spots. Pre-3.0 local was always nil.
* As of [[Patch 4.3]] this is working as shown - the unused parameter has been removed.
 
* This function will generate an error if the maximum macros of the specified kind already exist (36 for per acount and 18 for per character).
* This function will generate an error if the maximum macros of the specified kind already exist (36 for per acount and 18 for per character).
* It is possible to create macros with duplicate names. You should enumerate the current macros using [[API GetNumMacros|GetNumMacros()]] and [[API GetMacroIconInfo|GetMacroIconInfo(macroId)]] to ensure that your new macro name doesn't already exist. Macros with duplicate names can be used in most situations, but the behavior of macro functions that retrieve a macro by name is undefined when multiple macros of that name exist.
* It is possible to create macros with duplicate names. You should enumerate the current macros using [[API GetNumMacros|GetNumMacros()]] and [[API GetMacroIconInfo|GetMacroIconInfo(macroId)]] to ensure that your new macro name doesn't already exist. Macros with duplicate names can be used in most situations, but the behavior of macro functions that retrieve a macro by name is undefined when multiple macros of that name exist.
 
* This function may not be called in combat anymore, as of [[Patch 2.0]].
This function may not be called in combat anymore, as of 2.0.

Latest revision as of 04:45, 15 August 2023

WoW API < CreateMacro

Creates a new macro command/button.

 CreateMacro(name, iconFileName, body, perCharacter)

Arguments[edit]

(name, iconFileName, body, perCharacter)
name
String - The name of the macro to be displayed in the UI. The current UI imposes a 16-character limit.
iconFileName
String , The icon name.
body
String - The macro commands to be executed. If this string is longer than 255 characters, only the first 255 will be saved.
perCharcter
Numeric - nil will create a "General" saved macro, 1 will save it as "Per Character"

Returns[edit]

macroId
Numeric - The 1-based index of the newly-created macro, as displayed in the "Create Macros" UI.

Example[edit]

General (All Character) Macros
local macroId = CreateMacro("MyMacro", "INV_MISC_QUESTIONMARK", "/script CastSpellById(1);", nil);
perChar (Per Character) Macros
local macroId = CreateMacro("MyMacro", "INV_MISC_QUESTIONMARK", "/script CastSpellById(1);", 1);

Notes[edit]

  • As of Patch 4.3 this is working as shown - the unused parameter has been removed.
  • This function will generate an error if the maximum macros of the specified kind already exist (36 for per acount and 18 for per character).
  • It is possible to create macros with duplicate names. You should enumerate the current macros using GetNumMacros() and GetMacroIconInfo(macroId) to ensure that your new macro name doesn't already exist. Macros with duplicate names can be used in most situations, but the behavior of macro functions that retrieve a macro by name is undefined when multiple macros of that name exist.
  • This function may not be called in combat anymore, as of Patch 2.0.