not seeing the obvious

Discuss macro implementations, ask for macro help (to share your creations, see User Creations, probably either Campaign Frameworks or Drop-in Resources).

Moderators: dorpond, trevor, Azhrei, giliath, jay, Mr.Ice

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

not seeing the obvious

Post by mfrizzell »

I'm apparently not seeing the obvious. I've fiddled with this simple macro for a couple of hours staring at it and can't seem to see the issue. I'm getting errors in both if() roll options.

Code: Select all

<!-- General Damage -->
[h: Name = getProperty("Name")]
[h: Dead = getProperty("Dead")]
[h: HP = getProperty("HP")]
[h: TempHP = getProperty("TempHP")]
[h: Bloodied = getProperty("Bloodied")]
[h:Damage = DamageInflicted]
[H:TempHP = TempHP - Damage]
[h:HP = HP + min(0, TempHP)]
[h:TempHP = max(0,TempHP)]

[r: Name] takes [r:Damage] HP of damage<br>

[r, if(isPC()), code:
  {
  [h, if(HP <= Bloodied): setState("Bloodied",1);setState("Bloodied",0)]
  [h, if(HP <= 0): setState("Dying",1);setState("Dying",0)]
  [h, if(HP <= 0): setState("Prone",1);setState("Prone",0)]
  [r: Name] has [r:HP] HP and [r:TempHP] temporary HP remaining.<br>
  [r, if(HP<= Dead), code:
    {
    [h: setState("Dead",1)]
   [h: setState("Dying",0)]
   };]
 };]
