input() and other new b42 macro functions

Doc requests, organization, and submissions

Moderators: dorpond, trevor, Azhrei

User avatar
jfrazierjr
Deity
Posts: 5176
Joined: Tue Sep 11, 2007 7:31 pm

Post by jfrazierjr »

Sooo... Here is my question:

With the new features, is there now any way to put an input (among other code) into an if statement.

Basically, what i would like to to try to do is (in pseudo code):

num = getListSize(somelist)
If num > 0
targets = getlistitems
Input(target|targets|Targets?|LIST" ,
"targetAlt||Alternate Target")
putlistitem(somelist, target)

else
Input(target||Targets")
putlistitem(somelist, target)

end if

In a nutshell, if their are no values in the list, then show a text field and put the result into the list. If there are values in the list show the list AND text box. Check if the text box is empty and the list selection is empty and bail if so. Otherwise, either add to the list (if textbox entered) or just use the selected list item.

The idea here is that as you attack creatures... you build a list of possible targets(just for use in macro text as a string at this moment) Yea... I know this does not really help those that can attack multiple opponents, but it's a start. If not possible, just let me know and I will wait until we can get true targeting....
I save all my Campaign Files to DropBox. Not only can I access a campaign file from pretty much any OS that will run Maptool(Win,OSX, linux), but each file is versioned, so if something goes crazy wild, I can always roll back to a previous version of the same file.

Get your Dropbox 2GB via my referral link, and as a bonus, I get an extra 250 MB of space. Even if you don't don't use my link, I still enthusiastically recommend Dropbox..

User avatar
PyroMancer2k
Dragon
Posts: 925
Joined: Thu Sep 11, 2008 2:04 pm

Post by PyroMancer2k »

jfrazierjr wrote:Sooo... Here is my question:

With the new features, is there now any way to put an input (among other code) into an if statement.

In a nutshell, if their are no values in the list, then show a text field and put the result into the list. If there are values in the list show the list AND text box. Check if the text box is empty and the list selection is empty and bail if so. Otherwise, either add to the list (if textbox entered) or just use the selected list item.

The idea here is that as you attack creatures... you build a list of possible targets(just for use in macro text as a string at this moment) Yea... I know this does not really help those that can attack multiple opponents, but it's a start. If not possible, just let me know and I will wait until we can get true targeting....
It sounds like you want to do two different input() prompts if I'm correct?

Well even in b45 it was possible to have different input() statements based on what the user is going to enter. Check out my new token v1.7 and the attack macro it has. It creates a different input based on weather or not the user is going to have multiple attacks as well as if the attack with rotate between main and off hands. Here's a link with the code at the bottom of the post.

http://forums.rptools.net/viewtopic.php?p=70340#70340

Also you can check out the card draw token which has a macro that creates a list of check boxes for each card in the user's hand to allow for multiple discard which sounds similar to what you want for people targeting multiple enemies. I cut out the segment that creates the input from a list.

Code: Select all

<!-- Creates input display listing all cards in hand -->
[H:DiscardPrompt = 'input(']
[H:HandSize = listCount(eval("Player" + (Player+1) + "Hand"))]
[H,C(HandSize):DiscardPrompt = DiscardPrompt + '"DiscardFromHand" + ' + roll.count + ' + " | 0 | Discard " + listGet(eval("Player" + (Player+1) + "Hand"),' + roll.count + ') + " | CHECK" ' + if(HandSize > (roll.count+1), ',' , ')')]
<!-- Displays input for which cards to discard -->
[H:fail = eval(DiscardPrompt)]
[H:abort(fail)]

User avatar
jfrazierjr
Deity
Posts: 5176
Joined: Tue Sep 11, 2007 7:31 pm

Post by jfrazierjr »

PyroMancer2k wrote: It sounds like you want to do two different input() prompts if I'm correct?
Nope.. was hoping to dynamically build the input based on token properties and go from there.
I save all my Campaign Files to DropBox. Not only can I access a campaign file from pretty much any OS that will run Maptool(Win,OSX, linux), but each file is versioned, so if something goes crazy wild, I can always roll back to a previous version of the same file.

Get your Dropbox 2GB via my referral link, and as a bonus, I get an extra 250 MB of space. Even if you don't don't use my link, I still enthusiastically recommend Dropbox..

Lindharin
Dragon
Posts: 668
Joined: Sat Apr 21, 2007 4:51 pm

Post by Lindharin »

You could try something like:

Code: Select all

[IF(num>0), CODE: 
{  
   [input(yada yada yada)]
   [post-processing for first case]
} ; 
{
   [input(other yada yada yada)]
   [post-processing for second case]
}]
[post-post-processing for both cases]
The CODE construct is awesome for things like this.

However, I have run into one situation where I was using a SWITCH structure with CODE so that each case in the SWITCH had a block of code. It wasn't long before the macro would no longer run; it would just lock up in the chat window's command box. It wasn't an error in the code, but seemed to be length-dependent. I could remove any of several non-critical lines and get it to work, but put any of them back and it would stop. So it seems like there is a size limit to how much you can have in a CODE block.

In my case, the solution to that was to just have each SWITCH case call an external macro stored on a Library token, which actually worked out much better anyway (since I can then re-use those functions in other macros).

I've got to say that I am really loving the macro enhancements in b46/47. :-)

User avatar
palmer
Great Wyrm
Posts: 1367
Joined: Sat Sep 06, 2008 7:54 pm

Post by palmer »

It is possible. Just dynamically build what goes INTO the Input, rather than encoding separate Inputs entirely.

Here's part of one macro I used, it's for Sacrifice to Caiphon, a Dragon Warlock feat. Basically, it lets you regain an Encounter that just missed by spending HP.

Code: Select all

[h: IsUsed = if(PowerUsed>=MaxUses,1,0)]
[h: IsEnc = if(UseLimit=="Encounter",1,0)]
[h: Valid = min(IsUsed,IsEnc)]

[h:Line1 = if(Valid==1,"bleh |. | Caiphon will restore the use of "+PowerName+" | LABEL","bleh |. | Caiphon will not aid you at this time | LABEL")]
[h:Line2 = if(Valid==1,"bleh |. | At a cost of "+PowerLevel+" Hit Points, leaving you with "+(HP-PowerLevel)+" | LABEL","")]
[h:Line3 = if(Valid==1,"bleh |. | Are you willing to give Caiphon its due? | LABEL","")]

[h: fail = input(Line1,Line2,Line3)]
[h: abort(fail)]
[h: abort(Valid)]
Basically, you can use your IF statements and everything to build the lines of the Input using variables, and then just plug them in as needed.

BONUS: Any variable set to a null string ("") is ignored by Input, even if it's in the middle. Thus you can dynamically make your Inputs as long or short as you want. Just be sure to set all the line variables to "" first :)

User avatar
PyroMancer2k
Dragon
Posts: 925
Joined: Thu Sep 11, 2008 2:04 pm

Post by PyroMancer2k »

jfrazierjr wrote:
PyroMancer2k wrote: It sounds like you want to do two different input() prompts if I'm correct?
Nope.. was hoping to dynamically build the input based on token properties and go from there.
Well that's pretty much what the 2nd example I gave does. the Discard multiple cards macro I posted because creates an input with as many check boxes as you have card's in hand which uses the token's property to get. And it a lot more dynamic then most of the if() builds which only hand either A or B. If you have 3 cards in hand you will see 3 check boxes where if you have 5 cards in hand you will see 5 check boxes thus allowing you to select as many or as few as you want unlike LIST which only lets you select one at a time.

User avatar
jfrazierjr
Deity
Posts: 5176
Joined: Tue Sep 11, 2007 7:31 pm

Post by jfrazierjr »

PyroMancer2k wrote:
jfrazierjr wrote:
PyroMancer2k wrote: It sounds like you want to do two different input() prompts if I'm correct?
Nope.. was hoping to dynamically build the input based on token properties and go from there.
Well that's pretty much what the 2nd example I gave does. the Discard multiple cards macro I posted because creates an input with as many check boxes as you have card's in hand which uses the token's property to get. And it a lot more dynamic then most of the if() builds which only hand either A or B. If you have 3 cards in hand you will see 3 check boxes where if you have 5 cards in hand you will see 5 check boxes thus allowing you to select as many or as few as you want unlike LIST which only lets you select one at a time.
Hmmm.... if I eval to create variable names and loop over them to create checkboxes...... I could in theory make an area attack and create the results "per hit" in the output. I might want to create a generic macro that allows "adding" to the list, and then in each power, perhaps check to see if multiple targets are allowed. If so build the checkboxes from the list otherwise, show a dropdown to allow single selection. That gives me quite a bit to think on. I guess I would have to have an End Encouter maco to clear the list and a Start Encounter one to populate it with targets.... Unless someone beats me to it.... I will post up an example later tonight....
I save all my Campaign Files to DropBox. Not only can I access a campaign file from pretty much any OS that will run Maptool(Win,OSX, linux), but each file is versioned, so if something goes crazy wild, I can always roll back to a previous version of the same file.

Get your Dropbox 2GB via my referral link, and as a bonus, I get an extra 250 MB of space. Even if you don't don't use my link, I still enthusiastically recommend Dropbox..

User avatar
PyroMancer2k
Dragon
Posts: 925
Joined: Thu Sep 11, 2008 2:04 pm

Post by PyroMancer2k »

jfrazierjr wrote:
Hmmm.... if I eval to create variable names and loop over them to create checkboxes...... I could in theory make an area attack and create the results "per hit" in the output. I might want to create a generic macro that allows "adding" to the list, and then in each power, perhaps check to see if multiple targets are allowed. If so build the checkboxes from the list otherwise, show a dropdown to allow single selection. That gives me quite a bit to think on. I guess I would have to have an End Encouter maco to clear the list and a Start Encounter one to populate it with targets.... Unless someone beats me to it.... I will post up an example later tonight....
Yea it sounds like you need a lot more then simple input handling. If they would need to prompt if they are adding targets or attacking if you want it to me in one macro. Gonna end with with a ton of condition checks for a big hairy thing like that.

My Weapon Attack Template macro for my token kinda does that though with a not quite that much of a dynamic input() like you want with list of targets. It checks if the attack is against a single target or multiple, in case of multiple you simple enter a number of how many. It also checks if the attack switches between main hand and off hand. All with variable set at the start of the macro and comments for easy editing. But basically it has to handle the attack rolls and damage rolls along with the chat display differently depending on which type of attack they are using. Oh and it has crit checking.

Craig
Great Wyrm
Posts: 2107
Joined: Sun Jun 22, 2008 7:53 pm
Location: Melbourne, Australia

Post by Craig »

Lindharin wrote:Okay, I finally started to play with the new macro functions from b41 on, and I have to say that I am LOVING it! :D :D :D

I have run into one snag with string properties and the new ability to call another macro from a library token, though. I've been finding string properties incredibly useful for passing multiple key/value pairs back and forth between the main macro and the library macro.

However, you cannot have either an equal sign (=) or semi-colon ( ; ) in the values in a string property. The lack of equal signs is a big problem, because it means you can't make use of tooltips in spans; we need to be able to have something like:

<span>8</span>

when we're building custom outputs for rolls. But that breaks if we try to add it to a string property and send it to/from a library macro, because the string property parser chokes on the equal signs in the span tag.

I went into eclipse and looked at the source, and I added a call to URLEncoder.encode() in the setStrProp function when it stores the value, and calls to URLDecoder.decode() in getStrProp, varsFromStrProp, and indexValueStrProp so that the stored value gets decoded before it is sent back to a macro.

This seems to work well, with one exception. If the string property gets stored in a token property and you look at the value in the token editor, you see the encoded string (this means all punctuation and special characters are converted into codes like %20, etc.)

How important is it for people to be able to see human-readable content in string properties stored in tokens?
Since the patch I sent Trevor has quite a few string manipulation functions in it I decided to roll 2 new functions in that will help you out.

encode() takes a string and encodes it in a way that will escape = and ; characters.

decode() will take an encoded string and well decode if for you.

So you can do something like

Code: Select all

[h: props1 = "a=1;b=2"]
[h: props2 = "c=3;d=4"]
[h: props= ";"]
[h: props = setStrProp(props, "First", encode(props1))]
[h: props = setStrProp(props, "Second", encode(props2))]
You would then retrieve them with something like

Code: Select all

[decode(getStrProp(props, "First"))]
but hopefully you would use them for something more meaningful than the above example ;)

