TinTin++ Mud Client The TinTin++ message board

 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
TinTin++ Mud Client

Nested IF statements

 
Post new topic   Reply to topic    The TinTin++ message board Forum Index -> Script Help
View previous topic :: View next topic  
Author Message
cupcake



Joined: 06 Jun 2008
Posts: 9

PostPosted: Fri Jun 06, 2008 3:20 am    Post subject: Nested IF statements Reply with quote

From what I understand, IF statements can be nested by leaving out semi-colons between them. However, it seems like it's not possible to have more than twenty nested. Here is an example of where it seems to break down:

Code:

/action {^$prompt} {
   /if {$sleep  == 0 && $stun == 0 && $aeon == 0 && $herbbal == 1 && $checkee == 1 && $anorexia == 0 && $indifference == 0} {
      /if {$paralysis == 1 && $checkee == 1} {outc $bloodroot;eat $bloodroot;/var checkee 0}
      /if {$limp == 1 && $checkee == 1} {outc $kelp;eat $kelp;/var checkee 0}
      /if {$confusion == 1 && $checkee == 1} {outc $ash;eat $ash;/var checkee 0}
      /if {$stupidity == 1 && $checkee == 1} {outc $goldenseal;eat $goldenseal}
      /if {$berserking == 1 && $checkee == 1} {outc $lobelia;eat $lobelia;/var checkee 0}
      /if {$impatience == 1 && $checkee == 1} {outc $goldenseal;eat $goldenseal;/var checkee 0}
      /if {$recklessness == 1 && $checkee == 1} {outc $lobelia;eat $lobelia;/var checkee 0}
      /if {$darkshade == 1 && $checkee == 1} {outc $ginseng;eat $ginseng;/var checkee 0}
      /if {$blindness == 0 && $checkee == 1} {outc $bayberry;eat $bayberry;/var checkee 0}
      /if {$deafness == 0 && $checkee == 1} {outc $hawthorn;eat $hawthorn;/var checkee 0}
      /if {$hatred == 1 && $checkee == 1} {outc $ash;eat $ash;/var checkee 0}
      /if {$sensitivity == 1 && $checkee == 1} {outc $kelp;eat $kelp;/var checkee 0}
      /if {$masochism == 1 && $checkee == 1} {outc $lobelia;eat $lobelia;/var checkee 0}
      /if {$epilepsy == 1 && $checkee == 1} {outc $goldenseal;eat $goldenseal;/var checkee 0}
      /if {$hallucinations == 1 && $checkee == 1} {outc $ash;eat $ash;/var checkee 0}
      /if {$peace == 1 && $checkee == 1} {outc $bellwort;eat $bellwort;/var checkee 0}
      /if {$lovers == 1 && $checkee == 1} {outc $bellwort;eat $bellwort;/var checkee 0}
      /if {$earthrot == 1 && $checkee == 1} {outc $bloodroot;eat $bloodroot;/var checkee 0}
      /if {$heartflutter == 1 && $checkee == 1} {outc $bloodroot;eat $bloodroot;/var checkee 0}
      /if {$haemophilia == 1 && $checkee == 1} {outc $ginseng;eat $ginseng;/var checkee 0}
      /if {$vomiting == 1 && $checkee == 1} {outc $ginseng;eat $ginseng;/var checkee 0}
      /if {$vertigo == 1 && $checkee == 1} {outc $lobelia;eat $lobelia;/var checkee 0}
      /if {$paranoia == 1 && $checkee == 1} {outc $ash;eat $ash;/var checkee 0}
      /if {$agoraphobia == 1 && $checkee == 1} {outc $ash;eat $ash;/var checkee 0}
      /if {$loneliness == 1 && $checkee == 1} {outc $lobelia;eat $lobelia; /var checkee 0}
      /if {$lethargy == 1 && $checkee == 1} {outc $ginseng;eat $ginseng;/var checkee 0}
      /if {$thinblood == 1 && $checkee == 1} {outc $ginseng;eat $ginseng;/var checkee 0}
      /if {$claustrophobia == 1 && $checkee == 1} {outc $lobelia;eat $lobelia;/var checkee 0}
      /if {$hypochondria == 1 && $checkee == 1} {outc $kelp;eat $kelp;/var checkee 0}
      /if {$dissonance == 1 && $checkee == 1} {outc $goldenseal;eat $goldenseal;/var checkee 0}
      /if {$dementia == 1 && $checkee == 1} {outc $ash;eat $ash;;/var checkee 0}
      /if {$generosity == 1 && $checkee == 1} {outc $bellwort;eat $bellwort/var checkee 0}
      /if {$justice == 1 && $checkee == 1} {outc $bellwort;eat $bellwort;/var checkee 0}
      /if {$shyness == 1 && $checkee == 1} {outc $goldenseal;eat $goldenseal;/var checkee 0}
      /if {$clumsiness == 1 && $checkee == 1} {outc $kelp;eat $kelp;/var checkee 0}
      /if {$weariness == 1 && $checkee == 1} {outc $kelp;eat $kelp;/var checkee 0}
      /if {$dizziness == 1 && $checkee == 1} {outc $goldenseal;eat $goldenseal;/var checkee 0}
      /if {$slickness == 1 && $checkee == 1} {outc $bloodroot;eat $bloodroot; /var checkee 0}
      /if {$addiction == 1 && $checkee == 1} {outc $ginseng;eat $ginseng;/var checkee 0}
      /if {$hypersomnia == 1 && $checkee == 1} {outc $ash;eat $ash;/var checkee 0}
      /if {$bloodcurse == 1 && $checkee == 1} {outc $ash;eat $ash;/var checkee 0}
      /if {$bloodpoison == 1 && $checkee == 1} {outc $kelp;eat $kelp;/var checkee 0}
      /if {$asthma == 1 && $checkee == 1} {outc $kelp;eat $kelp;/var checkee 0}
   }
}


