Yes, the Lua script is syntactically correct, but there are some caveats regarding its execution in World of Warcraft Classic:
-
The script attempts to register for the "ENCOUNTER_START" event, which may not function as expected in Classic. This event was introduced in later versions of WoW and provides data about dungeon/raid boss encounters[12]. While the Classic client supports many events from the original game, some modern events might not be implemented or might behave differently.
-
Splitting the script across two separate /run commands as shown in your query would cause issues. When executed this way, the first part would create the frame and register the event, but the function definition in the second part would be separate and not properly attached. The script needs to be run as a single command[1][3].
-
For Classic WoW, this script would be better implemented as a proper addon with .toc and .lua files, or at least combined into a single /run command[15].
A corrected version for a single /run command would be:
/run local frame = CreateFrame("Frame"); frame:RegisterEvent("ENCOUNTER_START"); frame:SetScript("OnEvent", function(self, event, encounterID, encounterName) print("Encounter ID:", encounterID, "Encounter Name:", encounterName) end)
If you want to test if this event actually works in Classic, you could use this script to register for multiple combat-related events:
/run local f = CreateFrame("Frame"); f:RegisterEvent("ENCOUNTER_START"); f:RegisterEvent("PLAYER_REGEN_DISABLED"); f:SetScript("OnEvent", function(self, event, ...) print(event, ...); end)
This would print both when the ENCOUNTER_START event fires (if available) and when you enter combat (PLAYER_REGEN_DISABLED)[15]. If you only see the combat events but never ENCOUNTER_START, that would confirm the event isn't implemented in Classic.