Gnome sequencer step sequence

Im working on coding a smarter step sequence. What information must be in the step sequence in order for it to function and what cannot be in the step sequence. I am trying to make a Slightly smarter macro for gladiator.

-- Prot Gladiator
Sequences["GLADIATOR"] = {	
StepFunction = [[
	if UnitMana("player") > 50 then
		step = 7
	else
	usable, nomana = IsUsableSpell("Shield Slam");
	if  usable then
		step =1
	 else
	 usable, nomana = IsUsableSpell("Revenge");
	 if usable then
		step = 2 
	 else
	  usable, nomana = IsUsableSpell("Victory Rush");
	 if usable then
		step = 3
	else
	usable, nomana = IsUsableSpell("Storm Bolt");
	if usable then
		step = 4
	else
	usable, nomana = IsUsableSpell("Execute");
	if usable then
		step = 5
	else 
		step = 6
	end
]],
PreMacro = [[
/targetenemy [noharm][dead]
/cast [combat] Berserker Rage
/cast [combat] Shield Block
/cast [combat] Bloodbath
]],
'/cast Shield Slam',
'/cast Revenge',
'/cast Victory Rush',
'/cast Storm Bolt',
'/cast Execute',
'/cast Devastate',
'/cast Heroic Strike',
PostMacro = [[
/startattack
/use [combat]13
/use [combat]14
/cast Shield Slam
]],
}

and i get an error I’m not sure the meaning of when i run the macro.

Message: Interface\FrameXML\RestrictedExecution.lua:397: Call failed: Interface\FrameXML\RestrictedExecution.lua:124: [string "	local step = self:GetAttribute('step')..."]:36: 'end' expected (to close 'if' at line 15) near '<eof>'
Time: 12/30/14 19:05:21
Count: 2
Stack: [C]: ?
[C]: ?
Interface\FrameXML\RestrictedExecution.lua:397: in function <Interface\FrameXML\RestrictedExecution.lua:390>
(tail call): ?
(tail call): ?
Interface\FrameXML\SecureHandlers.lua:283: in function <Interface\FrameXML\SecureHandlers.lua:277>
(tail call): ?
[C]: in function 

Click’
Interface\FrameXML\ChatFrame.lua:1542: in function ?' Interface\FrameXML\ChatFrame.lua:4367: in functionChatEdit_ParseText’
Interface\FrameXML\ChatFrame.lua:4041: in function ChatEdit_SendText' Interface\FrameXML\ChatFrame.lua:2686: in function &lt;Interface\FrameXML\ChatFrame.lua:2679&gt; [C]: in functionUseAction’
Interface\FrameXML\SecureTemplates.lua:348: in function `handler’
Interface\FrameXML\SecureTemplates.lua:649: in function <Interface\FrameXML\SecureTemplates.lua:597>
[C]: ?
Interface\FrameXML\SecureHandlers.lua:264: in function <Interface\FrameXML\SecureHandlers.lua:261>
[C]: ?
Interface\FrameXML\SecureHandlers.lua:294: in function <Interface\FrameXML\SecureHandlers.lua:277>
(tail call): ?

Locals: `

If i could get any advice i would appreciate it.

This may help.

I’m really curious how well this would work vs just brute forcing it.

http://www.lua.org/pil/4.3.1.html

“When you write nested ifs, you can use elseif. It is similar to an else followed by an if, but it avoids the need for multiple ends:”

if op == "+" then
      r = a + b
    elseif op == "-" then
      r = a - b
    elseif op == "*" then
      r = a*b
    elseif op == "/" then
      r = a/b
    else
      error("invalid operation")
    end

i’m using the warrior as a start since its easy to run a rotation i was going to expand it to other rotations and use situational cooldowns. when learning i like to start simple and work toward the compex.

Thank you for the help eventually i want to write a guide on how to do step sequences this way and include examples on how to check for buffs, debuffs procs etc.

Have you made any progress on your macro?

A couple of pointers in addition what’s already been posted:

UnitMana is a deprecated function - in other words it’s not recommended for use and is going to be removed from the game at some point. Instead you should be using:

UnitPower("player", SPELL_TYPE_MANA)

or, if mana is the main resource for that player, you can just use

UnitPower("player")

“if” statements are quite versatile, but each “if” statement MUST have an assocaited “end” statement or your code will fall over, e.g.

if usable then
   step = 2
end

if usable then step = 2 end

if usable then
   step = 2
else
   step = 3
end

if usable then
   step = 2
elseif nomana then
   step = 3
end

are all valid statements. You can also nest if statments:

if usable then
   if nomana then
      step = 3
   else
      step = 4
   end
else
   step = 5
end

The important point is that each “if” statement is treated as a block that finishes with an “end” statement.

Also note that while this is possible, adding this degree of intelligence to the step function is botting. It is one thing to create a fall-through on a macro’d rotation, when the macro chooses what effect to execute based on player variables that are dynamic rather than static, that meet’s Blizzard’s definition of botting. So while the programmer in me would love to see what is possible, the player in me suspects your work is going to draw Blizzard’s ire and your work will force me to stop playing again because I am unable to play without something like GS.

Thus, I repudiate your efforts and ask you to stop publicly developing such logic.

On my latest attempts i have cleaned up the coding but if i add any kind of logic to my macros i get the same error. i think blizzard is already ahead of me and has it broken. Although i haven’t given up yet I am needing to do more research on my specific errors.

My understanding is that GS compiles the sequences on load/reload, so the logic should fail. But again, I am not a WoW or LUA programmer and have not dug into the code. I limit my support to simple things like encoding, syntax and parsing, believe me there are enough people who just copy and paste macros (error filled ones at that) to keep me as busy as I might like.

Again, as a (now retired/disabled) programmer: I appreciate your efforts
As a disabled WoW player: It scares me.

