if inside if inside if?

Doc requests, organization, and submissions

Moderators: dorpond, trevor, Azhrei

Post Reply
allan
Kobold
Posts: 9
Joined: Tue Oct 26, 2010 7:08 am

if inside if inside if?

Post by allan »

Okay, so what I've got here is a little predicament; I'm working on a macro that has a variety of variables. First off, if the token is not "latched", then it latches the token to their target (which is outlined in the properties). Then, if it is latched (which will be on another turn) it asks if the target is still alive. If it is it deals damage. If it is not, it delatched the token from the target.

Up to this point everything is golden, but I need to add another if command asking if it won a strength percentile, and if it did, then the token is thrown from the target. It would ask this after it determined the token's target was still alive.

Here's what I have. Individually they work, but once I get about 3 if's deep it doesn't want to work anymore.

Code: Select all

[if(state.Latch == 0),CODE:
{
    [h:Essence = Essence - (15)]
    [h:bar.Essence = Essence / MaxES]
    <b>[r:token.name]</b> latches on to <b>[r:target]</b>, digging in hard with her teeth and dealing <b>[r:round(Strength*Level/2/4)] damage</b>!
    [h: setState("Latch", 1)]};
     {
     [h:status = input(
     "alive|Yes|Is your target alive?")]
     [h:abort(status)]

          [if(alive=="Yes"),CODE:
          {
          [h:status = input(
          "win|Yes|Did you win your Strength Percentile?")]
          [h:abort(status)]

	[if(win=="Yes"),CODE:
	{
	<b>[r:token.name]</b> continues her hold on <b>[r:target]</b>, dealing <b>[r:round(Strength*Level/2/4)] damage</b>!
	};
	{<b>[r:token.name]</b> is thrown off <b>[r:target]</b>!
	[h: setState("Latch", 0)]
	};]
          };
          {
          <b>[r:token.name]</b> releases her grip on <b>[r:target]</b>!
         [h: setState("Latch", 0)]
          };]
     };]
If you remove the

Code: Select all

	[if(win=="Yes"),CODE:
	{
	<b>[r:token.name]</b> continues her hold on <b>[r:target]</b>, dealing <b>[r:round(Strength*Level/2/4)] damage</b>!
	};
	{<b>[r:token.name]</b> is thrown off <b>[r:target]</b>!
	[h: setState("Latch", 0)]
	};]
and replace it with whatever, it will work. It's that if command that it doesn't like.

User avatar
mfrizzell
Dragon
Posts: 762
Joined: Sat Feb 13, 2010 2:35 am
Location: California

Re: if inside if inside if?

Post by mfrizzell »

You can only nest 'ifs' 2 deep.
DCI/RPGA# 7208328396 Skype ID mfrizzell77
Characters:
Strabor - Dwarf Avenger 5th Level
Tikkanan - Human Warlock 2nd Level
----------------------------------------------------
"People are more violently opposed to fur than leather because it's safer to harass rich women than motorcycle gangs."

allan
Kobold
Posts: 9
Joined: Tue Oct 26, 2010 7:08 am

Re: if inside if inside if?

Post by allan »

if that's the case, is there any way to work around what I'm trying to do, or is it simply too complicated?

User avatar
mfrizzell
Dragon
Posts: 762
Joined: Sat Feb 13, 2010 2:35 am
Location: California

Re: if inside if inside if?

Post by mfrizzell »

There probably a couple of ways you could do it. I haven't looked too hard at your code but maybe you could use switch/case for multiple options. That would allow you to pick one of many choices.
You could also daisy chain your if statements one right after another instead of nesting them.
You could also use macro roll option to shoot out to another macro and return with an answer. Here is the wiki for that. http://www.lmwcs.com/rptools/wiki/macro ... _option%29
DCI/RPGA# 7208328396 Skype ID mfrizzell77
Characters:
Strabor - Dwarf Avenger 5th Level
Tikkanan - Human Warlock 2nd Level
----------------------------------------------------
"People are more violently opposed to fur than leather because it's safer to harass rich women than motorcycle gangs."

allan
Kobold
Posts: 9
Joined: Tue Oct 26, 2010 7:08 am

Re: if inside if inside if?

Post by allan »

Yeah that helps. Thanks mfriz!

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

Re: if inside if inside if?

Post by aliasmask »

[Deleted]
edit: Nevermind, I was being a retard.

Code: Select all

[R, if(state.Latch == 0), CODE: {
   [H:Essence = Essence - 15]
   [H: bar.Essence = Essence / MaxES]
   [R: strformat("<b>%{token.name}</b> latches on to <b>%{target}</b>, digging in hard with her teeth and dealing <b>%d damage</b>!",
      round(Strength * Level /8))
   ]
   [H: state.Latch = 1]
};{
   [H:status = input("alive|1|Target is Alive|CHECK")]
   [H: abort(status)]
   [R, if(alive), CODE: {
      [H: status = input("win|1|You won Strength Challange|CHECK")]
      [H: abort(status)]
      [R, if(win): strformat("<b>%{token.name}</b> continues her hold on <b>%{target}</b>, dealing <b>%s damage</b>!",round(Strength * Level /8));
         strformat("<b>%{token.name}</b> is thrown off <b>%{target}</b>!")]
      [H, if(!win): state.Latch = 0]
   };{
      [R: strformat("<b>%{token.name}</b> releases her grip on <b>%{target}</b>!")]
      [H: state.Latch = 0]
   }]
}] 

allan
Kobold
Posts: 9
Joined: Tue Oct 26, 2010 7:08 am

Re: if inside if inside if?

Post by allan »

My god you are amazing.

Now to pick-apart your macro so I can figure out what you did!

I don't really have a good grasp on commas or exclamation marks (or %'s either, haven't seen those before).

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

Re: if inside if inside if?

Post by wolph42 »

allan wrote:My god you are amazing.

Now to pick-apart your macro so I can figure out what you did!

I don't really have a good grasp on commas or exclamation marks (or %'s either, haven't seen those before).
the ! is not part of the code.
the strformat AFAIK does two things:
1. it will substitute any string between %{ and } with its corresponding variable so
[damage = 5]
[strformat("hit for %{damage}")]
And you can use erm... operators(?) like %d %s and probably others, though I only use %s (string). which will substitute that operator with anything after the ",". So
[damage=5]
[strformat("hit for %s", damage)]

It took me about a year before I started using these, but its fast and handy.

Post Reply

Return to “Documentation Requests/Discussion”