I need to dynamically pass a formula that involves "json.get(Object, Field)" to eval. How do I it?
Example: I need to know what level of Wizard the token is.
eval('json.get({"Barbarian":0,"Bard":0,"Cleric":0,"Druid":1,"Fighter":0,"Monk":0,"Paladin":0,"Ranger":0,"Rogue":0,"Sorcerer":0,"Warlock":0,"Wizard":2}, "Wizard")')
This will generate an error.
[H: Data = json.set("{}", "Barbarian", 0,"Bard", 0, "Cleric", 0, "Druid", 1, "Fighter", 0, "Monk", 0, "Paladin", 0, "Ranger", 0, "Rogue", 0, "Sorcerer", 0, "Warlock", 0, "Wizard", 2)]
[H: Formula = concat("json.get(", Data, ", 'Wizard')")]
[H: broadcast(json.type(Data) + ". " + Formula)]
outputs: OBJECT. json.get({"Barbarian":0,"Bard":0,"Cleric":0,"Druid":1,"Fighter":0,"Monk":0,"Paladin":0,"Ranger":0,"Rogue":0,"Sorcerer":0,"Warlock":0,"Wizard":2}, 'Wizard')
[H: Value = eval(string(Formula))]
generates an error
What am I doing wrong?
Using eval to retrieve info from an object
Moderators: dorpond, trevor, Azhrei, giliath, jay, Mr.Ice
Re: Using eval to retrieve info from an object
It's hard to tell what you're trying to accomplish but it seems like you're making it more complicated than it needs to be. Perhaps you want to use Wiki: evalMacro() instead and create a string that looks like macro code.
Downloads:
- Notepad++ MapTool addon
- RPEdit details (v1.3)
- Coding Tips: Modularity and Design
- Videos: Macro Writing Tools
Re: Using eval to retrieve info from an object
I know that. However in this case I need to evaluate it dynamically. I was just detailing the crux of the issue, the rest is far too lengthy.
Re: Using eval to retrieve info from an object
what am said, just add brackets and use evalmacro the rest remains the same
GETTING STARTED WITH MAPTOOLS - TUTORIALS, DOCS, VIDEOS, TOOLS, ETC
DISCORD (the new MT forum!)
My stuff
Excel Tools: Table and Light editors
MT Tools: Bag of Tricks: Tools for Maptool, Dungeon Builder I, Dungeon Builder II,onMouseOverEvent.
Frameworks: Dark Heresy, Rogue Trader, Deathwatch, Black Crusade, Only War, SET Card Game, RoboRally
Wiki: Debugging Tutorial, Speed Up Your Macros, Working With Two CODE Levels, Shortcut Keys, Avoiding Stack Overflow, READ THIS
DISCORD (the new MT forum!)
My stuff
Excel Tools: Table and Light editors
MT Tools: Bag of Tricks: Tools for Maptool, Dungeon Builder I, Dungeon Builder II,onMouseOverEvent.
Frameworks: Dark Heresy, Rogue Trader, Deathwatch, Black Crusade, Only War, SET Card Game, RoboRally
Wiki: Debugging Tutorial, Speed Up Your Macros, Working With Two CODE Levels, Shortcut Keys, Avoiding Stack Overflow, READ THIS