Canceling a macro and killing a span moloch

Thoughts, Help, Feature Requests, Bug Reports, Developing code for...

Moderators: dorpond, trevor, Azhrei

Forum rules
PLEASE don't post images of your entire desktop, attach entire campaign files when only a single file is needed, or generally act in some other anti-social behavior. :)
Post Reply
Hekau Chasut
Cave Troll
Posts: 54
Joined: Fri Jul 02, 2010 4:53 am

Canceling a macro and killing a span moloch

Post by Hekau Chasut »

Hey Guys,

I am new to this Forum, so I hope I created this thread in the right board.

Shortly I became a member of an online group of "Arcane Codex" that uses MapTools. Some days ago I decided to redo our macros, since they seemed to be quiet chaotic and did not use their full potential

The following macro executes a magical spell.
I have two problems with it, I could not solve on my own...

The first line after the block that defines the variables should stop the macro. (assert) It does so, but the text it gives out is not impersonated. ("zu wenige Kraftpunkte") I tried to add "/self" or "/im name" and checked, whether the Token was impersonated, but it did not help.
I think the problem is, that it is some kind of "alarm message", but no usual text. Do you have any idea, what I could do to change this?

Now to my second question: I would like to shorten the moloch at the end of the macro. Can I somehow only once define the span and use it for every case of the switch?

Code: Select all

[h: skillname = "Mit Pflanzen & Tieren sprechen"]
[h: skill = 4]
[h: MW = 13]
[h: WW = "-"]
[h: Kosten = 2]

[h: assert(Kosten <= Kraftpunkte, ""+skillname+": zu wenige Kraftpunkte", 0)]

[h: status = input("value|0|Modifikatoren eingeben")]
[h: abort(status)]
[h, if(isNumber(value)): modifier = value; modifier = eval(value)]

[h: dicepool = 2d10]
[h: valueEvaluated = dicepool + skill + ChaB + modifier - Belastung]

[h: result = 0]
[h, if(dicepool == 2): result=1]
[h, if(dicepool == 3): result=2]
[h, if(dicepool == 19): result=3]
[h, if(dicepool == 20): result=4]
[h, if(valueEvaluated > MW): result=5]

[r, switch(result):
	case1: ""+skillname+": <span bgcolor='#FFFFFF' title='Wurf: "+dicepool+", FW: "+skill+"+"+ChaB+", Bel: "+Belastung+", Mod: "+modifier+"'> Kritischer Patzer </span>";
	case2: ""+skillname+": <span bgcolor='#FFFFFF' title='Wurf: "+dicepool+", FW: "+skill+"+"+ChaB+", Bel: "+Belastung+", Mod: "+modifier+"'> Automatischer Fehlschlag </span>";
	case3: ""+skillname+": <span bgcolor='#FFFFFF' title='Wurf: "+dicepool+", FW: "+skill+"+"+ChaB+", Bel: "+Belastung+", Mod: "+modifier+"'> Automatischer Erfolg </span>";
	case4: ""+skillname+": <span bgcolor='#FFFFFF' title='Wurf: "+dicepool+", FW: "+skill+"+"+ChaB+", Bel: "+Belastung+", Mod: "+modifier+"'> Kritischer Erfolg </span>";
	case5: ""+skillname+": Mindestwert "+MW+" mit <span bgcolor='#FFFFFF' title='Wurf: "+dicepool+", FW: "+skill+"+"+ChaB+", Bel: "+Belastung+", Mod: "+modifier+"'> "+valueEvaluated+" </span> erreicht.";
	default: ""+skillname+": Mindestwert "+MW+" mit <span bgcolor='#FFFFFF' title='Wurf: "+dicepool+", FW: "+skill+"+"+ChaB+", Bel: "+Belastung+", Mod: "+modifier+"'> "+valueEvaluated+" </span> nicht erreicht.";]

[h: Kraftpunkte = min(Kraftpunkte - Kosten, KraftpunkteMax)]
[h: bar.Kraftpunkte = Kraftpunkte / KraftpunkteMax]