I agree and support everything Mr. B is saying about the potential for Blizzard’s attention to be drawn to this addon.

As far as the code goes, GS does not compile or validate the actual code. That’s left to Blizzards secure handlers and all they are currently doing is passing it through the Lua pcall function (I have copies of all Blizzard’s lua coding extracted from the game client).

Bottom line, as far as I can see at the moment - if the lua code you’re using is not working as expected, then there’s simply something wrong with it. I’d need to see both the exact code you’re using and the errors it’s producing to confirm that. If you want to do that though, I’d suggest you PM me.

[quote quote=21189]<snip>As far as the code goes, GS does not compile or validate the actual code. That’s left to Blizzards secure handlers and all they are currently doing is passing it through the Lua pcall function (I have copies of all Blizzard’s lua coding extracted from the game client).<snip>
[/quote]

Deepac, I understand that you know far more about LUA interfacing with WoW than I, but it is doing something at load else people would not be seeing LUA errors at load time for sequences that have not been nor will ever be used. Now it may well be WoW that is doing the compiling, I really do not know but if I get one more PM in game about an unescaped “’” throwing a LUA error or as is the way it is normally phrased to me is:“GS sucks can you fix it” So some validation is happening somewhere at load else Thunder Chickens would not be having issues with Avenger’s Shield :slight_smile:

Whenever any lua file is loaded into the game, the client itself does some rudimentary validation of lua syntax. Since the sequences are being entered into a lua file that is essentially part of the GS addon this will also happen for that file. That’s what will cause errors on logging into the game (or at least when GS is loaded).

A second functional check is performed by the game client via the RestrictedExecution code written by Blizzard using the lua pcall function when an attempt is made to actually execute the code.

I’m quite happy to help out with these errors as I have a lot of experience debugging wow’s flavour of lua, so feel free to pass the pm’s straight on to me (assuming you’re happy doing that of course, I fully understand and appreciate any objections you may have).

[quote quote=21210]Whenever any lua file is loaded into the game, the client itself does some rudimentary validation of lua syntax. Since the sequences are being entered into a lua file that is essentially part of the GS addon this will also happen for that file. That’s what will cause errors on logging into the game (or at least when GS is loaded).

A second functional check is performed by the game client via the RestrictedExecution code written by Blizzard using the lua pcall function when an attempt is made to actually execute the code.
[/quote]
Good to know. I knew some validation was going on, but as I said I did not know specifically what was being checked.

To be completely honest, other than a small few really screwy sequence files people send me, I already have a frequent issues post that I simply add things to and suggest they look at number X and link it to them.

I live by the philosophy it is better to teach a man to fish than to give him a fish. Plus, I am a disabled former programmer, LUA is just after my time LOL I started with FORTRAN 7 and punchcards, these days it is mostly ECMA, ObjC and PHP. Script syntax is no problem, but thank you for the offer. Should I get swamped, I will send them your way.

I think, from experience of learning lua, it would probably drive you nuts after programming with OOP. I tried learning objC once, but I just couldn’t get used to the event names and the like so gave up on it.

Yeah i tried this and it didn’t do anything just made my game drop frames when i spammed it :frowning:

I am a programmer but haven’t done alot of lua work. I am curious if I am reading this function correctly.
I will comment after the line with --. Assume 8 macros.


StepFunction = [[ -- Name of Function plus opening statement
	limit = limit or 1  -- Limit = current Limit or 1 if null
	if step == limit then   -- if step equals limit do next block
		limit = limit % #macros + 1  
		step = 1 -- resets the value of step back to first macro
	else  -- this is done if step does not equal limit
		step = step % #macros + 1 
	end   -- end if statement 
]], -- Closing function

What does the line ( limit = limit % #macros + 1 ) really mean?

If I am understanding correctly you may be able to do the following:


StepFunction = [[ 
	limit = limit or 1  
	if step == limit then   
		limit = limit % #macros + 1  
		step = 1 
	else  
                if UnitPower("player", SPELL_POWER_RUNIC_POWER) >= 45 then 
                   step = 8
                else 
		   step = step % #macros + 1
                end 
	end    
]], 

This in theory, if you put frost strike as the last macro would frost strike as priority over all others if the runic power was greater then 45. Otherwise it would iterate normally through the macro list. With this is there a way to not goto step 8 unless power reached greater then 45? Could you set the limit equal to number of macros minus 1?

So I had some time to play with this and found a few things.

Inside of StepFunction, you can not access UnitPower(“player”, whatever), or API hooks like it because they are sandboxed off.

It will throw the error.

But, inside PreMacro, PostMacro, or the macro itself, you can access UnitPower, Buffs, etc.

For example, this code below will print the targets buffs to the chat window.

Sequences["Macro"] = {	

PreMacro = [[
/targetenemy [noharm][dead]
]],

'/cast Tickle Attack',
/run for i=1,40 do local B=UnitBuff("target",i); if B then print(i.."="..B) end end

PostMacro = [[
/startattack
/use [combat]13
/use [combat]14
]],

}

Now the question is, which I ran out of time to investigate last night, can you have logic (even minimal logic) inside of that run block that will influence what is cast?

There is a way to influence what is cast using a run block with GS, but I’m reluctant to publicise how as adding this level of logic contravenes something Blizzard have gone to great lengths to prevent and is likely to get this addon banned. However, as an interested party I am happy to discuss via PM if you wish.

@Sean
% is the lua modulus operator

is lua shorthand for the size of an array (replaces the deprecated table.getn)

Cool, I noticed the same effect on secure handlers and the step function. Pretty sure, that limits down the power of semi-intelligent macros. I was looking to see if it was possible to only hit the resource burner if that resource got over a certain amount. otherwise iterate through the builders. Not that big of deal.