Page 1 of 1

Convert String To Array Name

Posted: Sat Mar 19, 2016 12:59 pm
by AyataneIruka
Hi Everyone :)

I've some trouble now , i try to do a Mob Generator and the array of stats and other stuff is base on the mob name, but when oi try to get the stuff with json.get it's not work...

It's possible to take the String From a dropdown list to an array name ?

my Macro :

Code: Select all

[h:mobList = "Eagle,Dragon,Dire Rat"] 

[h:abort(input("mobIndex|"+mobList+"|Select Mob|LIST"))]

[h: mob = listGet(mobList, mobIndex)]


[h:Dummy=json.set("{}","str",10,"dex",10,"con",10,"int",10,"wis",10,"char",10,"Dc1",0,"Weapon1","","Dmg1",0,"Bon1",0,"Weapon2","Dc2",0,"Dmg2",0,"Bon2",0,"Weapon3","Dc3",0,"Dmg3",0,"Bon3",0,"Weapon4","Dc4",0,"Dmg4",0,"Bon4",0,"Weapon5","Dc5",0,"Dmg5",0,"Bon5",0)]
<!--Eagle-->
[h:Eagle=json.set("{}","str",12,"dex",8,"con",16,"int",14,"wis",8,"char",8,"Dc1",2,"Dmg1",12,"Bon1",10,"Dc2",0,"Dmg2",0,"Bon2",0,"Dc3",0,"Dmg3",0,"Bon3",0,"Dc4",0,"Dmg4",0,"Bon4",0,"Dc5",0,"Dmg5",0,"Bon5",0)]

[h:Strength = json.get([r:mob],"str")]
[h:Dexterity = json.get([r:mob],"dex")]
[h:Constitution=json.get([r:mob],"con")]
[h:Intelligence =  json.get([r:mob],"int")]
[h:Wisdom =  json.get([r:mob],"wis")]
[h:Charisma =  json.get([r:mob],"char")]
[h:Weapon1 = json.get([r:mob],"Weapon1")]
[h:Dc1 =  json.get([r:mob],"Dc1")]
[h:Dmg1 =  json.get([r:mob],"Dmg1")]
[h:Bon1 =  json.get([r:mob],"Bon1")]
[h:Weapon2 = json.get([r:mob],"Weapon2")]
[h:Dc2 =  json.get([r:mob],"Dc2")]
[h:Dmg2 =  json.get([r:mob],"Dmg2")]
[h:Bon2 =  json.get([r:mob],"Bon2")]
[h:Weapon3 = json.get([r:mob]at,"Weapon3")]
[h:Dc3 =  json.get([r:mob],"Dc3")]
[h:Dmg3 =  json.get([r:mob],"Dmg3")]
[h:Bon3 =  json.get([r:mob],"Bon3")]
[h:Weapon4 = json.get([r:mob],"Weapon4")]
[h:Dc4 =  json.get([r:mob]at,"Dc4")]
[h:Dmg4 =  json.get([r:mob],"Dmg4")]
[h:Bon4 =  json.get([r:mob],"Bon4")]
[h:Weapon5 = json.get([r:mob],"Weapon5")]
[h:Dc5 =  json.get([r:mob],"Dc5")]
[h:Dmg5 =  json.get([r:mob],"Dmg5")]
[h:Bon5 =  json.get([r:mob],"Bon5")]


[h: y = 3]
    [h: updates = "{ 
                     name: '[r:mob]' ,
                     y: '[r: y = y + 2]',
                   }"
    ]

    [h: copyToken("Dummy", 3, "", updates)]
thanks you for ur help :)

Re: Convert String To Array Name

Posted: Sat Mar 26, 2016 12:02 pm
by AyataneIruka
Finaly i resolve my Trouble by mysel :

U need to convert the string in object array name :

Code: Select all


[h:mobList = "Eagle,Dragon,Rat"]
[h:NumberList="1,2,3,4,5,6,7,8,9,10"]

[h:abort(input("mobIndex|"+mobList+"|Select Mob|LIST"))]