User avatar
biodude
Dragon
Posts: 444
Joined: Sun Jun 15, 2008 2:40 pm
Location: Montréal, QC

Re: Canceling a macro and killing a span moloch

Post by biodude »

Greetings, and welcome to the forums (fora?)!
Wiki: assert() only sends error-text to the user running the macro (i.e. 'self'-only): it is never sent as "impersonated". If you want the message to come out as impersonated, you would have to fake it, using something a bit fancier, including Queued Conditional Output (outputTo Function), and formatting the output to 'look' impersonated. Probably not worth the effort.
A simpler solution would be to include the token name (and image) in the assert output:

Code: Select all

...
[H: tokenName = getName() ]
[H: tokenImage = <img src='"+ getTokenImage( 40 ) +"'></img> ]
[H: errorMessage = "<b>"+ tokenImage + tokenName +":</b> "+ skillname+": zu wenige Kraftpunkte" ]
[H: assert( Kosten <= Kraftpunkte , errorMessage , 0 )]
... 
Fake Impersonation
If you are comfortable with user-defined functions, I use this macro to automatically format a message to look like it was impersonated:

Code: Select all

<!-----===== token.outputFrom =====----->
<!-- emulates output from current token. --> 
[H: outputMessage = arg( 0 )]
[H, if( argCount()>1 ): color = arg( 1 ) ; color = "#000000" ]
[H, if( argCount()>2 ): bg.color = arg( 2 ) ; bg.color = "transparent" ]
[H: outputText = 
    "<div style='color: "+ color +" ; background: "+ bg.color +";'><table cellpadding='0'>
        <tr>
            <td valign='top' width='40' style='padding-right: 5px'><img src='"+ getTokenImage( 40 ) +"'></img></td>
            <td valign='top' style='margin-right: 5px'>"+ token.name +":</td>
            <td valign='top'>"+ outputMessage +"</td>
        </tr>
    </table></div>" 
]
[H: macro.return = outputText )]    <!-- using strformat could be dangerous here if outputMessage has strformat code? -->
 
Define the function like so, in a macro called onCampaignLoad on a Lib:Token

Code: Select all

[R: defineFunction( 'token.outputFrom', 'token.outputFrom@this', 1, 1 )]
I don't know what a "moloch" is, but if you are referring to the output in the SWITCH case, then I suggest extracting all the text common to all output strings, and storing that in a variable, so it can be re-used in each case. I also recommend building your output message, and sending it to output all at once, at the end:

Code: Select all

...
[H: message = skillname+": <span bgcolor='#FFFFFF' title='Wurf: "+dicepool+", FW: "+skill+"+"+ChaB+", Bel: "+Belastung+", Mod: "+modifier+"'>" ]  <!-- still missing contents and closing </span> tag, to be added later. -->
[H, SWITCH(result):
   case 1: message = message +" Kritischer Patzer </span>";
   case 2: message = message +" Automatischer Fehlschlag </span>";
   case 3: message = message +" Automatischer Erfolg </span>";
   case 4: message = message +" Kritischer Erfolg </span>";
   case 5: message = message +valueEvaluated+" </span> erreicht.";
   default: message = message +valueEvaluated+" </span> nicht erreicht."
]

[h: Kraftpunkte = min(Kraftpunkte - Kosten, KraftpunkteMax)]
[h: bar.Kraftpunkte = Kraftpunkte / KraftpunkteMax]
<!-- OUTPUT -->
[R: message ] 
Building a string the fancy way
Here's how I would do it, using the Wiki: strformat() function, which I find to be an easy way to build a string "template", and adjust specific contents as needed (it's also faster in loops that repeat a lot, but this is probably not an issue for you at the moment):

Code: Select all