Lindharin
Dragon
Posts: 668
Joined: Sat Apr 21, 2007 4:51 pm

Post by Lindharin »

Craig wrote: Since the patch I sent Trevor has quite a few string manipulation functions in it I decided to roll 2 new functions in that will help you out.
Thanks! :D

User avatar
RedDog
Dragon
Posts: 393
Joined: Sat Jan 05, 2008 10:02 pm
Location: Clearwater, FL

Post by RedDog »

I has some input() and list questions and was not sure if I should ask here or do a new post. Hopefully, this is good.

First of all, I love the new functions. It takes a bit of time, but we are working to set up a lot of tools for our games and it really makes MT more accessible and easy to use for non-scripters and new users.

1) For a LIST option of the input() command, is there a way to set the left side to empty text? I've noticed if it is left blank, it defaults to the variable name. I've taken to setting up descriptive pop-ups on tokens that players can use. I have to use a single character such as a colon, so the margin has :: down the the left side. It works, but it would be nice if it was cleaner.

I was wondering the same thing for the CHECKbox as well.

2) For the RADIO, ORIENT=H of the input(), could we get a little more padding or an option to control the padding between choices? They are sometimes difficult to read at a glance.

3) When referencing an image from a table, the very first time the macro with the input() command is run, the image comes up as a question mark (unfound asset). I am guessing that this is because the image has not been referenced in the session yet and not enough time is given by the time the message box is displayed. Any idea if this might be corrected in an upcoming build?

