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

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD Beta Forum
Kanonball
Novice


Joined: 06 Feb 2006
Posts: 48

PostPosted: Tue Nov 21, 2006 9:31 am   

syntax and such..
 
ughh.. spent an hour trying to figure out why my script wouldn't compile.. finally managed to narrow it down to my #while loop...
So I made a blank alias with

#while(true){}


and it tells me I have unmatched parenthesis.. Shocked Did I miss something glaringly obvious?


Last edited by Kanonball on Tue Nov 21, 2006 5:52 pm; edited 2 times in total
Reply with quote
slicertool
Magician


Joined: 09 Oct 2003
Posts: 459
Location: USA

PostPosted: Tue Nov 21, 2006 9:40 am   
 
putting spaces on either side of (true) fixes it for me.
Code:
#while (true) {}
_________________
Ichthus on SWmud: http://www.swmud.org/
Reply with quote
Kanonball
Novice


Joined: 06 Feb 2006
Posts: 48

PostPosted: Tue Nov 21, 2006 9:40 am   
 
ooh.. crap...
#while (true){}

tells me I have a syntax error..


Apparently it has to be
#while (true) {}


ickyRolling Eyes

Of course my script is more complex than that and i still have no idea what spaces i missed/extra'd. Embarassed

A little leeway with formatting would be welcome.
So would the ability to block indent.. Wink
Reply with quote
Kanonball
Novice


Joined: 06 Feb 2006
Posts: 48

PostPosted: Tue Nov 21, 2006 10:10 am   
 
So.. yeah.. I found the compatibility report, and it tells me I have an error at line 30 column 36. Not that there are any line/column indicators in the editor.. Laughing
Anyhow.. that was this line.. right at the "t" in "position"...
But then, i tested the line in a new alias and it works just fine..
$currentbold=%copy($unparsed,($position+1),1);

Um.. should I post my code? Any thoughts? I can't get it work :/
Reply with quote
Kanonball
Novice


Joined: 06 Feb 2006
Posts: 48

PostPosted: Tue Nov 21, 2006 10:14 am   
 
Oh, and the syntax checker consistently throws an Access Violation error as well when I try to use it on my alias.
Reply with quote
Zugg
MASTER


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

PostPosted: Tue Nov 21, 2006 6:34 pm   
 
Paste the full code of the alias here so we can take a look at it and try it on our own systems.

And yes, you ALWAYS NEED SPACES around your command arguments. Spaces are important in CMUD (and in zMUD) and your first example (without spaces) wouldn't work in either CMUD or zMUD.
Reply with quote
Kanonball
Novice


Joined: 06 Feb 2006
Posts: 48

PostPosted: Wed Nov 22, 2006 3:29 pm   
 
I've narrowed it down to this section, it just tells me unmatched parenthesis, and I'm pretty sure all the parenthesis are matched..

#local $unparsed $position $currentbold $targetcolour $boldcol
#if (%copy($unparsed,$position+2,1)=";") {$currentbold=%copy($unparsed,$position+1,1);#if ($currentbold=$boldcol && begins(%copy($unparsed,$position+3,3),$targetcolour)) {$position+=3+%len($targetcolour);#while (%copy($unparsed,$position,1)!="") {Dec=%concat(@Dec,%copy($unparsed,$position,1));$position=$position+1}}} {#if ($currentbold=$boldcol && begins(%copy($unparsed,$position+1,3),$targetcolour)) {$position+=1+%len($targetcolour);#while (%copy($unparsed,$position,1)!="") {Dec=%concat(@Dec,%copy($unparsed,$position,1));$position=$position+1}}}
$unparsed=%right($unparsed,$position);$strlen-=$position;$position=%pos("[",$unparsed);}
Reply with quote
Zugg
MASTER


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

PostPosted: Wed Nov 22, 2006 5:57 pm   
 
CMUD does not have += or -= operators. Also, it looks like you are missing a % in front of the "begins" function. The "unmatched parenthesis" is actually the wrong error message, so it doesn't really mean that the problem is with parens.

