PQR is 100% based on the World of Warcraft Lua implementation. This means, that any function made available to the Lua engine is available to you. A rotation is executed by starting at the first ability in a rotation and calling the Lua code in that ability to determine if it returns true, false or nil. If it returns true, it will cast the indicated spell ID. If it returns false or nil, it will call the Lua code for the next ability in the rotation and so on until PQR reaches an ability that returns true, or reaches the end of the rotation in which case it will start over at the first ability.
For a complete list of WoW functions, see: http://www.wowpedia.org/World_of_Warcraft_API
For a a list of PQR functions, see: http://pqrotation.wikia.com/wiki/PQR_Custom_Functions
For full indepth information on the Lua programming language, see this: http://www.lua.org/manual/5.2/
Basic Lua Implementation OverviewEdit
When you look at an ability, it may appear to be a blurb of text that is hard to understand, but the truth is that it can be read left to right, top to bottom just like you were reading a sentence once you understand the syntax.
Note all syntax in this section is case sensitive and is usually lower case. 'If' is not the same as 'if'. 'And' is not the same as 'and.' Etc.
Variables exist to store data for future use, in Lua there are two types of variables… local variables and global variables. It is best programming practice to use global variables only when there is a performance gain to be had, for example, if you want to check the health of your target only once per rotation loop, instead of once per ability because you have multiple abilities that need to check the HP of your target, this might be a good idea. If you are only doing it once or twice , you shouldn’t need a global variable. Global variables are also sensitive to all other WoW addons, so if you are running an addon that uses the same global variable you will run into issues.
‘local’ variable exist to provide a temporary place to save a piece of information, example:
local isSpellAvailable = true This piece of information is only true when you access it from the same area. If you have two abilities, and in ability one you set the local variable isSpellAvailable to true, then your rotation moves onto ability two, the variable you set in ability one has been erased from memory and no longer exists.
‘global’ variables are variables that are set without the local prefix. This value will exist in memory until WoW is reloaded and will not change until you change the value.
isSpellAvailable = true
This variable would be accessible from all abilities in your rotation, and would not reset on the next loop.
IMPORTANT: You only use one equal sign when assigning a value to a variable.
The if StatementEdit
The “if” statement basically says “if X is true then DO THIS BECAUSE IT WAS TRUE .”
An if statement must have a ‘then’ statement to indicate that nothing else will be checked, and an ‘end’ statement to indicate that there is nothing left to do in the current if statement. Here is an actual example, the green text is just comments to explain:
if PQR_SpellAvailable(35395) then –if the spell 35395 is available:
return true –Return true, if the spell is available, so PQR knows to cast this ability
end –Nothing remaining to do here.
Else and ElseIfEdit
The “elseif” statement allows you to check multiple variable in a top-to-bottom order. If one returns true, the rest of the statement is not run.
The “else” statement allows you to perform code if all “if” or “elseif” statement return false or nil.
Example: if PQR_SpellAvailable(35395) then –If spell ID 35395 is available then…
elseif PQR_SpellAvailable(24275) then –If the above spell was NOT available, and this spell IS available
elseif PQR_SpellAvailable(12345) then –If the above 2 spells were not available, and spell 12345 is avail:
else –No spells were available at all, perform the code here:
And…Or… and parenthesesEdit
An if statement can do much more than just check if a single value is true.
You can use the ‘or’ statement to see if ANY value is true.
If spell 35395 OR spell 24275 are available then execute the code below…
If PQR_SpellAvailable(35395) or PQR_SpellAvailable(24275) then
The ‘and’ statement allows you to require multiple statements to be true. If spell 35395 AND spell 24275 are available then execute the code below
If PQR_SpellAvailable(35395) and PQR_SpellAvailable(24275) then
Parentheses allow you to compare certain combinations of 'and' and 'or' statements:
If spell 35395 and 24275 are available OR spell 12345 is available then execute the code below if (PQR_SpellAvailable(35395) and PQR_SpellAvailable(24275)) or PQR_SpellAvailable(12345) then
If not true, and Comparing NumbersEdit
You may at one point need to check if a value is not true, there are multiple ways to do this, however the simplest is to check if the value is false.
NOTE: When comparing a value for equality, you use TWO equal signs, as opposed to assigning it a value, in which case you only one.
If spell 35395 is false then execute the code below:
If PQR_SpellAvailable(35395) == false then
--the above statement was true, the spell is NOT available.
--the above statement was false, the spell IS available.
NOTE: Checking for false values can get a little confusing to read, as you can see above by my comments. It is best practice to always compare in the positive whenever possible, and to check if a value is true rather than false.
You may at one point need to check the health of a target, to check if it is below 20% health.
Save a local variable with the targets health percentage:
local unitHealth = UnitHealth(“target”) / UnitHealthMax(“target”) * 100
if the local variable we saved above is less than or equal to twenty then perform the code below
if unitHealth <= 20 then
Other ways to compare are:
> Greater than
>= Greater than or equal to
== is equal to
<= less than or equal to
< less than