intfiction.org

The Interactive Fiction Community Forum
It is currently Sun May 19, 2013 2:59 pm

All times are UTC - 6 hours [ DST ]




Post new topic Reply to topic  [ 21 posts ]  Go to page 1, 2, 3  Next
Author Message
PostPosted: Tue Jan 31, 2012 3:43 pm 
Offline

Joined: Sun Nov 06, 2011 12:17 pm
Posts: 156
Location: Toledo, Ohio, USA
Every time I start to really get going on my story, I hit a bump in the road. I added the 'else if' statement to the code below and now I get compile errors. I checked the code for some amount of time and checked the manuals but can't figure it how to fix the problem. Wouldn't mind some help.

RonG

Code:

+ring: Wearable 'platinum ring' 'platinum ring'
 "Faint cryptic runes are inscribed around the band of the platinum ring." 
 
 dobjFor(Wear){
  action(){
   inherited();
   "You feel a strange magical power coursing through your body!
    And, you hear the faint echo of the word GLOW surrounding you.";
   gActor.makeWizard();
  }
 }

 dobjFor(Doff){
  action(){
   inherited();
   "You shudder as the power of the ring and the magic of the GLOW chant leave
    you";
   gActor.makeNormal();
  }
 }
;

  DefineIAction(Glow);
  VerbRule(Glow)
    'glow'
  :GlowAction
  verbPhrase='glow/glowing'
;
  modify GlowAction
   execAction(){
    if(gActor.powerLevel!=wizard)
     reportFailure('At this time, you do not have the power of a Wizard.');
    else if(gActor.powerLevel=wizard)
     "The blue, radiant light quickly fades from your body.";
     gActor.brightness=0;
    else{
     "You chant the GLOW spell!
      Your body begins to glow with a bright, radiating blue light!"; 
      gActor.brightness=10;
      }
     }




Top
 Profile Send private message  
 
PostPosted: Tue Jan 31, 2012 3:53 pm 
Offline
User avatar

Joined: Tue Apr 20, 2010 2:48 pm
Posts: 680
"if" only controls a single instruction if you omit the braces. This is a good reason to always use braces. When you write:

Code:
if (blah)
  something;
  something;
else
  something;


What the compiler does is:

Code:
if (blach)
  something;
something;
else
  something;

Which doesn't make sense.

Also, you used a "=" instead of a "==", which compiles but it's not what you mean.


Top
 Profile Send private message  
 
PostPosted: Tue Jan 31, 2012 4:54 pm 
Offline

Joined: Sun Mar 01, 2009 8:02 pm
Posts: 902
To put Nikos's observation in a slightly different way ... T3 doesn't care about indentation. (Unlike Inform 7, which does.) However, Workbench does automatic indentation, which can give you some good guidance on how the compiler is going to interpret your code.

If you only want one statement after an if-test, you can do this:

Code:
if (someCondition == true) "That's certainly true. ";
else "That's not true at all. ";


What you can't do is:

Code:
if (someCondition == true) "That's certainly true -- and worth awarding a point. ";
someAchievement.awardPointsOnce();
else "That's not true at all, so no points for you, bucko! ";


You would have to do it this way:

Code:
if (someCondition == true) {
    "That's certainly true -- and worth awarding a point. ";
    someAchievement.awardPointsOnce();
    }
else "That's not true at all, so no points for you, bucko! ";


But again, what matters is the brackets, not the indentation.


Top
 Profile Send private message  
 
PostPosted: Tue Jan 31, 2012 5:49 pm 
Offline

Joined: Sun Nov 06, 2011 12:17 pm
Posts: 156
Location: Toledo, Ohio, USA
I looked at all the posts but still don't understand this. The statement I added to the original of this was the two lines of the code that begin with 'else if'. before that, all the story compiled and ran with no problems; including the wizard section. I added the 'else if' part so that the actor could turn off the glowing, if he desired for some reason. As you can see, I made your suggestions but I no doubt did it all incorrectly :roll: :roll:

Code:
modify GlowAction
   execAction()
    if(gActor.powerLevel!==wizard){
     reportFailure('At this time, you do not have the power of a Wizard.');}
    else if(gActor.powerLevel==wizard){
     "The blue, radiant light quickly fades from your body.";
     gActor.brightness=0;}
    else{
     "You chant the GLOW spell!
      Your body begins to glow with a bright, radiating blue light!"; 
      gActor.brightness=10;
;     
 


Top
 Profile Send private message  
 
PostPosted: Tue Jan 31, 2012 5:59 pm 
Offline
User avatar

Joined: Wed Feb 03, 2010 4:25 pm
Posts: 264
Location: Sweden
You're missing a } for your final else block.

Edit: And the operator for "not equal to" is != (one exclamation mark and one equals sign). See chapter 3.4 of Learning TADS 3 for a full explanation.

_________________
"The thing I like about deadlines is the wonderful whooshing noise they make as they go past."
- Douglas Adams


Top
 Profile Send private message  
 
PostPosted: Tue Jan 31, 2012 7:10 pm 
Offline
User avatar

Joined: Tue Apr 20, 2010 2:48 pm
Posts: 680
It seems you don't grasp the basics yet. Like the syntax of functions/methods and "if" statements. For example your execAction()'s code is not inside braces. Also, your code's formatting is very chaotic and unreadable, which *will* make things very difficult for you. A good way to write that code is:

Code:
modify GlowAction
    execAction()
    {
        if (gActor.powerLevel != wizard) {
            reportFailure('At this time, you do not have the power of a Wizard.');
        } else if (gActor.powerLevel == wizard) {
            "The blue, radiant light quickly fades from your body.";
            gActor.brightness = 0;
        } else {
            "You chant the GLOW spell!
            Your body begins to glow with a bright, radiating blue light!";
            gActor.brightness = 10;
    }
;

And now it's very obvious that the final "else" is missing the closing brace.

Another thing you're missing is putting a space after a text sentence ends. For example, instead of:

Code:
"The blue, radiant light quickly fades from your body."


You should write:

Code:
"The blue, radiant light quickly fades from your body. "

This is needed in order to avoid sentences running together.


Top
 Profile Send private message  
 
PostPosted: Wed Feb 01, 2012 8:27 am 
Offline
User avatar

Joined: Wed Feb 03, 2010 4:25 pm
Posts: 264
Location: Sweden
Also, that final else will never happen. If gActor.powerLevel is wizard, the second code block is executed - if it isn't, we get the first. How are you planning to trigger the third?

_________________
"The thing I like about deadlines is the wonderful whooshing noise they make as they go past."
- Douglas Adams


Top
 Profile Send private message  
 
PostPosted: Wed Feb 01, 2012 2:09 pm 
Offline

Joined: Sun Nov 06, 2011 12:17 pm
Posts: 156
Location: Toledo, Ohio, USA
Well, I'm stumped. That's not difficult for me. I made all the suggestions I received and now I receive 109 errors, yes 109, when I compile my story. If I comment out the entire 'ring' section then the program compiles with no errors and and runs as expected. I still think that the problem is in the else-if section.

Quote:

+ring: Wearable 'platinum ring' 'platinum ring'
"Faint cryptic runes are inscribed around the band of the platinum ring."
//location = Beach
dobjFor(Wear){
action(){
inherited();
"You feel a strange magical power coursing through your body!
And, you hear the faint echo of the word GLOW surrounding you.";
gActor.makeWizard();
}
}

dobjFor(Doff){
action(){
inherited();
"You shudder as the power of the ring and the magic of the GLOW chant leave
you";
gActor.makeNormal();
}
}
;

DefineIAction(Glow);
VerbRule(Glow)
'glow'
:GlowAction
verbPhrase='glow/glowing'
;

modify GlowAction
execAction()
{
if(gActor.powerLevel!=wizard){
reportFailure('At this time, you do not have the power of a Wizard.');
}else if(gActor.powerLevel==wizard){
"The blue, radiant light quickly fades from your body.";
gActor.brightness==0;
}else{
"You chant the GLOW spell!
Your body begins to glow with a bright, radiating blue light!";
gActor.brightness==10;
}
;


Top
 Profile Send private message  
 
PostPosted: Wed Feb 01, 2012 2:17 pm 
Offline

Joined: Sun Mar 01, 2009 8:02 pm
Posts: 902
Well, for one thing, you're using the comparison operator (==) in a couple of places where you want the assignment operator (=).

Edit: However, that won't cause compilation errors. Such a statement will simply evaluate as true or nil, but will have no effect on the rest of the code. It's no different than writing this line:
Code:
1;


Looking through your code, I don't immediately spot any syntax errors. What you've posted should compile.

However, as pointed out earlier in this thread, that final else block will never be reached, because the two previous tests take care of all of the possible cases. [[ It looks to me as if you're trying to use that final block to create an Unglow action. If so, you need to start by figuring out what command the player will use to stop glowing, and then implement that separately.]] Edit: No, I see it now. You need a separate test to determine if the player is currently glowing. You're trying to test powerlevel again, and that won't tell you what you need to know.

I would also point out that you don't need to use modify to create the code for execAction(). You can put that within the definition of DefineIAction(Glow), before the semicolon.


Last edited by Jim Aikin on Wed Feb 01, 2012 4:39 pm, edited 1 time in total.

Top
 Profile Send private message  
 
PostPosted: Wed Feb 01, 2012 2:28 pm 
Offline

Joined: Sun Nov 06, 2011 12:17 pm
Posts: 156
Location: Toledo, Ohio, USA
RealNC;

You are correct about my lack of TADS basics and my formatting of the sections of my code. However, despite my dementia [Look it up.], I continue to strive to learn TADS. I spend eight to ten hours a day(often longer) working on it. I will make the formatting changes you suggested.

I really am not looking for pity or criticism , so, please give me just a little bit of slack.

RonG


Top
 Profile Send private message  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 21 posts ]  Go to page 1, 2, 3  Next

All times are UTC - 6 hours [ DST ]


Who is online

Users browsing this forum: Bing [Bot] and 2 guests


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 post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group