How do I break one property into two?
Moderators: dorpond, trevor, Azhrei, giliath, jay, Mr.Ice
How do I break one property into two?
I'm working on some Heavy Gear macros and I'd like to take a property that's in this form: "xD+n" and turn it into two new properties "x" and "n"
How do I do this? (the D will always be in the property)
How do I do this? (the D will always be in the property)
Re: How do I break one property into two?
So, what are the possible combinations:
xD
xD+n
xD-n
??
xD
xD+n
xD-n
??
Downloads:
- Notepad++ MapTool addon
- RPEdit details (v1.3)
- Coding Tips: Modularity and Design
- Videos: Macro Writing Tools
Re: How do I break one property into two?
your a bit vague, but if i take it literally and assuming that x and n are always single characters then you can use Wiki: substring():
if they're not, then you'll probly need regex to retrieve them. bit trickier and you'll need: Wiki: getGroup()
Code: Select all
[prop="xD+n"]
[x = substring(prop, 0,1)]
[n = substring(prop, 3)]
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: How do I break one property into two?
wolph42 wrote:your a bit vague, but if i take it literally and assuming that x and n are always single characters then you can use Wiki: substring():if they're not, then you'll probly need regex to retrieve them. bit trickier and you'll need: Wiki: getGroup()Code: Select all
[prop="xD+n"] [x = substring(prop, 0,1)] [n = substring(prop, 3)]
I think this is exactly what I need. Thanks.
Re: How do I break one property into two?
That will work is x and n is a single digit.Zaran wrote:wolph42 wrote:your a bit vague, but if i take it literally and assuming that x and n are always single characters then you can use Wiki: substring():if they're not, then you'll probly need regex to retrieve them. bit trickier and you'll need: Wiki: getGroup()Code: Select all
[prop="xD+n"] [x = substring(prop, 0,1)] [n = substring(prop, 3)]
I think this is exactly what I need. Thanks.
Since you didn't answer my questions I'm going to assume the format will always be xD+n. I suggest doing this:
Code: Select all
[H: prop="xD+n"]
[H: x = listGet(prop,0,"D")] <!-- everything before "D" -->
[H: n = listGet(prop,1,"+")] <!-- everything after "+" -->
Downloads:
- Notepad++ MapTool addon
- RPEdit details (v1.3)
- Coding Tips: Modularity and Design
- Videos: Macro Writing Tools
- Bone White
- Great Wyrm
- Posts: 1124
- Joined: Tue Aug 23, 2011 11:41 am
- Location: Cornwall, UK
Re: How do I break one property into two?
I'd personally use listGet's list separator in this situation... Just for the sake of multiple opinions.
[code][h: diceString = "1d5"]
[r: diceQuantity = listGet(diceList,0,"d")]
[r: diceSides = listGet(diceList,1,"d")][/code]
Results in:
1
5
edited to remove the wasteful stringToList and just use listGet
[code][h: diceString = "1d5"]
[r: diceQuantity = listGet(diceList,0,"d")]
[r: diceSides = listGet(diceList,1,"d")][/code]
Results in:
1
5
edited to remove the wasteful stringToList and just use listGet
Last edited by Bone White on Mon May 18, 2015 6:34 pm, edited 1 time in total.
Re: How do I break one property into two?
These are the possible combinations yes.aliasmask wrote:So, what are the possible combinations:
xD
xD+n
xD-n
??
Re: How do I break one property into two?
in that case youll need to check the string Wiki: length ()cause the second substring command will render an error in case of xDZaran wrote:These are the possible combinations yes.aliasmask wrote:So, what are the possible combinations:
xD
xD+n
xD-n
??
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: How do I break one property into two?
I can work around that by just making it xD+0 .wolph42 wrote:in that case youll need to check the string Wiki: length ()cause the second substring command will render an error in case of xDZaran wrote:These are the possible combinations yes.aliasmask wrote:So, what are the possible combinations:
xD
xD+n
xD-n
??
The whole problem is routed around mechanics of the Silhouette system. 2d+1 doesn't do 3-13 as a result in that game. It takes the highest of the dice rolled and adds 1 for every extra 6 rolled. So i'll need to be able to break down how one records each skill roll into the two parts so that it can roll the dice and then add the mod.
Re: How do I break one property into two?
I think this should cover most instances including bad input.
Code: Select all
[H: abort(input("strInput|0|Enter dice string. Format xD[+/-n]"))]
<!--
(?i) = case insensitive;
([0-9]+) = 1 or more digits (group 1);
D(.*) = D followed by anything, anything is (group2)
-->
[H: regex = "(?i)([0-9]+)D(.*)"]
[H: findId = strfind(strInput,regex)]
[H: foundMatch = getFindCount(findId)]
[H, if(foundMatch), code: {
<!-- x is the first match of group 1 -->
[H: x = getGroup(findId,1,1)]
<!-- n is the first match of group 2 -->
[H: n = getGroup(findId,1,2)]
<!-- clean up n. Save only digits and +,- symbols. -->
[H, if(length(n)): n = replace(n,"[^0-9+-]","")]
<!-- set n to 0 if not a number (like a blank) -->
[H, if(! isNumber(n)): n = 0]
};{
[H: x = ""]
[H: n = ""]
}]
[R, if(foundMatch): strformat("Input: %{strInput}; x = %{x}; n = %{n}");
strformat("No matches found: '%{strInput}'")]
Downloads:
- Notepad++ MapTool addon
- RPEdit details (v1.3)
- Coding Tips: Modularity and Design
- Videos: Macro Writing Tools