input() and other new b42 macro functions

Doc requests, organization, and submissions

Moderators: dorpond, trevor, Azhrei

User avatar
Daniel
Giant
Posts: 132
Joined: Thu Nov 20, 2008 3:49 am
Location: Germany (GMT +1)

Post by Daniel »

Hi all.

Using a minimally adapted version of k.fan's original character sheet macro, I get an error message telling me that

Code: Select all

Could not execute the command: Invalid input type 'TAB' in the parameter string 'TabBasics | Basics | Stufe, LE, etc. | TAB'
It plain doesn't let me use the TAB option...?

My code is (abbreviated some input lines identical to the one saying "Dukaten")

Code: Select all

[H: status = input(
    "TabBasics | Basics | Stufe, LE, etc. | TAB",
 "bla | | Grundlegendes | LABEL",
      "bla |"+ token.name +" | Name | LABEL",
      "Dukaten_ | " + Dukaten + " | Dukaten | TEXT | width=3",
    "TabSkills | Handwerk | Handwerkliche Talente | TAB",
      "bla | Blubbediblubb | Note | LABEL"
)]
[H: abort(status)]

User avatar
lmarkus001
Great Wyrm
Posts: 1867
Joined: Sat Mar 29, 2008 12:30 am
Location: Layfayette Hill, PA

Post by lmarkus001 »

It appears the changes/additions referred to in the doc posts of this thread are not in the current build. I think there was some build confusion as a number of rather old (stuff that was done shortly after b45 went live) fixes did not make it in to the b46/47 build.

So I would recommend referencing an older version of the docs (which you would have had to print out...).

User avatar
Daniel
Giant
Posts: 132
Joined: Thu Nov 20, 2008 3:49 am
Location: Germany (GMT +1)

Post by Daniel »

Ah, I see... so it's mainly a matter of waiting for b48(+) when all the documented features are actually in. :lol:

I can live with that (barely). No seriously, macros have gotten lots of loving in recent builds, and the thing I was trying to write would really just be icing on the cake.

Thanks to all programmers making this happen.

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

Post by jfrazierjr »

Ugh... I am having trouble getting my syntax right inside my loop. What i want to is to build a CHECK string from a list.

validTargets is a token Property. In another macro, I add a list of "creatures" who fill in validTargets.

Code: Select all

[h: numTargets = listCount(validTargets)]

<MACRO> 
[h: attackTargets = '']
[h: targetString= '']

[H,C(numTargets),CODE: { 
	[h: eval( targetNumber +roll.count) = ''  ]
}]


[H,C(numTargets),CODE: { 
	[h: targetString = targetString + " 0 |" + listGet(validTargets, roll.count) + "| CHECK"   ]
}]

