Help with a taking damage code

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
ralstad
Cave Troll
Posts: 54
Joined: Sat Nov 19, 2016 12:52 am

Help with a taking damage code

Post by ralstad »

Hello,

I have a problem with the following code.

Code: Select all

[r: hp = getProperty("Vitality")]
[h: wnds=getProperty("Wounds")]
[r: input("dmg|0|Damge You have taken.")]
[r: hpremaining=hp-dmg]
[h: val = abs(hpremaining)]
[h: wndsrmning=wnds-val]
[h: if(hpremaining <= 0),CODE:{
[h: setProperty("Vitality", 0)]
[h: setProperty("Wounds", wndsremaining)]
<b>I have 0 Vitality and [t: wnds-val] left.<b/><br>
};
{
[h: setProperty("Vitality", hpremaining)]
<b>I have [t:hp-dmg] Vitality left.<b/><br>
}]
I get this error. I have tried to figure out where I messed it up but don't see it.

Error in body of roll.       Statement options (if any): h       Statement Body (first 200 characters): if(hpremaining = 0),CODE:{ [h: setProperty("Vitality", 0)] [h: setProperty("Wounds", wndsremaining)] I have 0 Vitality and [t: wnds-val] left. }; { [h: setProperty("Vitality", hpremainin

ralstad

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

Re: Help with a taking damage code

Post by Full Bleed »

ralstad wrote:
Wed Jul 11, 2018 10:55 pm
Hello,

I have a problem with the following code.
Probably the same problem you have HERE with your if roll option statement.
Maptool is the Millennium Falcon of VTT's -- "She may not look like much, but she's got it where it counts."


ralstad
Cave Troll
Posts: 54
Joined: Sat Nov 19, 2016 12:52 am

Re: Help with a taking damage code

Post by ralstad »

Thanks Full Bleed,

Now, I would like to put and extra bit of code into this

Code: Select all

[h: hp = getProperty("Vitality")]
[h: wnds=getProperty("Wounds")]
[h: input("dmg|0|Damge You have taken.")]
[h: hpremaining=hp-dmg]
[h: val = abs(hpremaining)]
[h: wndsrmning=wnds-val]
[r, if(hpremaining <= 0),CODE:
	{
		[h: setProperty("Vitality", 0)]
		[h: setProperty("Wounds", wndsrmning)]				------------ Check to see if wndsrmning is below 0-------------
		<b>I have 0 Vitality and [t: wnds-val] Wounds left.</b><br>
	};
	{
		[h: setProperty("Vitality", hpremaining)]
		<b>I have [t: hp-dmg] Vitality left.</b><br>
	}
]
I would like to put another if as shown above to check for wndsrmning <=0 but I was told this is not suggested is there another way to do this?

ralstad

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

Re: Help with a taking damage code

Post by Full Bleed »

ralstad wrote:
Thu Jul 12, 2018 5:32 pm
I would like to put another if as shown above to check for wndsrmning <=0 but I was told this is not suggested is there another way to do this?
You can use as many IF statements as you want. What you want to stay away from is more than 2 nested CODE levels. MT won't do it without using a workaround.

As Alias indicated in your other thread, if you're only exercising one action using the IF statement and you don't need to use a CODE block then that is the way to go.
Maptool is the Millennium Falcon of VTT's -- "She may not look like much, but she's got it where it counts."

ralstad
Cave Troll
Posts: 54
Joined: Sat Nov 19, 2016 12:52 am

Re: Help with a taking damage code

Post by ralstad »

Full Bleed,

I am trying to do something like this

Code: Select all

[h: hp = getProperty("Vitality")]
[h: wnds=getProperty("Wounds")]
[h: input("dmg|0|Damge You have taken.")]
[h: hpremaining=hp-dmg]
[h: val = abs(hpremaining)]
[h: wndsrmning=wnds-val]
[r, if(hpremaining <= 0),CODE:
	{
		[r, if(wndsrmning>0),CODE:
			{
				[h: setProperty("Vitality", 0)]
				[h: setProperty("Wounds", wndsrmning)]
				<b>I have 0 Vitality and [t: wnds-val] Wounds left.</b><br>
			};
				<b> I HAVE DIED!!!!!!!!!!!</b><br>
			}
		]
	};
	{
		[h: setProperty("Vitality", hpremaining)]
		<b>I have [t: hp-dmg] Vitality left.</b><br>
	}
]
But obviously it doesn't work so what am I doing wrong?

ralstad

ralstad
Cave Troll
Posts: 54
Joined: Sat Nov 19, 2016 12:52 am

Re: Help with a taking damage code

Post by ralstad »

Never mind I figured out the glaringly missing { in my code and it works now.

Sorry guys. :(

ralstad

ralstad
Cave Troll
Posts: 54
Joined: Sat Nov 19, 2016 12:52 am

Re: Help with a taking damage code

Post by ralstad »

here is my finished (at the moment any way) code.

Code: Select all

[h: hp = getProperty("Vitality")]
[h: wnds=getProperty("Wounds")]
[h: input("dmg|0|Damge You have taken.")]
[h: hpremaining=hp-dmg]
[h: val = abs(hpremaining)]
[h: wndsrmning=wnds-val]
[r, if(hpremaining <= 0),CODE:
	{
		[r, if(wndsrmning>0),CODE:
			{
				[h: setProperty("Vitality", 0)]
				[h: setProperty("Wounds", wndsrmning)]
				<b>I have 0 Vitality and [t: wnds-val] Wounds left.</b><br>
			};
			{
				[h: setProperty("Vitality", 0)]
				[h: setProperty("Wounds", 0)]
				<b> I HAVE DIED!!!!!!!!!!!</b><br>
			}
		]
	};
	{
		[h: setProperty("Vitality", hpremaining)]
		<b>I have [t: hp-dmg] Vitality left.</b><br>
	}
]
I also created a macro for healing damage. Here it is.

Code: Select all

[h: hp = getProperty("Vitality")]
[h: maxhp = getProperty("MaxVitality")]
[h: wnds=getProperty("Wounds")]
[h: mxwnds=getProperty("MaxWounds")]
[h: input("heal|0|How much damage was healed.")]
[h: wndschk=wnds+heal]
[h: wndsoverhealchk=mxwnds-wnds]
[h: healchk=hp+heal]
[h: healvit=maxhp-hp]
[r, if(wnds < mxwnds), CODE:
	{
		[r, if(wndschk > mxwnds),CODE:
			{
				[h: setProperty("Wounds",mxwnds)]
				[h: setProperty("Vitality",hp+wndsoverhealchk)]
				<b>I have [t: hp+wndsoverhealchk] Vitality and [t: mxwnds] Wounds left.</b><br>
			};
			{
				[h: setProperty("Wounds",wndschk)]
				<b>I have 0 Vitality and [t: wnds=wnds+heal] Wounds left.</b><br>
			}
		]
	};
	{
		[r, if(healchk>maxhp),CODE:
			{
				[h: setProperty("Vitality",maxhp)]
				<b>I have [t: hp+healvit] Vitality and [t: mxwnds] Wounds left.</b><br>
			};
			{
				[h: setProperty("Vitality",hp+heal)]
				<b>I have [t: hp+heal] Vitality and [t: mxwnds] Wounds left.</b><br>
			}
		]
	}
]
Thanks for everyone who helped me out as you can see I do learn from my mistakes. Even if it is just basic coding.

ralstad

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

Re: Help with a taking damage code

Post by Full Bleed »

ralstad wrote:
Thu Jul 12, 2018 7:38 pm
Never mind I figured out the glaringly missing { in my code and it works now.

Sorry guys. :(
You really need to use an external editor (unless you're using the Nerps editor)... I highly suggest you use Notepad++.

It makes managing brackets much easier.
Maptool is the Millennium Falcon of VTT's -- "She may not look like much, but she's got it where it counts."

ralstad
Cave Troll
Posts: 54
Joined: Sat Nov 19, 2016 12:52 am

Re: Help with a taking damage code

Post by ralstad »

Full Bleed,

I understand what your saying, I have tried using notepad++ or whatever and didn't like it. Not for any reason in particular. Plus if I take my time and code the way the last coding is set up it is starting to make sense to me. Plus it forces me to make sure coding is correct per say. Not saying the coding works but the way it is coded is correct if that make any sense.

ralstad

User avatar
Jagged
Great Wyrm
Posts: 1306
Joined: Mon Sep 15, 2008 9:27 am
Location: Bristol, UK

Re: Help with a taking damage code

Post by Jagged »

ralstad wrote:
Fri Jul 13, 2018 5:11 am
I have tried using notepad++ or whatever and didn't like it
:shock:

In my humble opinion Notepad++ is the single most important development tool currently in use in the IT industry :wink:

Phergus
Deity
Posts: 7132
Joined: Fri May 12, 2006 8:56 pm
Location: Middle of Nowhere, NM
Contact:

Re: Help with a taking damage code

Post by Phergus »

Jagged wrote:
Fri Jul 13, 2018 9:42 am
In my humble opinion Notepad++ is the single most important development tool currently in use in the IT industry :wink:
#truth

User avatar
aliasmask
RPTools Team
Posts: 9024
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: Help with a taking damage code

Post by aliasmask »

I don't think he tried it with my mods. ;)

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

Re: Help with a taking damage code

Post by Full Bleed »

Jagged wrote:
Fri Jul 13, 2018 9:42 am
ralstad wrote:
Fri Jul 13, 2018 5:11 am
I have tried using notepad++ or whatever and didn't like it
:shock:

In my humble opinion Notepad++ is the single most important development tool currently in use in the IT industry :wink:
MT's macro language is frustrating enough to debug... I think anyone willingly writing and editing macros in MT's default editor is engaging in masochistic behaviour.

Lets be honest, the only reason MT's default editor is so bad is because the developers were certain that no one in their right mind would ever actually use it for much more than a place to cut/paste code. If they knew so many new users were going to suffer as they have (are) I just can't believe they'd have left it as is... no one is that cruel.

I think ralstad's biggest problem is that he probably sees Notepad++ as some kind of complicated coding tool. But if he only used it as a glorified text editor it would still save him hours of pain and suffering.

I know that there is a story about water and a horse in there somewhere...
Maptool is the Millennium Falcon of VTT's -- "She may not look like much, but she's got it where it counts."

bobifle
Giant
Posts: 219
Joined: Thu Oct 19, 2017 12:36 pm

Re: Help with a taking damage code

Post by bobifle »

Phergus wrote:
Fri Jul 13, 2018 2:21 pm
Jagged wrote:
Fri Jul 13, 2018 9:42 am
In my humble opinion Notepad++ is the single most important development tool currently in use in the IT industry :wink:
#truth
after vim. :mrgreen: (5 troll points)

To bring something to the thread, I agree with the above statements, MT macro language is already a big mess, you have to have a decent text editor.
If you don't like Notepad++, fine, pick one of your liking (vim, emacs, atom, whatvever).

If you're don't have previous experience with text editors for writing code, then pick Notepad++, you may not like it right now, but you will, and it will make you successful in writing macros, otherwise you'll fail miserably.

Post Reply

Return to “Requests for HELLLLP!”