Creating a stored output property from a foreach.
Moderators: dorpond, trevor, Azhrei, giliath, jay, Mr.Ice
- Xaelvaen
- Dragon
- Posts: 498
- Joined: Wed Aug 31, 2011 9:49 pm
- Location: Somewhere between Heaven and Hell
Creating a stored output property from a foreach.
So, as the title indicates, I'm trying to figure out how to take some html created by a [Foreach] and store it in a property to call upon later with broadcast(). I have no idea if this is possible, or how to approach it. I tried to simply wrap the foreach in ' ' so it would 'stack' with the quotations of the html around it, but that creates a table basically saying 'foreach' lol. I've never really worked with strformat or anything like that, so not sure if it could help in this case.
Any points in the right direction, or even if it is possible, would be appreciated.
Any points in the right direction, or even if it is possible, would be appreciated.
"An arrogant person considers himself perfect. This is the chief harm of arrogance. It interferes with a person's main task in life - becoming a better person." - Leo Tolstoy
Re: Creating a stored output property from a foreach.
I'm not sure if the "broadcast()" function is the right way to do this. but can't know that for sure without knowing more about what you try to do.
anyway. for the stringformat i use something like this for my weapon attack (you need to write your own)
and i call it like:
Every "%s" is a variable and you can add them when calling the strformat
In theory you can put both in and foreach loop
anyway. for the stringformat i use something like this for my weapon attack (you need to write your own)
Code: Select all
[H: RNA_OutputFormat = '
<table border="1" cellpadding="0">
<td><table border="0" cellpadding="0" cellspacing="0">
<tr Align="Center"><b>Source:</b></tr>
<tr Align="Center"><img src="%{OP_SourceImg}"></img></tr>
<tr Align="Center">%{OP_SourceName}</tr>
</table></td><td><table border="0" cellpadding="1">
<tr bgcolor="green">
<td width="4"></td><td Align="Center" style="color:white"><b>%s</b></td><td width="4"></td>
</tr><tr>
<td width="4"></td><td Align="Center">%s</td><td width="4"></td>
</tr><tr>
<td width="4"></td><td Align="Center">%s</td><td width="4"></td>
</tr><tr>
<td width="4"></td><td Align="Center">%s</td><td width="4"></td>
</tr><tr>
<td width="4"></td><td Align="Center">%s</td><td width="4"></td>
</tr>
</table></td><td><table border="0" cellpadding="0" cellspacing="0">
<tr Align="Center"><b>target:</b></tr>
<tr Align="Center">%{OP_targetImg}</tr>
<tr Align="Center">%{OP_targetName}</tr>
</table></td>
</table>
']
Code: Select all
[R: strformat(RNA_OutputFormat,
OP_Type,
OP_Weapon,
OP_Attack,
OP_Damage,
OP_Ammo
)]
In theory you can put both in and foreach loop
My own 5th d&d character sheet framework (preview)
Re: Creating a stored output property from a foreach.
this is really silly but it shows what you're asking for:
I use this method a lot to build dynamic forms, tables, etc. obviously you can also use strformat in the mix, but I thought to keep it simple.
Code: Select all
[h:txt = "<html>"]
[h:nums = "0,1,2,3,4"]
[h,foreach(num,nums): txt = txt + ", " + num]
[h:txt = txt + "</html>"]
[h:broadcast(txt)]
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
Re: Creating a stored output property from a foreach.
that is actually a very good example. think i was overthinking this
My own 5th d&d character sheet framework (preview)
- Xaelvaen
- Dragon
- Posts: 498
- Joined: Wed Aug 31, 2011 9:49 pm
- Location: Somewhere between Heaven and Hell
Re: Creating a stored output property from a foreach.
Haha - Wolph to the rescue (of my sanity - still awful at strformat after however many years I've been at this). Thank you both for the input; so happy to not have to suddenly dive into strformat.
"An arrogant person considers himself perfect. This is the chief harm of arrogance. It interferes with a person's main task in life - becoming a better person." - Leo Tolstoy
Re: Creating a stored output property from a foreach.
Depends how the html is created. If the author just dumps it to the chat then there is one trick you can use. Any output from a function can be put in to a variable if called as a function or UDF. For example:
Running this macro just goes to the chat. But if you create a UDF...
Then you control when and where you want the output to go.
Code: Select all
<!-- my html macro -->
<b>stuff goes here</b>
Code: Select all
<!-- onCampaignLoad -->
[H: defineFunction("am.myHTML","myHTML@"+getMacroLocation())]
Code: Select all
<!-- save output and broadcast -->
[H: htmlOutput = am.myHTML()]
[H: broadcast(htmlOutput)]
- Attachments
-
- lib_test.rptok
- (30.01 KiB) Downloaded 33 times
Downloads:
- Notepad++ MapTool addon
- RPEdit details (v1.3)
- Coding Tips: Modularity and Design
- Videos: Macro Writing Tools
Re: Creating a stored output property from a foreach.
y're welcome. Note that stringformat can take many forms which is why it can be so painstakingly hard to manage. One form however which is very easy to use and very usefull is the one where you use variables e.g.
Code: Select all
[h:me = "Tim the Enchanter"]
[h:target = "Harmless bunny"]
[r:strformat("%{me} is really scared of %{target}")]
Last edited by aliasmask on Wed Aug 30, 2017 6:25 pm, edited 2 times in total.
Reason: added {}'s
Reason: added {}'s
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
- Xaelvaen
- Dragon
- Posts: 498
- Joined: Wed Aug 31, 2011 9:49 pm
- Location: Somewhere between Heaven and Hell
Re: Creating a stored output property from a foreach.
Code: Select all
[h: outputList=macro.args]
[h: open="<html><body bgcolor=#cccccc><table border=1 cellpadding=1 cellspacing=0>"]
[h: txt="<tr><td border=1 cellpadding=1 cellspacing=0>"]
[h,foreach(output,outputList) : txt=txt +output +"</td></tr>"]
[h: endTxt=add(open,txt,"</table></html>")]
[h: broadcast(endTxt)]
As for strformat, in your example Wolph, I assume 'me' and 'target' could be other called variables, like getName() etc? It doesn't just have to be text, right? If so, that seems a lot easier than all the "Blah Blah " +variable +" Blah."
@Aliasmask
I'm still working on figuring out UDFs. At the moment, I don't use any, but I've been very interested in picking it up. My Anarchy framework is almost finished, so that'll be my next 'target' to learn I reckon.
"An arrogant person considers himself perfect. This is the chief harm of arrogance. It interferes with a person's main task in life - becoming a better person." - Leo Tolstoy
Re: Creating a stored output property from a foreach.
erm... you're quite good at mixing stuff up...As for strformat, in your example Wolph, I assume 'me' and 'target' could be other called variables, like getName() etc? It doesn't just have to be text, right? If so, that seems a lot easier than all the "Blah Blah " +variable +" Blah."
YESI assume 'me' and 'target' could be other called variables
NO. getName() is a function, NOT a variable. You could use [anotherName = getName()] and then use %anotherName inside the strformat.like getName() etc?
YES, that was the point of my example. It makes it a LOT easier to create output strings and makes much more eligible code.If so, that seems a lot easier than all the "Blah Blah " +variable +" Blah."
---------------
IF you want to use functions like getName() directly you get into the second stage of using strformat and that is the %s:
Code: Select all
<!-- assuming "Harmless bunny" is selected! -->
[h:switchToken("Tim the Enchanter")]
[r:strformat("%s is really scared of %s", getName(), getSelectedNames())]
another example
Code: Select all
<!-- assuming "Harmless bunny" is selected! -->
[h:switchToken("Tim the Enchanter")]
[h:text = "is really scared of"]
[r:strformat("%s %{text} %s", getName(), getSelectedNames())]
OR
[r:strformat("%s %s %s", getName(), text, getSelectedNames())]
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
Re: Creating a stored output property from a foreach.
There's nothing really to them. I even made a starter token so any macro you create is automatically a UDF as well. Just read the comments on the lib token as well as in the macros.Xaelvaen wrote:@Aliasmask
I'm still working on figuring out UDFs. At the moment, I don't use any, but I've been very interested in picking it up. My Anarchy framework is almost finished, so that'll be my next 'target' to learn I reckon.
- Attachments
-
- starter lib token.rptok
- (168.82 KiB) Downloaded 40 times
Downloads:
- Notepad++ MapTool addon
- RPEdit details (v1.3)
- Coding Tips: Modularity and Design
- Videos: Macro Writing Tools
- Xaelvaen
- Dragon
- Posts: 498
- Joined: Wed Aug 31, 2011 9:49 pm
- Location: Somewhere between Heaven and Hell
Re: Creating a stored output property from a foreach.
wolph42 wrote: erm... you're quite good at mixing stuff up...
Story of my life mate lol. By 'called variable', tokenName=getName() was exactly what I was referring to (function to call, store as variable). I'm just awful-bad at explaining things. Also awful-bad at remembering specific terminology. Thank you for the clarification; already started using strformat replacements. Also, thank you for the second use of strformat. I was thinking I'd have to go away from it for output where I needed to use a function in them, because "Blah Blah " +getName() +"Blah" is a bit faster than making a separate (new) variable just for the sake of using strformat. So your new examples helped as well =)
@Aliasmask
Thank you, I've downloaded it, and now I'll give it a poke and read up on 'em.
"An arrogant person considers himself perfect. This is the chief harm of arrogance. It interferes with a person's main task in life - becoming a better person." - Leo Tolstoy
Re: Creating a stored output property from a foreach.
it appeared I made a typo in my earlier messages, but someone (probly AM) corrected them. Its strformat("%{variable}") not strformat("%variable") in strformat.
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
Re: Creating a stored output property from a foreach.
I've actually had issues with using %s in strformat. I recall there being two things that can muck things up so I just stick with %{varName} as much as I can. I know I've mentioned them in some really old posts but I can't think of what they are at the moment. I think one has to do with ' being in the variable and the other is when % in the string where you have to use %% to get a literal % when using %s in string. When you don't use %s then you don't need to use %%. All these really boil down to is needing an extra step to format the text which can be a pain depending on how dynamic the text is.
Downloads:
- Notepad++ MapTool addon
- RPEdit details (v1.3)
- Coding Tips: Modularity and Design
- Videos: Macro Writing Tools
- Xaelvaen
- Dragon
- Posts: 498
- Joined: Wed Aug 31, 2011 9:49 pm
- Location: Somewhere between Heaven and Hell
Re: Creating a stored output property from a foreach.
Then perhaps I should just stick to using strformat when I already have variables place in the code, and 'simple' formatting when I need to call something new. Regardless, thank you both as always =)
"An arrogant person considers himself perfect. This is the chief harm of arrogance. It interferes with a person's main task in life - becoming a better person." - Leo Tolstoy