[h, if(isNPC()), code:
 {
  [h, if(HP <= Bloodied): setState("Bloodied",1);setState("Bloodied",0)]
  [h, if(HP <= 0): setState("Dead",1);setState("Dead",0)]
   [h, if(getState("Dead"), code:
     {
     [h: removeFromInitiative()]
     [h: id = getSelected()]
     [h: setLayer("Object",id)]
     };]
  };]

[H:bar.Damage = HP / MaxHP]

Another set of eyes would be greatly appreciated.
Thanks
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."

User avatar
Rumble
Deity
Posts: 6235
Joined: Tue Jul 01, 2008 7:48 pm

Re: not seeing the obvious

Post by Rumble »

What error are you getting? The only thing I see on first glance is that you don't need the semicolons for if conditions that only have one branch - you can do:

Code: Select all

[r,if(condition),code:
{
    [x = 1d20]
}]

User avatar
CoveredInFish
Demigod
Posts: 3104
Joined: Mon Jun 29, 2009 10:37 am
Location: Germany
Contact:

Re: not seeing the obvious

Post by CoveredInFish »

If you want to specifiy the else branch you have to add a code branch . even if its empty.

Code: Select all

[r,if(condition),code:
{
    [x = 1d20]
};{}]

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

Re: not seeing the obvious

Post by biodude »

Syntax error: your second nested IF() option is missing a closing bracket after the closing bracket from the function used as the condition. I do this all the time and started emulating other people's code formatting on the forums so I now compulsively add spaces around brackets and other delimiters to make them easy to see and count:

mfrizzell wrote:...

Code: Select all

...
[r, if( isPC() ), code:
  {
  ...
  [r, if( HP<= Dead ), code:
    { <!--so far, so good -->
    ...
    }]<!-- either add an empty else case, or omit the semi-colon as Rumble & CIF have pointed out -->
 }]
[h, if( isNPC() ), code:
 {
  ... <!-- so far, so good -->
   [h, if( getState("Dead") ), code:
     {  <!-- oops.  added closing bracket to preceding IF() -->
     ...
     }]
  }]
...
"The trouble with communicating is believing you have achieved it"
[ d20 StatBlock Importer ] [ Batch Edit Macros ] [ Canned Speech UI ] [ Lib: Math ]

User avatar
Raoden
Dragon
Posts: 381
Joined: Fri Dec 18, 2009 2:33 am
Location: San Diego

Re: not seeing the obvious

Post by Raoden »

Rumble wrote:What error are you getting? The only thing I see on first glance is that you don't need the semicolons for if conditions that only have one branch - you can do:

Code: Select all

[r,if(condition),code:
{
    [x = 1d20]
}]

You can do that, but it will get you a useless quotation mark of output if the condition is not met.

CoveredInFish wrote:If you want to specifiy the else branch you have to add a code branch . even if its empty.

No, I'm quite certain you can specify the "else" branch even without using [wroll]code[/wroll]. It may be true, though, that if you are using [wroll]code[/wroll] and the "else" branch is empty, you are still supposed to put empty braces {} there.

biodude wrote:Syntax error: your second nested IF() option is missing a closing bracket after the closing bracket from the function used as the condition. I do this all the time and started emulating other people's code formatting on the forums so I now compulsively add spaces around brackets and other delimiters to make them easy to see and count:

Aha! I think biodude has your real issue pegged. And yeah, I do this all the time too. :?
"Fairy tales do not tell children the dragons exist. Children already know that dragons exist. Fairy tales tell children the dragons can be killed."
- G. K. Chesterton

Wonderful HTML/CSS reference * Color Manager * Token Manager 2.0

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

Re: not seeing the obvious

Post by mfrizzell »

biodude wrote:Syntax error: your second nested IF() option is missing a closing bracket after the closing bracket from the function used as the condition. I do this all the time and started emulating other people's code formatting on the forums so I now compulsively add spaces around brackets and other delimiters to make them easy to see and count:

mfrizzell wrote:...

Code: Select all

...
[r, if( isPC() ), code:
  {
  ...
  [r, if( HP<= Dead ), code:
    { <!--so far, so good -->
    ...
    }]<!-- either add an empty else case, or omit the semi-colon as Rumble & CIF have pointed out -->
 }]
[h, if( isNPC() ), code:
 {
  ... <!-- so far, so good -->
   [h, if( getState("Dead") ), code:
     {  <!-- oops.  added closing bracket to preceding IF() -->
     ...
     }]
  }]
...

I'm not sure I follow, that looks like an open bracket to me. Thanks for the help.
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."

User avatar
CoveredInFish
Demigod
Posts: 3104
Joined: Mon Jun 29, 2009 10:37 am
Location: Germany
Contact:

Re: not seeing the obvious

Post by CoveredInFish »

Raoden wrote:
CoveredInFish wrote:If you want to specifiy the else branch you have to add a code branch . even if its empty.

No, I'm quite certain you can specify the "else" branch even without using [wroll]code[/wroll]. It may be true, though, that if you are using [wroll]code[/wroll] and the "else" branch is empty, you are still supposed to put empty braces {} there.

Agreed, but you got me wrong. I meant to say, what you formulated here better. Of course you can state an else case without using code at all. But if you want to use the else part and code together it must have brackets - even if they are empty.

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

Re: not seeing the obvious

Post by biodude »

mfrizzell wrote:I'm not sure I follow, that looks like an open bracket to me. Thanks for the help.


Before:

Code: Select all

   [h, if(getState("Dead"), code:
    {
    ...
   };]

After:

Code: Select all

   [h, if( getState( "Dead" ) ), code:
     {  <!-- oops.  added closing bracket to preceding IF() -->
     ...
     }]

The IF roll option was missing a second closing bracket after the getState("Dead") function call, to close the condition of the IF(). Without it, the code parser keeps looking in vain for the end of the condition and eventually craps out. (I can't highlight text within a code block, but I added space around the brackets to help them stand out more.

Hope that helps.
"The trouble with communicating is believing you have achieved it"
[ d20 StatBlock Importer ] [ Batch Edit Macros ] [ Canned Speech UI ] [ Lib: Math ]

User avatar
Rumble
Deity
Posts: 6235
Joined: Tue Jul 01, 2008 7:48 pm

Re: not seeing the obvious

Post by Rumble »

Bracket = parenthesis. Biodude isn't referring to [ ] or { }, but the parentheses around the getState('Dead') call.

Took me a while to get what he meant because to me:

[ ] ==> Bracket
{ } ==> Brace
( ) ==> Parentheses


but that is apparently the American usage...?

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

Re: not seeing the obvious

Post by biodude »

Or, I'm an amateur programmer and not familiar with all the terms. I'm used to referring to "brackets" in text and sort of lump those many paired-symbols together. I like the terms Rumble has pointed and shall endeavor to use them.

Sorry for the confusion, and thanks for the clarification.
"The trouble with communicating is believing you have achieved it"
[ d20 StatBlock Importer ] [ Batch Edit Macros ] [ Canned Speech UI ] [ Lib: Math ]

User avatar
Rumble
Deity
Posts: 6235
Joined: Tue Jul 01, 2008 7:48 pm

Re: not seeing the obvious

Post by Rumble »

biodude wrote:Or, I'm an amateur programmer and not familiar with all the terms. I'm used to referring to "brackets" in text and sort of lump those many paired-symbols together. I like the terms Rumble has pointed and shall endeavor to use them.

Sorry for the confusion, and thanks for the clarification.



Before you do so, I may not be correct (they may be called brackets in programming, for instance). Wikipedia says that in America, bracket usually refers to [ ], while in the UK, generally they mean ( ).

prestidigitator
Dragon
Posts: 317
Joined: Fri Apr 23, 2010 8:17 pm

Re: not seeing the obvious

Post by prestidigitator »

My understanding is the same as yours, Rumble. The full names I'm used to are:

[] - Square brackets
{} - Curly braces
<> - Angle brackets (when used in pairs to delimit things like vectors)
() - Parentheses
"He knows not how to know who knows not also how to un-know." --Sir Richard Burton

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

Re: not seeing the obvious

Post by biodude »

Rumble wrote:Before you do so, I may not be correct (they may be called brackets in programming, for instance). Wikipedia says that in America, bracket usually refers to [ ], while in the UK, generally they mean ( ).


Could be: I am from one of the Northern Colonies (Canada), so it could be a combination of UK conventions and lack of familiarity with programming conventions (which are likely based on US conventions).

Tomayto, Tomahto, and all that jazz. I like the precision of the names posted here, so I'm perfectly happy to use those in this context.
"The trouble with communicating is believing you have achieved it"
[ d20 StatBlock Importer ] [ Batch Edit Macros ] [ Canned Speech UI ] [ Lib: Math ]

User avatar
Azhrei
Site Admin
Posts: 12058
Joined: Mon Jun 12, 2006 1:20 pm
Location: Tampa, FL

Re: not seeing the obvious

Post by Azhrei »

prestidigitator wrote:My understanding is the same as yours, Rumble. The full names I'm used to are:

[] - Square brackets
{} - Curly braces
<> - Angle brackets (when used in pairs to delimit things like vectors)
() - Parentheses

Heh-heh, semantics! My favorite topic! ;)

Per U.S. usage (and hence, for programming languages that originated here) the term "brackets" means "[" and "]". Braces are the "{" and "}". And parens are the "(" and ")".

So "square brackets" and "curly braces" are redundant. :)

Ruby was developed in Japan so perhaps the terms they use might stick for that language? But what would they call them...?

My guess is that Mathemagician might agree (mathematics have definitions for this symbols as well; they match the programming terms AFAICR).

User avatar
Mathemagician
Dragon
Posts: 666
Joined: Tue May 22, 2007 2:27 pm

Re: not seeing the obvious

Post by Mathemagician »

They do indeed! I feel like sometimes I say curly bracket instead of brace, but that might just be me.

Post Reply

Return to “Macros”