[h: succces = input(targetString )
[h:abort(success)]
Once I can get this working, I should be able to check for checked targets, append them to a temp list in the macro, and then use this temp list to power the actual attack macro with crit detection.
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 »

jfrazierjr wrote:Ugh... I am having trouble getting my syntax right inside my loop. What i want to is to build a CHECK string from a list.
I've got to run (picking up in-laws for dinner tonight), so I can't put this into MT and test it, but on a quick look the following loop has a problem:

[H,C(numTargets),CODE: {
[h: targetString = targetString + " 0 |" + listGet(validTargets, roll.count) + "| CHECK" ]
}]

In the internal statement, you need a variable in the first spot, before the 0. Something like:

[h: targetString = targetString + "target" + roll.count+ " | 0 |" + listGet(validTargets, roll.count) + "| CHECK" ]


Then you will have a bunch of variables, target0 through target12 (if you had 13 possible targets), which are set to either 0 if unchecked or 1 if checked.

Then you'd add a new loop to go through them and figure out which ones are set to 1.

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

Post by jfrazierjr »

Lindharin wrote:
jfrazierjr wrote:Ugh... I am having trouble getting my syntax right inside my loop. What i want to is to build a CHECK string from a list.
I've got to run (picking up in-laws for dinner tonight), so I can't put this into MT and test it, but on a quick look the following loop has a problem:

[H,C(numTargets),CODE: {
[h: targetString = targetString + " 0 |" + listGet(validTargets, roll.count) + "| CHECK" ]
}]

In the internal statement, you need a variable in the first spot, before the 0. Something like:

[h: targetString = targetString + "target" + roll.count+ " | 0 |" + listGet(validTargets, roll.count) + "| CHECK" ]


Then you will have a bunch of variables, target0 through target12 (if you had 13 possible targets), which are set to either 0 if unchecked or 1 if checked.

Then you'd add a new loop to go through them and figure out which ones are set to 1.

Thanks, I had already figured that out (I copied the wrong thing), but the problem is that the input string I don't know how to get it properly quoted. Each option to Input needs to be quoted, followed by a comma for the next option. Soo.. how do I get quotes in there since the normal delimiter for string contact is quotes? As far as I know, there is no "escape" character which would allow me to embed a literal quote.
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..

Kzintzi
Giant
Posts: 156
Joined: Mon Feb 19, 2007 12:18 am
Location: Perth, Western Australia

Post by Kzintzi »

jfrazierjr wrote:
Thanks, I had already figured that out (I copied the wrong thing), but the problem is that the input string I don't know how to get it properly quoted. Each option to Input needs to be quoted, followed by a comma for the next option. Soo.. how do I get quotes in there since the normal delimiter for string contact is quotes? As far as I know, there is no "escape" character which would allow me to embed a literal quote.
I think I read somewhere in here that you can use double quotes to enquote single quotes and then the parser will place the single quotes into the resulting string but will evaluate the single quotes as quotes when the string itself is evaluated (ie using html like color='red' ).. assuming it hasn't been changed from the build it was written against this has the info in it:

http://forums.rptools.net/viewtopic.php?t=5177

heres the relevant text:
An important note: you can use either double or single quotes to indicate a string. Note that I had to use both types in the <span> tag below, because I wanted a quoted string 'color:red' to be inside the larger string. If I had used the same kind of quote in both places, MapTool would become quite confused and give me the unhelpful error message "Could not execute the command: null".

it's the macro sticky and the relevant section is under WRITING MACROS (about 2/3 of the way down)

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

Post by jfrazierjr »

Ok... I am really darn close now. This spits out the right string, which I can copy/paste manually into an input(). But when I call the input directly in the macro with targetString as the argument, it barfs... Help?

Code: Select all

[h: numTargets = listCount(validTargets)]

<!--    MACRO SCOPPED VARIABLES --> 
[h: attackTargets = ""]
[h: targetString= ""]
Targets: {numTargets}<br>
[H,C(numTargets),CODE: { 
	[h:  foo = eval( "targetNumber" +roll.count   +   "=" +  "''")   ];
}]


[H,C(numTargets),CODE: { 
	[h: targetString = targetString +    "'targetNumber" +  roll.count + " | 0 | " + listGet(validTargets, roll.count) + " | CHECK'<br> " + if(numTargets >  (roll.count+1) , " , " , "   ") ] 
}]
{targetString}
 
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 »

**** EDIT: Ignore this. I missed your prior post, so you're already past this stage. ****
jfrazierjr wrote: Thanks, I had already figured that out (I copied the wrong thing), but the problem is that the input string I don't know how to get it properly quoted. Each option to Input needs to be quoted, followed by a comma for the next option. Soo.. how do I get quotes in there since the normal delimiter for string contact is quotes? As far as I know, there is no "escape" character which would allow me to embed a literal quote.
Ah, try this:

[h: targetString = targetString + " ' target" + roll.count+ " | 0 |" + listGet(validTargets, roll.count) + "| CHECK ' , " ]

That's a single quote at the start of the line, and a single quote at the end, followed by the comma.

Because it ends with a comma after the last iteration of the loop, though, you need to add one more line after the end of the loop. It can be something just to fill the space, though, like:

[h: targetString = targetString + " ' blah |---------------- | --------------| LABEL ' "]
Last edited by Lindharin on Thu Nov 27, 2008 7:13 pm, edited 1 time in total.

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

Post by Lindharin »

jfrazierjr wrote:Ok... I am really darn close now. This spits out the right string, which I can copy/paste manually into an input(). But when I call the input directly in the macro with targetString as the argument, it barfs... Help?
I'm not sure the input function would like the <br> inside the targetString.

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

Post by PyroMancer2k »

jfrazierjr wrote:Ok... I am really darn close now. This spits out the right string, which I can copy/paste manually into an input(). But when I call the input directly in the macro with targetString as the argument, it barfs... Help?
Yea I think it looks right in chat but I think two things are wrong. First off like Lindharin said input() probably doesn't like <br>. The second problem is that you have ' in the string. But I'm pretty sure input() requires you to have " in it.

I'm guessing this is what you want?

Code: Select all

[H: validTargets = "Ork, Goblin, Kobold"]
[h: numTargets = listCount(validTargets)]

<!--    MACRO SCOPPED VARIABLES -->
[h: attackTargets = ""]
[h: targetString= "input("]
Targets: {numTargets}<br>
[H,C(numTargets),CODE: {
   [h:  foo = eval( "targetNumber" +roll.count   +   "=" +  "''")   ];
}]

[C(numTargets,'<BR>'),CODE: {
   [h: targetString = targetString + ' "targetNumber' + roll.count + ' | 0 | ' + listGet(validTargets, roll.count) + ' | CHECK " ' + if(numTargets >  (roll.count+1) , " , " , "   ") ]
}]
[H: targetString = targetString + ")"]
{targetString}<BR>
[eval(targetString)]

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

Post by jfrazierjr »

Ok.. thanks to everyone, I have gotten a bit further. Now, I am having trouble with embedding a CODE block inside an if statement:

Code: Select all

[h: numTargets = listCount(validTargets)]

<MACRO>
[h: attackTargets = ""]
[h: allTargets = ""]
[h: targetString= "input("]
[H,C(numTargets),CODE: {
   [h:  foo = eval( "targetNumber" +roll.count   +   "=" +  "''")   ];
}]

[C(numTargets,'<BR>'),CODE: {
   [h: targetString = targetString + ' "targetNumber' + roll.count + ' | 0 | ' + listGet(validTargets, roll.count) + ' | CHECK " ' + if(numTargets >  (roll.count+1) , " , " , "   ") ]
}]
[H: targetString = targetString + ")"]
[h: eval(targetString)]


[FOR(i ,0,listCount(validTargets)-1), CODE: {
 	[h: thisRoll = eval("rollNum" + roll.count +   "=" + d20)  ]
	[h: attackString = if((eval("targetNumber" + roll.count) == 1), CODE:{["foo"]} , "bar" 	)] 
	[attackString]	
}]
If I replace that if statement inside the FOR loop to have "foo" instead of CODE:{["foo"]} (or any variation I have tried) it works and spits out the expected output based on which check boxes were selected.
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: If I replace that if statement inside the FOR loop to have "foo" instead of CODE:{["foo"]} (or any variation I have tried) it works and spits out the expected output based on which check boxes were selected.
That's cause you can't have CODE blocks in the middle of an if(). You need to set it up an an [if():] block like so.

Code: Select all

 [h,if(eval("targetNumber" + roll.count) == 1),CODE: {
  [attackString = "foo"]
 };{
  [attackString = "bar"]
 }]  

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

Post by PyroMancer2k »

b48 is out and your new options still aren't in the build yet. I was kinda looking forward to the TAB option as a way to improve some input displays.

User avatar
mmbutter
Cave Troll
Posts: 36
Joined: Tue Nov 25, 2008 4:29 pm
Location: Huntersville, NC
Contact:

Post by mmbutter »

I noticed that listSort() still doesn't exist in b48, either...

Post Reply

Return to “Documentation Requests/Discussion”