If/code functions and Warhammer Hit Location

If you have searched the other User Creations subforums and an answer to your question has not been found, please post here!

Moderators: dorpond, trevor, Azhrei, Gamerdude

Post Reply
YuriPRIME
Kobold
Posts: 19
Joined: Fri Nov 09, 2012 5:45 pm

If/code functions and Warhammer Hit Location

Post by YuriPRIME »

Hello, I'm working on macro sets for my Warhammer 2nd Edition gaming group. For last two days I was building a basic Attack macro and gradually expanding it. The goal was for the Macro to take few properties off the token, like Weapon Skill for instance, add modifier, roll two dice and compile the result.
Everything went just fine, the macro takes the property, adds modifier, treats that as a target number. Then it rolls separate d10s for Decimals and Normal numbers, processes them to create the result ranging from 1 to 100 with ability to reverse the number order to get the Warhammer Hit Locations numbers.
I've managed to create functions to display either Degrees of Success or Failure, and all went well, until I tried to play with the 'If functions' that gives commands and codes.

Basically the idea was, that there is the final Location-Hit variable calculated from the previous dice rolls and the 'if functions' checks the number, assigning a text Phrase to another variable which would be displayed at the very end, or moves on to compare the number again, to some higher values.
I used the [if(comparison), code:{command}; ...], asking the macro to run another check and asign a text Phrase if it finds proper values in comparison section.
I tested the macro with few basic increments and it went on fine, but once I finished the whole chain, I get constant Errors...
The Macro below is partially written in Polish
Macro in question

Code: Select all

<!-----------This part loads in cWS - which stands for Character's Weapon Skill - no problem here
	[h: WW=getProperty("cWS")]	
	[h: WWmod=Modyfikator]	
	[h: finalWW=WW+WWmod]		
<!----------The main 'engine' block - everything runs smoothly here. 'nLokTraf' stands for NewHitLocation and is the crucial value used later
	[h: Dziesietne = 1d10-1]		
	[h: Zwykle = 1d10-1]		
	[h: ZwykleT = Zwykle]		
	[h: Skladowa = ((Dziesietne * 10))+Zwykle]	
	[h: OSklad = Skladowa]		
	[h: nSkladowa = if(Skladowa == 0, 100, Osklad)]	
	[h: LokTraf = ((Zwykle *10))+Dziesietne]		
	[h: OLokTraf = LokTraf]			
	[h: nLokTraf = if(LokTraf == 0, 100, OLokTraf)]	
	[h: StanTestu = if(finalWW>=nSkladowa, 1, 0)]
	[h: StopnieTemp = if(finalWW>=nSkladowa, (floor((finalWW-nSkladowa)/10)),
	(floor((nSkladowa-finalWW)/10)))]
	[h: Stopnie = if(0>StopnieTemp, 0, StopnieTemp)]

<!-----------This is the problematic part. Basically 'Lokacja' means Location, and the idea was to provide that variable with a phrase, by comparing the nLokTraf with numerical ranges corresponding to each Hit Location in game's mechanics.
[e,if(15>=nLokTraf), code:{[Lokacja="Glowa"]}; 
	{[if(nLokTraf>15 && 35>=nLokTraf), code:{[Lokacja="Prawa Reka"]};{
		[if(nLokTraf>35 && 55>=nLokTraf), code:{[Lokacja="Lewa Reka"]};{
			[if(nLokTraf>55 && 80>=nLokTraf), code:{[Lokacja="Korpus"]};{
				[if(nLokTraf>80 && 90>=nLokTraf), code:{[Lokacja="Prawa Noga"]};{
					[if(nLokTraf>90 && 100>=nLokTraf), code:{[Lokacja="Lewa Noga"]};{[Lokacja="Error"]}]}]}]}]}]}]

<!------------------The block that shows results - no problems here. The idea is to display the phrase indicating body location where [Lokacja] is.
<b>Próg Wyzwania:</b> [finalWW]<br>
<b>Wynik Rzutu:</b> [nSkladowa] [if(StanTestu==1): "Sukces"; "Niepowodzenie"] [Stopnie] Stopni<br> 
<b>Trafienie w:</b> [nLokTraf] [Lokacja]<br>
I tried everything, I'm reading the macro writing guides on rptools wiki, I've double checked all the brackets and can't find the problem, yet no matter what, I get the same message:
Error Message
   Error in body of roll.       Statement options (if any): e,if(15>=nLokTraf), code       Statement Body (first 200 characters): {[Lokacja="Glowa"]}; {[if(nLokTraf>15 && 35>=nLokTraf), code:{[Lokacja="Prawa Reka"]};{ [if(nLokTraf>35 && 55>=nLokTraf), code:{[Lokacja="Lewa Reka"]};{ [if(nLokTraf>55 && 80>=nLokTraf), code:
Can anyone explain what am I doing wrong? And... in rather plain way, since I'm not native English user.
Thanks in advance.

User avatar
Full Bleed
Demigod
Posts: 4736
Joined: Sun Feb 25, 2007 11:53 am
Location: FL

Re: If/code functions and Warhammer Hit Location

Post by Full Bleed »

YuriPRIME wrote: Can anyone explain what am I doing wrong? And... in rather plain way, since I'm not native English user.
Thanks in advance.
http://lmwcs.com/rptools/wiki/Working_W ... ODE_Levels

You might want to take a look at the SWITCH Option.
Maptool is the Millennium Falcon of VTT's -- "She may not look like much, but she's got it where it counts."

User avatar
wolph42
Winter Wolph
Posts: 9999
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: If/code functions and Warhammer Hit Location

Post by wolph42 »

what FB said. Also note that in this case you dont need the 'code' part. you only need that if you have more than one line of code to execute
additionally you could also consider using the table function.

YuriPRIME
Kobold
Posts: 19
Joined: Fri Nov 09, 2012 5:45 pm

Re: If/code functions and Warhammer Hit Location

Post by YuriPRIME »

Thank you, I struggled with this for some time and went for tables in the end.
Everything works now

Post Reply

Return to “Requests for HELLLLP!”