...
[H: message.txt = "%{skillname}: <span bgcolor='#FFFFFF' title='Wurf: %{dicepool}, FW: %{skill} +%{ChaB}, Bel: %{Belastung}, Mod: %{modifier}'> %s</span> %s" ]  <!-- still missing span contents, and trailer text at the end, to be added later with strformat(). -->
[H, SWITCH(result):
   case 1: message = strformat( message.txt , "Kritischer Patzer" , "" ) ;
   case 2: message = strformat( message.txt , "Automatischer Fehlschlag" , "" ) ;
   case 3: message = strformat( message.txt , "Automatischer Erfolg" , "" ) ;
   case 4: message = strformat( message.txt , "Kritischer Erfolg" , "" ) ;
   case 5: message = strformat( message.txt , "valueEvaluated" , "erreicht" ) ;
   default: message = strformat( message.txt , "valueEvaluated" , "nicht erreicht" )
]

[h: Kraftpunkte = min(Kraftpunkte - Kosten, KraftpunkteMax)]
[h: bar.Kraftpunkte = Kraftpunkte / KraftpunkteMax]
<!-- OUTPUT -->
[R: message ] 
If this does not make sense, or you have other questions, feel free to ask. I also did not have time to test any of this code, so if it doesn't work, let me know and I'll take a closer look to make sure I didn't make any mistakes.
"The trouble with communicating is believing you have achieved it"
[ d20 StatBlock Importer ] [ Batch Edit Macros ] [ Canned Speech UI ] [ Lib: Math ]

Hekau Chasut
Cave Troll
Posts: 54
Joined: Fri Jul 02, 2010 4:53 am

Re: Canceling a macro and killing a span moloch

Post by Hekau Chasut »

Now that you told me, that the errorMessage can only be seen by the player using the macro anyway, I decided that it is enough for now, if he is told about the Error.

strformat is really great. That's exactly what I have been looking for.

I had to do some minor changes, but now it works great.

Thanks for your help.

Code: Select all

[h: skillname = "Mit Pflanzen & Tieren sprechen"]
[h: skill = 4]
[h: Attribut = ChaB]
[h: MW = 13]
[h: WW = "-"]
[h: Kosten = 2]

[h: errorMessage = "<span  style='color: red'>"+skillname+": zu wenige Kraftpunkte</span>"]
[h: assert(Kosten <= Kraftpunkte, errorMessage, 0)]

[h: status = input("value|0|Modifikatoren eingeben")]
[h: abort(status)]
[h, if(isNumber(value)): modifier = value; modifier = eval(value)]

[h: dicepool = 2d10]
[h: valueEvaluated = dicepool + skill + Attribut + modifier - Belastung]

[h: result = 0]
[h, if(dicepool == 2): result=1]
[h, if(dicepool == 3): result=2]
[h, if(dicepool == 19): result=3]
[h, if(dicepool == 20): result=4]
[h, if(valueEvaluated >= MW): result=5]

[h: message.txt= "%{skillname}: Mindestwert %{MW} mit<span bgcolor='#FFFFFF' title='Wurf: %{dicepool}, FW: %{skill} +%{ChaB}, Bel: %{Belastung}, Mod: %{modifier}'> %s</span> %s" ]  

[h, switch(result):
   case 1: message = strformat( message.txt , "Kritischem Patzer" , "nicht erreicht" ) ;
   case 2: message = strformat( message.txt , "Automatischem Fehlschlag" , "nicht erreicht" ) ;
   case 3: message = strformat( message.txt , "Automatischem Erfolg" , "erreicht" ) ;
   case 4: message = strformat( message.txt , "Kritischem Erfolg" , "erreicht" ) ;
   case 5: message = strformat( message.txt , valueEvaluated , "erreicht" ) ;
   default: message = strformat( message.txt , valueEvaluated  , "nicht erreicht" )
]
[h: Kraftpunkte = min(Kraftpunkte - Kosten, KraftpunkteMax)]
[h: bar.Kraftpunkte = Kraftpunkte / KraftpunkteMax]

[R: message]

Post Reply

Return to “MapTool”