Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
Alvar
Newbie


Joined: 05 Jun 2007
Posts: 8

PostPosted: Wed Aug 27, 2008 1:21 pm   

[2.36] temporary triggers created with alarm don't compile
 
I have tried writing a trigger that will cause some action to happen after a few seconds:

#alarm {+3}
{ #if (@somevar = "somevalue")
{ do one thing
}
{
do some other thing
}
}

Without #alarm the trigger works. With #alarm a temporary trigger is created that fires after three seconds. However, that trigger doesn't compile because the code of the generated trigger looks like this:

#if (@somevar = "somevalue")
{ do one thing
}{
do some other thing
}

The result is a mismatched braces error, probably because the whitespace between the two braces in the middle has been removed.
Reply with quote
shalimar
GURU


Joined: 04 Aug 2002
Posts: 4690
Location: Pensacola, FL, USA

PostPosted: Wed Aug 27, 2008 2:01 pm   
 
the opening { needs to be on the same line as the #IF or #Alarm it belongs to

#ALARM +3 {
#IF (@somevar="some value") {
Do one thing
} {
Do another thing
}
}

That would work
_________________
Discord: Shalimarwildcat
Reply with quote
Arde
Enchanter


Joined: 09 Sep 2007
Posts: 605

PostPosted: Wed Aug 27, 2008 4:05 pm   
 
shalimar wrote:
the opening { needs to be on the same line as the #IF or #Alarm it belongs to

Sorry? Shocked
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: Wed Aug 27, 2008 4:58 pm   
 
CMUD is *very* picky about the exact syntax used for multiline scripts. Also, you shouldn't have any spaces after the { character. Your script needs to be entered as:
Code:
#alarm {+3} {
  #if (@somevar = "somevalue") {
    do one thing
    } {
    do some other thing
    }
}

Or, you can remove the indentations and just use what shalimar posted. So I'm not sure why you are saying "Sorry?"...just follow the instructions that Shalimar gave and put the { character at the end of the previous lines.

If you *must* put the { on the next line (like with some C programming syntax), then the { needs to be the only character on the line. So this will also work:
Code:
#alarm {+3}
{
  #if (@somevar = "somevalue")
    {
      do one thing
    } {
      do some other thing
    }
}
Reply with quote
Alvar
Newbie


Joined: 05 Jun 2007
Posts: 8

PostPosted: Thu Aug 28, 2008 6:52 am   
 
Now that did it. The problem was not with the braces after the #alarm or #if statements but the two braces between the true and false branch of the #if statement. Putting them on the same line helped.

Actually the syntax of the #if statement worked well when used without the #alarm. It's just that #alarm seems to remove some whitespace from the code, resulting in an unusable syntax for the generated trigger.
Reply with quote
Arde
Enchanter


Joined: 09 Sep 2007
Posts: 605

PostPosted: Thu Aug 28, 2008 2:49 pm   
 
Alvar wrote:
Actually the syntax of the #if statement worked well when used without the #alarm.

That's true and that's why I've said "Sorry?" There is no problems with #IF while you keep its } { separated by the space or newline, and there is no need to keep "{" on the same line. To keep or not to keep { on the first line is a matter of taste.
Reply with quote
shalimar
GURU


Joined: 04 Aug 2002
Posts: 4690
Location: Pensacola, FL, USA

PostPosted: Thu Aug 28, 2008 7:33 pm   
 
Eh, my oversight for not realizing it worked with that syntax. It was just the first 'error' or so i thought, that i saw.

The #ALARM is not eating any whitespace that it shouldn't, its just that the starting example had no consistency with how the code was being formatted.
_________________
Discord: Shalimarwildcat
Reply with quote
Alvar
Newbie


Joined: 05 Jun 2007
Posts: 8

PostPosted: Fri Aug 29, 2008 6:30 am   
 
Quote:
The #ALARM is not eating any whitespace that it shouldn't


I'm not so sure about that. The formatting of the trigger generated by the #alarm is different from the code inside the original trigger. If it just left the formatting alone, the trigger would work without problems. The difference that causes the problem is that the newline between the two braces in the middle is removed, turning two separate tokens into a single one. It doesn't do this if both are on the same line, separated by space, but to me it's not really obvious why it should treat newlines and spaces differently. Actually my original code was indented (that somehow got lost when I pasted the example), so in addition to the newline there were spaces in front of the second brace as well, but those probably were eaten together with the newline.
Reply with quote
shalimar
GURU


Joined: 04 Aug 2002
Posts: 4690
Location: Pensacola, FL, USA

PostPosted: Fri Aug 29, 2008 8:48 pm   
 
you need to use the BB code tags around your script to save indentation on the forum

For me, I tend to write my code on one line, then let zMUD/CMUD reformat the script to look pretty.

It cant eat whitespace if i dont give it any to eat, and it always likes how it indents stuff itself.
_________________
Discord: Shalimarwildcat
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net