4) I have also have some difficulty working with lists (listAppend, listdelete, listInsert, listGet). I started out making a simple set of macros to add a list of names to a Token Property using the listAppend, but could not get it to work. I then manaully created the list (Bob, Joe, Phil and "Bob, Joe, Phil") on a Token Property and tried to remove them, but could not get that to work either. In each case, I didn't receive an errors, but also did not get the expected result. I looked for some examples in the forum, but had difficulty finding some simple examples (most were pretty complex). Can someone give me a basic example of using a macro to add a name to a list on a new token and another for deleting a name? I think I just need a nudge in the right direction. My scripting scrolls are pretty good, so I am surprised that I am having difficulty with this one.


Thanks for the great tools...and for any help

User avatar
PyroMancer2k
Dragon
Posts: 925
Joined: Thu Sep 11, 2008 2:04 pm

Post by PyroMancer2k »

RedDog wrote: 4) I have also have some difficulty working with lists (listAppend, listdelete, listInsert, listGet). I started out making a simple set of macros to add a list of names to a Token Property using the listAppend, but could not get it to work. I then manaully created the list (Bob, Joe, Phil and "Bob, Joe, Phil") on a Token Property and tried to remove them, but could not get that to work either. In each case, I didn't receive an errors, but also did not get the expected result. I looked for some examples in the forum, but had difficulty finding some simple examples (most were pretty complex). Can someone give me a basic example of using a macro to add a name to a list on a new token and another for deleting a name? I think I just need a nudge in the right direction. My scripting scrolls are pretty good, so I am surprised that I am having difficulty with this one.