Also, it helps in CMUD if you split your script into multiple lines. Then you can use the syntax check in the Tools menu in the settings editor and the cursor will jump to the place in the script where there is a problem. This doesn't work well with long lines that wrap. So try using this:
Code:
#local $unparsed $position $currentbold $targetcolour $boldcol
#if (%copy($unparsed,$position+2,1)=";") {
  $currentbold=%copy($unparsed,$position+1,1);
  #if ($currentbold=$boldcol && begins(%copy($unparsed,$position+3,3),$targetcolour)) {
    $position+=3+%len($targetcolour);
    #while (%copy($unparsed,$position,1)!=%char(27)) {
      Dec=%concat(@Dec,%copy($unparsed,$position,1));
      $position=$position+1}
    }
  } {
    #if ($currentbold=$boldcol && begins(%copy($unparsed,$position+1,3),$targetcolour)) {
      $position+=1+%len($targetcolour);
      #while (%copy($unparsed,$position,1)!=%char(27)) {
        Dec=%concat(@Dec,%copy($unparsed,$position,1));
        $position=$position+1}
      }
    }
  $unparsed=%right($unparsed,$position);
  $strlen-=$position;
  $position=%pos(%char(27)"[",$unparsed);
}

With multiple lines and proper indenting, your scripts will be a *lot* easier to read and debug. Also, notice that I replaced your control characters with calls to %char(27). You should use the %char function to test for control characters. If you embed control characters directly into your script, then you will have trouble saving the script, or exporting/importing to XML or the package library.
Reply with quote
Kanonball
Novice


Joined: 06 Feb 2006
Posts: 48

PostPosted: Thu Nov 23, 2006 1:02 am   
 
Thanks! I wasn't sure if it was my formatting that messed it up, so i crunched it all together with only what i knew was supposed to be spaced. I now have this, and when I try syntax check, cmud tries to crash.
Code:
#local $unparsed $position $currentbold $targetcolour $boldcol
#if (%copy($unparsed,$position+2,1)=";") {
  $currentbold=%copy($unparsed,$position+1,1);
  #if ($currentbold=$boldcol && %begins(%copy($unparsed,$position+3,3),$targetcolour)) {
    $position=$position+3+%len($targetcolour);
    #while (%copy($unparsed,$position,1)!=%char(27)) {
      Dec=%concat(@Dec,%copy($unparsed,$position,1));
      $position=$position+1}
    }
  } {
    #if ($currentbold=$boldcol && %begins(%copy($unparsed,$position+1,3),$targetcolour)) {
      $position=$position+1+%len($targetcolour);
      #while (%copy($unparsed,$position,1)!=%char(27)) {
        Dec=%concat(@Dec,%copy($unparsed,$position,1));
        $position=$position+1}
      }
    }
  $unparsed=%right($unparsed,$position);
  $strlen=$strlen+$position;
  $position=%pos(%char(27)"[",$unparsed);
}
Reply with quote
The Raven
Magician


Joined: 13 Oct 2000
Posts: 463

PostPosted: Fri Nov 24, 2006 7:32 pm   
 
There is an unmatched bracket. Notice near the end, there is a } after $position=$position+1. Also farther up, the same error. Move that down to the next line, and you see that the code should look like this instead (highlighting the redundant } at the end)

Code:
#local $unparsed $position $currentbold $targetcolour $boldcol
#if (%copy($unparsed,$position+2,1)=";") {
  $currentbold=%copy($unparsed,$position+1,1);
  #if ($currentbold=$boldcol && %begins(%copy($unparsed,$position+3,3),$targetcolour)) {
    $position=$position+3+%len($targetcolour);
    #while (%copy($unparsed,$position,1)!=%char(27)) {
      Dec=%concat(@Dec,%copy($unparsed,$position,1));
      $position=$position+1
    }
  }
} {
  #if ($currentbold=$boldcol && %begins(%copy($unparsed,$position+1,3),$targetcolour)) {
    $position=$position+1+%len($targetcolour);
    #while (%copy($unparsed,$position,1)!=%char(27)) {
      Dec=%concat(@Dec,%copy($unparsed,$position,1));
      $position=$position+1
    }
  }
}
$unparsed=%right($unparsed,$position);
$strlen=$strlen+$position;
$position=%pos(%char(27)"[",$unparsed);


Don't know if that code is correct, but at least the brackets are properly matching.
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD Beta Forum 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