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

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » zMUD General Discussion
smokin711
Newbie


Joined: 09 Dec 2003
Posts: 2

PostPosted: Wed Aug 04, 2004 9:52 am   

script help....can't get this to work....need a genius here
 
What's wrong with these aliases?

whenever a rat enters, it spams "claw rat" and zMUD freezes up. Anyone able to

perhaps tell me what I'm doing wrong?



#CLASS {Automated_Ratting} {disable}
#ALIAS rat_attack {claw rat;rat_check}
#ALIAS rat_check {#IF (@rat_slain >= "3" or @rat_present < "1") {#SAY {ROOM CLEAR OF RATS}}

{#IF (@rat_present > "0" and @rat_balance) {rat_attack;rat_balance = 0} {#TEMP {^You have

recovered balance on all limbs.} {rat_attack;rat_balance = 0}}}}
#ALIAS rat_enter {#ADD rat_present 1;rat_check}
#ALIAS rat_exit {#ADD rat_present -1;rat_check}
#ALIAS rat_reset {rat_present = "0";rat_slain = "0";rat_busy = 0;rat_balance = 1}
#VAR rat_balance {1} {1}
#VAR rat_busy {0} {0}
#VAR rat_present {0} {0}
#VAR rat_slain {0} {0}
#VAR rat_type {a baby rat|a young rat|a rat|an old rat|a black rat}
#TRIGGER {^A blizzard rages around you, blurring the world into a slate of uniform white.}

{rat_reset}
#TRIGGER {^Deepest Stygian night steals over the land as the symbolic hourglass empties}

{rat_slain = "0"}
#TRIGGER {^With a flick of its small whiskers, {@rat_type} dashes out of view.} {rat_exit}
#TRIGGER {^With a squeak, {@rat_type} darts into the room, looking about wildly.}

{rat_enter}
#TRIGGER {^You have recovered balance on all limbs.} {rat_balance = 1}
#TRIGGER {^You have slain {(@rat_type)}, retrieving the corpse.} {#ADD rat_present -1;#ADD

rat_slain 1;#IF ("%1" == "a baby rat") {#ADD rat_amount 1;#ADD rat_value 7};#IF ("%1" == "a

young rat") {#ADD rat_amount 1;#ADD rat_value 14};#IF ("%1" == "a rat") {#ADD rat_amount

1;#ADD rat_value 21};#IF ("%1" == "an old rat") {#ADD rat_amount 1;#ADD rat_value 28};#IF

("%1" == "a black rat") {#ADD rat_amount 1;#ADD rat_value 35};#SAY {@rat_slain RATS

KILLED};rat_check}
#TRIGGER {^You see {a single exit|exits} leading} {rat_reset}
#TRIGGER {^Your eyes are drawn to {@rat_type} that darts suddenly into view.} {rat_enter}
#TRIGGER {^{@rat_type} darts into the shadows and disappears.} {rat_exit}
#TRIGGER {^{@rat_type} noses its way cautiously out of the shadows.} {rat_enter}
#TRIGGER {^{@rat_type} wanders back into its warren where you may not follow.} {rat_exit}
#TRIGGER {^{@rat_type} wanders into view, nosing about for food.} {rat_enter}
#CLASS 0

#CLASS {Ratting} {enable}
#VAR rat_amount {0} {0}
#VAR rat_value {0} {0}
#TRIGGER {{The Ratman stands here|Liirup, the placid|Crazy Hakhim paces|Jorj, the city

caretaker}} {sell rats to ratman;sell rats to liirup;sell rats to hakhim;sell rats to

jorj;removed_gold;rat_amount = "0";rat_value = "0";#SAY {RATTING TALLIES RESET}}
#BUTTON 14 {Automated Ratting} {#T+ Automated_Ratting;#SAY {AUTOMATED RATTING

ENABLED};rat_reset} {Automated Ratting} {rat_reset;#T- Automated_Ratting;#SAY {AUTOMATED

RATTING DISABLED}} {} {1} {} {Size} {128} {24} {Pos} {24} {264} {12} {10} {} {} "" {} {} {}
#CLASS 0
Reply with quote
SCORNME
Novice


Joined: 25 Jul 2004
Posts: 48
Location: aka Falan

PostPosted: Wed Aug 04, 2004 3:21 pm   
 