Thanks for the great tools...and for any help
It's kinda hard to know what you could be doing wrong without seeing some of your coding attempts. But my guess is are you setting the result = to something? What I mean is...
This code doesn't actually change the list.

Code: Select all

[H:listAppend(List, "A")]
This code does change the list.

Code: Select all

[H:List = listAppend(List, "A")]
Here is a simple test macro I wrote when playing with syntax for card draw token. It simply adds a one item to the end of the macro.

Code: Select all

[DECKLIST = "1,2,3,4"]<BR>
[DECKLIST = listInsert(DECKLIST, listCount(DECKLIST), "5")]<BR>
{DECKLIST}<BR>

User avatar
RedDog
Dragon
Posts: 393
Joined: Sat Jan 05, 2008 10:02 pm
Location: Clearwater, FL

Post by RedDog »

PyroMancer2k wrote:[H:List = listAppend(List, "A")]
That was it. I was missing the List =
Thanks.

Craig
Great Wyrm
Posts: 2107
Joined: Sun Jun 22, 2008 7:53 pm
Location: Melbourne, Australia

Post by Craig »

Lindharin wrote:
Craig wrote: Since the patch I sent Trevor has quite a few string manipulation functions in it I decided to roll 2 new functions in that will help you out.
Thanks! :D
There is one problem although I don't know if it will really by a problem. I have been thinking about it and you can only use encode()/decode() to embed a property list inside of another one level deep.
ie you can have something that is kinda equivalent to

Code: Select all

    "Weapons=(
         Name=Long Sword;Damage=1d8
      ) ; 
      Potions=(
         Name=Invisibility;Count=2
      )"
Where the properties within the parenthesis would be encoded.

What you can't do is something equivalent to

Code: Select all

     "Weapons=(
          Melee=(
              Name=Long Sword;Damage=1d8
           ) ; 
           Ranged=(
              Name=Long Bow;Damage=1d10
           )
       ) ;
       Consumables=(
            Potions=(
                Name=Invisibility;Count=2
            )
       ) ;"
I have the rough idea of a solution in my mind for how something like the above can be achieved (and its more robust than just putting parenthesis around the lists ;) ), and a tried a very quick and nasty hack to see if I could get it working and it seems to hang together ok.

Question is, would this be of benefit to anyone? Is there anyone out there that has been itching for something like this?

jimb
Kobold
Posts: 22
Joined: Mon Sep 29, 2008 5:46 pm

Post by jimb »

Itching for something like this... no. Find useful... very.

I have been using something like this for awhile. I just have to simulate it with properties within a list within a list and using different separator characters for the two lists. Your change would make that much more elegant and much more readable in the Properties. Also much less prone to error since you don't have to remember what position in the list means what.

Post Reply

Return to “Documentation Requests/Discussion”