So, I have all these IF statements nested in one other IF statement. If I have 20 or less, it works fine. If I add another one, I get a huge debug dump. Is there a better or workable way of doing this? Thank you.
Back to top
View user's profile Send private message
Scandum
Site Admin


Joined: 03 Dec 2004
Posts: 3274

PostPosted: Fri Jun 06, 2008 8:45 am    Post subject: Reply with quote

Tintin sucks at nesting because of the way the scripting engine is written.

One solution is adding a ; behind each if check so it's no longer nested. Since you set checkee to 0 the other if checks won't trigger.

Another option is using aliasses and a list:
Code:

#list {checkeelist} {{paralysis} {limp} {confusion} {etc}}


#alias {fixparalysis} {outc $bloodroot;eat $bloodroot}
#alias {fixlimp}      {outc $kelp;eat $kelp}
#alias {fixconfusion} {outc $ash;eat $ash}


#action {^$prompt}
{
    #if {$sleep == 0 && $stun == 0 && $aeon == 0 && $herbbal == 1 && $checkee == 1 && $anorexia == 0 && $indifference == 0}
    {
        #forall {$checkeelist}
        {
            #if {$&0 == 1 && $checkee == 1} {#var checkee 0;fix&0}
        }
    }
}
Back to top
View user's profile Send private message Send e-mail
cupcake



Joined: 06 Jun 2008
Posts: 9

PostPosted: Fri Jun 06, 2008 7:05 pm    Post subject: Reply with quote

Thanks for your quick reply and all your work on this project. The problem with those solutions is that in the interest of speed, I don't want all the following IF statements to be evaluated if one is true. I was wondering if I could use a RETURN statement to break out of an IF statement, but I'm not entirely sure how it works.

Barring that, I might create a list that stores all the current afflictions that is evaluated whenever the prompt appears. The problem with that is that there is an order of precedence for curing that must be followed; even with a list of current afflictions, I would still need to evaluate many conditional statements to determine the curing order. Any other suggestions would be most appreciated. Thanks again.
Back to top
View user's profile Send private message
Scandum
Site Admin


Joined: 03 Dec 2004
Posts: 3274

PostPosted: Sun Jun 08, 2008 12:10 pm    Post subject: Reply with quote

Speed wise the following should be slightly faster:

Code:

#action {^$prompt}
{
    #if {$sleep == 0 && $stun == 0 && $aeon == 0 && $herbbal == 1 && $checkee == 1 && $anorexia == 0 && $indifference == 0}
    {
        #forall {$checkeelist}
        {
            #if {$&0 == 1}
            {
                #if {$checkee == 1} {#var checkee 0;fix&0}
            }
        }
    }
}


#return never really worked out well and doesn't increase performance. I'll probably remove the command in the future. If I ever get around to writing a pre-compiler it should be easy to add a proper #break, #else and #return command.


Regarding working with a queue, easiest would be incorporating the priority of each affliction into the affect name and using the srt option in #list.

Code:

#var {000_paralysis} {0}
#var {020_limp} {0}
#var {001_confusion} {0}

#list afflictions clr

#alias {addaffliction}
{
    #list afflictions srt %0
}

#act {You've been paralized} {addaffliction 000_paralize}

#alias {000_paralysis} {outc $bloodroot;eat $bloodroot}

#action {^$prompt}
{
    #if {$sleep == 0 && $stun == 0 && $aeon == 0 && $herbbal == 1 && $checkee == 1 && $anorexia == 0 && $indifference == 0}
    {
        #if {"$afflictions[1]" != ""}
        {
            $afflictions[1];
            #list afflictions del 1;
            #var checkee 0
        }
    }
}


(tagging this achaea for people doing searches)


Last edited by Scandum on Wed Dec 10, 2008 10:49 pm; edited 2 times in total
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    The TinTin++ message board Forum Index -> Script Help All times are GMT - 5 Hours
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
Get TinTin++ Mud Client at SourceForge.net. Fast, secure and Free Open Source software downloads Get TinTin++ Mud Client at SourceForge.net. Fast, secure and Free Open Source software downloads
TinTin++ Homepage

Powered by phpBB © 2001, 2002 phpBB Group