#ALIAS rat_attack {claw rat;rat_check}
#ALIAS rat_check {#IF (@rat_slain >= "3" or @rat_present < "1") {#SAY {ROOM CLEAR OF RATS}} {#IF (@rat_present > "0" and @rat_balance) {rat_attack;rat_balance = 0}

Is this it? rat_check will run rat_attack, which immediately runs rat_check again... ad infinitum

Would swapping rat_balance & rat_check work?

#ALIAS rat_attack {claw rat;rat_check}
#ALIAS rat_check {#IF (@rat_slain >= "3" or @rat_present < "1") {#SAY {ROOM CLEAR OF RATS}} {#IF (@rat_present > "0" and @rat_balance) {rat_balance = 0;rat_attack}
Reply with quote
LightBulb
MASTER


Joined: 28 Nov 2000
Posts: 4817
Location: USA

PostPosted: Wed Aug 04, 2004 4:05 pm   Re: script help....can't get this to work....need a genius h
 
Oops, beaten to the answer! I'll leave this in case the long-winded explanation helps.

It's quite simple. You use too many aliases and lose track of what you're doing.
#TRIGGER {^With a squeak, {@rat_type} darts into the room, looking about wildly.} {rat_enter}
#ALIAS rat_enter {#ADD rat_present 1;rat_check}
#ALIAS rat_check {#IF (@rat_slain >= "3" or @rat_present < "1") {#SAY {ROOM CLEAR OF RATS}} {#IF (@rat_present > "0" and @rat_balance) {rat_attack;rat_balance = 0} {#TEMP {^You have recovered balance on all limbs.} {rat_attack;rat_balance = 0}}}}
#ALIAS rat_attack {claw rat;rat_check}

These aliases are just subscripts and they can be replaced by their actual scripts. Substituting the scripts of rat_attack and rat_check, it's quite obvious that you have a recursive loop.

rat_check:
#ALIAS rat_check {
#IF (@rat_slain >= "3" or @rat_present < "1") {
#SAY {ROOM CLEAR OF RATS}
} {
#IF (@rat_present > "0" and @rat_balance) {
rat_attack
rat_balance = 0
} {
#TEMP {^You have recovered balance on all limbs.}{rat_attack;rat_balance = 0}}}}

Substituting for rat_attack:
#ALIAS rat_check {
#IF (@rat_slain >= "3" or @rat_present < "1") {
#SAY {ROOM CLEAR OF RATS}
} {
#IF (@rat_present > "0" and @rat_balance) {
claw rat
rat_check

rat_balance = 0
} {
#TEMP {^You have recovered balance on all limbs.}{rat_attack;rat_balance = 0}}}}

Substituting for rat_check:
#ALIAS rat_check {
#IF (@rat_slain >= "3" or @rat_present < "1") {
#SAY {ROOM CLEAR OF RATS}
} {
#IF (@rat_present > "0" and @rat_balance) {
claw rat
#IF (@rat_slain >= "3" or @rat_present < "1") {
#SAY {ROOM CLEAR OF RATS}
} {
#IF (@rat_present > "0" and @rat_balance) {
rat_attack
rat_balance = 0} {
#TEMP {^You have recovered balance on all limbs.} {rat_attack;rat_balance = 0}
}}

rat_balance = 0
} {
#TEMP {^You have recovered balance on all limbs.} {rat_attack;rat_balance = 0}}}}

Substituting for rat_attack again:
#ALIAS rat_check {
#IF (@rat_slain >= "3" or @rat_present < "1") {
#SAY {ROOM CLEAR OF RATS}
} {
#IF (@rat_present > "0" and @rat_balance) {
claw rat
#IF (@rat_slain >= "3" or @rat_present < "1") {
#SAY {ROOM CLEAR OF RATS}
} {
#IF (@rat_present > "0" and @rat_balance) {
claw rat
rat_check

rat_balance = 0
} {
#TEMP {^You have recovered balance on all limbs.} {rat_attack;rat_balance = 0}
}}
rat_balance = 0
} {
#TEMP {^You have recovered balance on all limbs.} {rat_attack;rat_balance = 0}}}}

Nothing changes between one claw rat and the next, so you will claw the rat twice (or at least try to) then do another rat_check, with nothing changed, and claw a third time then do another rat_check, with nothing changed, and claw a fourth time...

To fix, change the variable before using rat_attack.
rat_balance = 0
rat_attack
_________________
LightBulb
Senior member

Most scripts in this forum are written for Command Line entry.
Don't even open the Settings Editor unless its use is specified or obvious.
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » zMUD 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