ok I had a look at your campaign file and you're in the right direction, but not quite there. You have created a 'handler macro' per button. That is terribly inefficient. You should create ONE handler macro to which is activated when a button is pressed. Every button can have its own identifier and is passed on as an argument to the handler macro. The handler macro then roughly does this:
Code: Select all
[storedSequence = getLibProperty("storedSequence", "Lib:Spell")]
[buttonPressed = arg(0)]
[newSequence = listAppend(storedSequence, buttonPressed)]
[spellActivated = 1]
[switch(newSequence):
case "1, 2, 3": spell1();
case "1, 8, 2": spell2();
case "5, 4, 7": spell3();
default:spellActivated = 0
]
[if(!spellActivated), CODE:{
[if(listCount(newSequence) > 3), CODE:{
<!-- assuming spell sequence is max 3 characters, if more are pressed, it automatically resets -->
[newSequence = ""]
[ broadcast("That sequence does not exist")]
};{}]
};{
<!-- spell is activated, so reset the sequence -->
[ newSequence = "" ]
}]
[setLibProperty("storedSequence", newSequence, "Lib:Spell")]
<!-- refresh the button panel with the already pressed buttons (hence passed on as argument newSequence). In case newSequence is "" all buttons will be 'unpressed' -->
[macro("showSpellPanel@Lib:Spell"): newSequence]
something like that. This assumes that each spell is its own function, you can also use the code option in the switch statement and put the spell effect in that code block directly. Thats up to you.
This way you only need 1 macro with the form (which is created based on passed on arguments) and 1 macro handler which is always called when a button is pressed. It parses the argument and then automatically calls the 'form macro' again with the new sequence as argument.
note that i added a length check, you can leave that out (or not) and i didn't pay any attention to the last button (probly the 'activate spell') but this only means that you need to add that button identifier to the code in e.g. an if statement. (if that button is pressed, then get the sequence and check which spell it is, else just increase the sequence).
something like that.
edit:
here a working example of the 'showSpellPanel' macro:
Code: Select all
[h: spellCasting = getLibProperty("storedSequence", "Lib:Spell")]
<!-- a bit tricky, but this sequence creates variables fire=7, life=8, air=9 etc. -->
[h:buttonList = "submit,earth,death,ice,spirit,balance,physical,fire,life,air"]
[h,count(10): set(listGet(buttonList, roll.count), roll.count)]
<!-- even trickier: here 9 is added to those variables IF it exists in the sequence -->
[h,foreach(num,spellCasting): set(listGet(buttonList, num), eval(listGet(buttonList, num))+9)]
[h:balance]
<!--------------------------- ACTIVE BUTTONS ------------------------------>
[dialog("Spellcraft"): {
<h2 align="center"><u>CASTING YOUR SPELL</u></h2>
<TABLE border = 1 bgcolor="black" align="center"><form>
<h3 align="center">
    [r: macroLink(strformat('<img alt = "Fire" border = 0 src="%s" />', tblImage("SpellButtons", fire)),"spellHandler@Lib:Spell", "all", fire, "impersonated")]  
[r: macroLink(strformat('<img alt = "Life" border = 0 src="%s" />', tblImage("SpellButtons", life)), "spellHandler@Lib:Spell", "all", life, "impersonated")]  
[r: macroLink(strformat('<img alt = "Air" border = 0 src="%s" />', tblImage("SpellButtons", air)), "spellHandler@Lib:Spell", "all", air, "impersonated")]  
<br>
    [r: macroLink(strformat('<img alt = "Spirit" border = 0 src="%s" />', tblImage("SpellButtons", spirit)), "spellHandler@Lib:Spell", "all", spirit, "impersonated")]  
[r: macroLink(strformat('<img alt = "Balance" border = 0 src="%s" />', tblImage("SpellButtons", balance)), "spellHandler@Lib:Spell", "all", balance, "impersonated")]  
[r: macroLink(strformat('<img alt = "Physical" border = 0 src="%s" />', tblImage("SpellButtons", physical)), "spellHandler@Lib:Spell", "all", physical, "impersonated")]  
<br>
    [r: macroLink(strformat('<img alt = "Earth" border = 0 src="%s" />', tblImage("SpellButtons", earth)), "spellHandler@Lib:Spell", "all", earth, "impersonated")]  
[r: macroLink(strformat('<img alt = "Death" border = 0 src="%s" />', tblImage("SpellButtons", death)), "spellHandler@Lib:Spell", "all", death, "impersonated")]  
[r: macroLink(strformat('<img alt = "Ice" border = 0 src="%s" />', tblImage("SpellButtons", ice)), "spellHandler@Lib:Spell", "all", ice, "impersonated")]  
</h3>
<h4 align="center">
     [r: macroLink(strformat('<img alt = "Submit" border = 0 src="%s" />', tblImage("SpellButtons", 0)), "submit@Lib:Spell", "", "", "impersonated")]     
</h4>
</form></TABLE>
}]
these two macros are the ONLY two you need to use the panel. beyond this you only need the handling of the spells themselves.