| View previous topic :: View next topic |
| Author |
Message |
cupcake
Joined: 06 Jun 2008 Posts: 9
|
Posted: Fri Jun 06, 2008 3:20 am Post subject: Nested IF statements |
|
|
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 |
|
 |
Scandum Site Admin
Joined: 03 Dec 2004 Posts: 3274
|
Posted: Fri Jun 06, 2008 8:45 am Post subject: |
|
|
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 |
|
 |
cupcake
Joined: 06 Jun 2008 Posts: 9
|
Posted: Fri Jun 06, 2008 7:05 pm Post subject: |
|
|
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 |
|
 |
Scandum Site Admin
Joined: 03 Dec 2004 Posts: 3274
|
Posted: Sun Jun 08, 2008 12:10 pm Post subject: |
|
|
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 |
|
 |
|