[h:abort(input("NumberIndex|"+NumberList+"|Select Number|LIST"))]

[h: mobChoice = listGet(mobList, mobIndex)]
[h: numChoice = indexOf(NumberList,listGet(NumberList,NumberIndex))]
[h: mob = json.fromStrProp(mobChoice)]

[h:Dummy=json.set("{}","str",10,"dex",10,"con",10,"int",10,"wis",10,"char",10,"Dc1",0,"Weapon1","Element1","","","Dmg1",0,"Bon1",0,"Weapon2","Element2","","Dc2",0,"Dmg2",0,"Bon2",0,"Weapon3","Element3","","Dc3",0,"Dmg3",0,"Bon3",0,"Weapon4","Element4","","Dc4",0,"Dmg4",0,"Bon4",0,"Weapon5","Element5","","Dc5",0,"Dmg5",0,"Bon5",0)]
<!--Eagle-->
[h:Eagle=json.set("{}","str",12,"dex",8,"con",16,"int",14,"wis",8,"char",8,"Dc1",2,"Weapon1","Element1","Neutral","Beck","Dmg1",12,"Bon1",10,"Dc2","Weapon2","Element2","","",0,"Dmg2",0,"Bon2",0,"Dc3","Weapon3","Element3","","",0,"Dmg3",0,"Bon3",0,"Dc4","Weapon4","Element4","","",0,"Dmg4",0,"Bon4",0,"Dc5","Weapon5","Element5","","",0,"Dmg5",0,"Bon5",0)]

[h:Rat=json.set("{}","str",5,"dex",16,"con",8,"int",4,"wis",3,"char",2,"Dc1","Weapon1","Element1","Poison","Bite",1,"Dmg1",6,"Bon1",4,"Dc2","Weapon2","Element2","","",0,"Dmg2",0,"Bon2",0,"Dc3","Weapon3","Element3","","",0,"Dmg3",0,"Bon3",0,"Dc4","Weapon4","Element4","","",0,"Dmg4",0,"Bon4",0,"Dc5","Weapon5","Element5","","",0,"Dmg5",0,"Bon5",0)]

[h:Strength = json.get(mob,"str")]
[h:Dexterity = json.get(mob,"dex")]
[h:Constitution=json.get(mob,"con")]
[h:Intelligence =  json.get(mob,"int")]
[h:Wisdom =  json.get(mob,"wis")]
[h:Charisma =  json.get(mob,"char")]
[h:Weapon1 = json.get(mob,"Weapon1")]
[h:Dc1 =  json.get(mob,"Dc1")]
[h:Dmg1 =  json.get(mob,"Dmg1")]
[h:Bon1 =  json.get(mob,"Bon1")]
[h:Weapon2 = json.get(mob,"Weapon2")]
[h:Dc2 =  json.get(mob,"Dc2")]
[h:Dmg2 =  json.get(mob,"Dmg2")]
[h:Bon2 =  json.get(mob,"Bon2")]
[h:Weapon3 = json.get(mob,"Weapon3")]
[h:Dc3 =  json.get(mob,"Dc3")]
[h:Dmg3 =  json.get(mob,"Dmg3")]
[h:Bon3 =  json.get(mob,"Bon3")]
[h:Weapon4 = json.get(mob,"Weapon4")]
[h:Dc4 =  json.get(mob,"Dc4")]
[h:Dmg4 =  json.get(mob,"Dmg4")]
[h:Bon4 =  json.get(mob,"Bon4")]
[h:Weapon5 = json.get(mob,"Weapon5")]
[h:Dc5 =  json.get(mob,"Dc5")]
[h:Dmg5 =  json.get(mob,"Dmg5")]
[h:Bon5 =  json.get(mob,"Bon5")]


[h: y = 3]
    [h: updates = "{ 
                     name: '[r:mobChoice]' ,
                     y: '[r: y = y + 2]',
                   }"
    ]

    [h: copyToken("Dummy", numChoice, "", updates)]