BigO wrote:Syne wrote:I think I understand your question. Yes, you can do that, like this:
Code: Select all
[C(Iterations): eval ("Weapon" + roll.count + " = [varname]")]
Remember that eval() runs the contents of the string as code, so to the praser it will look like multiple iterations of Weapon# = [varname]. Note that the quotes contain the right part of the equation as well.
Though depending on the information you want stored, it might be better to use a list. No need to resort to eval().
Also, I want to thank the developers for this awesome addition. It really adds functionality.
It would be great if you had a possibility of choosing another delimiter for list, though. *thinks* and making lists/property strings from variables.
Your first post, and you already have a solid understanding of macro syntax? You must have been lurking for a while
Welcome to the boards!
Actually his syntax is wrong. You can't have [] inside another []. But if you remove them it works fine
.
Also what I was trying to do I only needed to do once so loop doesn't really help. But his eval() setup made me realize what I was doing wrong. I was trying to do something like:
Code: Select all
[h:eval("Armor" + ArmNum) = ...... ]
Problem was it kept eval the first part and didn't put Armor# = to what I was trying to set. Combine that with the fact I had to have some " " marks in there for other functions. I did however realize that I needed to put it all under 1 eval and once I got the " and ' order sorted it worked fine. The end result was this line of the code:
Code: Select all
[H:eval ('Armor' + ArmNum + ' = setStrProp(eval("Armor" + ArmNum), "IsLight", ArmLight)'))]
The full macro is just like K.fan weapon editor except it only does 3 armors and there is a check box for if the armor is Light rather then having the player enter a value. Here is the finished working code:
Code: Select all
---Variables Needed
Armor1:Name=Cloth ; ArmorBonus=0 ; EnchantBonus=0 ; CheckPenalty=0; SpeedPenalty=0 ; Notes/Powers=None ; Keyword=None ; IsLight=1 ;
Armor2:Name=Hide ; ArmorBonus=5 ; EnchantBonus=0 ; CheckPenalty=1; SpeedPenalty=0 ; Notes/Powers=None ; Keyword=None ; IsLight=1 ;
Armor3:Name=Plate ; ArmorBonus=8 ; EnchantBonus=0 ; CheckPenalty=2; SpeedPenalty=1 ; Notes/Powers=None ; Keyword=None ; IsLight=0 ;
---Armor Setup v2
[h: ArmList = ""]
[h, c(3,""): ArmList = ArmList + getStrProp(eval("Armor" + roll.count), "Name") + ","]
[h: fail = input("ArmNum | " + ArmList + " | Select Armor to edit | LIST")]
[h: abort(fail)]
[h: ArmNum = ArmNum + 1]
[h: ArmName = "Armor" + ArmNum]
[h: ArmProps = eval(ArmName)]
[h:ArmLight = getStrProp(ArmProps, "IsLight")]<BR>
[h: ArmProps = deleteStrProp(ArmProps, "IsLight")]
[h: NumProps = countStrProp(eval(ArmName))]
[h: abort(NumProps)]
[h: fail = input("blah | " + ArmNum + " | Armor number | LABEL",
" ArmLight | "+eval('ArmLight')+" | This is Light Armor | CHECK",
ArmName + " | " + ArmProps + " | Armor properties | PROPS | setvars=true")]
[h: abort(fail)]
[H:eval ('Armor' + ArmNum + ' = setStrProp(eval("Armor" + ArmNum), "IsLight", ArmLight)'))]
New properties for armor #{ArmNum}:
<table border=0>
[h: NumProps = countStrProp(eval(ArmName)) - 1]
[h,p,c(NumProps,""):
"<tr><td style='padding:0px 5px'><b>"
+ indexKeyStrProp(ArmProps,roll.count-1)
+ "</b></td><td>"
+ eval(indexKeyStrProp(ArmProps,roll.count-1))
+ "</td></tr>" ]
</table>
Thanks for the help.