Prompt Trigger Problems

Posted by Warbit on Tue 11 Oct 2011 11:39 PM — 23 posts, 76,573 views.

USA #0
I was trying to get my trigger to fire with the updating of my prompt. Right now it has many problems, but the problem I want to focus on now is that it is not Sending the command 'create food' on prompt update. Variable Hungry is Yes so the and mana is maxed. So there is no reason i see why, I am not sending 'create food'

This is my trigger

<triggers>
  <trigger
   enabled="y"
   expand_variables="y"
   group="Prompt"
   match="^\&lt;(\d+)\/(\d+)Hp (\d+)\/(\d+)Ma (\d+)\/(\d+)Mv AC\:\-(\d+) Continent\:(.*?) Weather\:(.*?)\&gt;$"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>SetVariable("CurHp","%1")
SetVariable("MaxHp","%2")
SetVariable("CurMana","%3")
SetVariable("MaxMana","%4")
SetVariable("CurMove","%5")
SetVariable("MaxMove","%6")
SetVariable("AC","%7")
SetVariable("Continent","%8")

SetVariable("InsideOutside","%9")

if "InsideOutside"~="indoors" then
SetVariable("InsideOutside","Outdoors")
end--if

HpNeeded = %2-%1

if "Hungry" ~="Yes" then
SetVariable("Hungry","No")
end--if

if "Thirsty" ~="Yes" then
SetVariable("Thirsty","No")
end--if



if "HpNeeded" &gt; 5 and "CurrentMana" &gt;16 then
Send("Cast 'cure light'")
end--if

-- create water                  - Lvl:  2, Mana:  5, Learned  

-- create food                   - Lvl:  3, Mana:  6, Learned  
if "Hungry"=="Yes" and "CurMana"&gt;12 then
Send("Cast 'create food'")
Send("Look")
end--if

-- cure minor                    - Lvl:  4, Mana:  8, Learned  
-- bless                         - Lvl:  5, Mana:  8, Learned  
-- shield of faith               - Lvl:  6, Mana: 35, Learned  
-- freshwater                    - Lvl:  4, Mana: 10, Learned  
-- goodberry                     - Lvl:  6, Mana:  7, Learned  
-- bone armor                    - Lvl: 11, Mana: 16, Learned  

</send>
  </trigger>
</triggers>


I am getting no errors since I converted to digits from wildcards. But trigger is not firing. I check that list of variables icon and it assures me Hungry Variable = "Yes". Though it is not updating for me being outside, but that's a problem for a later time.

QUESTION:
1. Why is trigger not firing?
2. How do I fix it?
Australia Forum Administrator #1
Quote:

1. Why is trigger not firing?


You need to show (copy and paste) an example of your prompt before we could answer that.

This is completely wrong:


if "Hungry" ~="Yes" then
  SetVariable("Hungry","No")
end--if


The word "Hungry" will never be equal to the word "Yes".

Do you mean:



if GetVariable ("Hungry") ~="Yes" then
  SetVariable("Hungry","No")
end--if


Ditto for the other similar cases.
USA #2
Thanks Nick Making changes now.

Here is prompt.

<462/567Hp 104/104Ma 331/331Mv AC:-6.8 Continent:Ah Weather:indoors>

All one line.

Edited Prompt Trigger with your changes.

<triggers>
  <trigger
   enabled="y"
   expand_variables="y"
   group="Prompt"
   match="^\&lt;(\d+)\/(\d+)Hp (\d+)\/(\d+)Ma (\d+)\/(\d+)Mv AC\:\-(\d+) Continent\:(.*?) Weather\:(.*?)\&gt;$"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>SetVariable("CurHp","%1")
SetVariable("MaxHp","%2")
SetVariable("CurMana","%3")
SetVariable("MaxMana","%4")
SetVariable("CurMove","%5")
SetVariable("MaxMove","%6")
SetVariable("AC","%7")
SetVariable("Continent","%8")

SetVariable("InsideOutside","%9")

if GetVariable("InsideOutside")~="indoors" then
SetVariable("InsideOutside","Outdoors")
end--if

HpNeeded = %2-%1

if GetVariable("Hungry") ~="Yes" then
SetVariable("Hungry","No")
end--if

if GetVariable("Thirsty") ~="Yes" then
SetVariable("Thirsty","No")
end--if



if "HpNeeded" &gt; 5 and "CurMana" &gt;16 then
Send("Cast 'cure light'")
end--if

-- create water                  - Lvl:  2, Mana:  5, Learned  

-- create food                   - Lvl:  3, Mana:  6, Learned  
if GetVariable("Hungry")=="Yes" and GetVariable("CurMana")&gt;12 then
Send("Cast 'create food'")
Send("Look")
end--if

-- cure minor                    - Lvl:  4, Mana:  8, Learned  
-- bless                         - Lvl:  5, Mana:  8, Learned  
-- shield of faith               - Lvl:  6, Mana: 35, Learned  
-- freshwater                    - Lvl:  4, Mana: 10, Learned  
-- goodberry                     - Lvl:  6, Mana:  7, Learned  
-- bone armor                    - Lvl: 11, Mana: 16, Learned  

</send>
  </trigger>
</triggers>

Amended on Thu 13 Oct 2011 09:13 AM by Warbit
Australia Forum Administrator #3
I presume the trigger still isn't matching?

And I am a bit puzzled by this:


if GetVariable("Hungry") ~="Yes" then
  SetVariable("Hungry","No")
end--if



So if the variable Hungry is not Yes (ie. presumably it is No) then you set it to No. What does that achieve?
USA #4
well if hungry is anything but me being hungry then it will say no i am not hungry.

when i get hungry it will say yes

if it says yes then i will eat and set it to no,
till next time i am hungry.
Australia Forum Administrator #5
Apart from there, where does the variable "Hungry" get set ever?





if "HpNeeded" > 5 and "CurMana" > 16 then
  Send("Cast 'cure light'")
end--if


You are confusing variables with literals. You may as well write:



if 3 > 5 and 2 > 16 then
  Send("Cast 'cure light'")
end--if


You can see they will never be true?
Amended on Fri 14 Oct 2011 05:20 AM by Nick Gammon
USA #6
Thanks Nick.
Redid trigger and it is working.
Here is code. Took me a while to digest all you taught me. Working mostly trying to do the wait timer thing so that it casts spell once. Changes IsHungry Variable from yes to no and stops.

But here it is.


<triggers>
  <trigger
   enabled="y"
   expand_variables="y"
   group="Prompt"
   match="&lt;*/*Hp */*Ma */*Mv AC:* Continent:* Weather:*&gt;"
   send_to="12"
   sequence="100"
  >
  <send>SetVariable("CHp","%1")
SetVariable("MHp","%2")
SetVariable("CMa","%3")
SetVariable("MMa","%4")
SetVariable("CMv","%5")
SetVariable("MMv","%6")
SetVariable("AC","%7")
SetVariable("Continent","%8")
SetVariable("IndoorsOutdoors","%9")


CHp=GetVariable("CHp")
MHp=GetVariable("MHp")
CMa=GetVariable("CMa")
MMa=GetVariable("MMa")
CMv=GetVariable("CMv")
MMv=GetVariable("MMv")
AC=GetVariable("AC")
Continent=GetVariable("Continent")
IndoorsOutdoors=GetVariable("IndoorsOutdoors")

IndoorsOutdoors=GetVariable("IndoorsOutdoors")
IsFighting=GetVariable("IsFighting")
IsHungry=GetVariable("IsHungry")
IsRelaxing=GetVariable("IsRelaxing")
IsSleep=GetVariable("IsSleep")
IsStanding=GetVariable("IsStanding")
IsThirsty=GetVariable("IsThirsty")
Location=GetVariable("Location")
StoneSkin=GetVariable("StoneSkin")
Target=GetVariable("Target")
Trackie=GetVariable("Trackie")


if IndoorsOutdoors == "indoors" then
SetVariable("IndoorsOutdoors","Indoors")
IndoorsOutdoors ="Indoors"
else
SetVariable("IndoorsOutdoors","Outdoors")
IndoorsOutdoors ="Outdoors"
end--if


if IsHungry == "Yes" then
Send("|")
Send("cast 'create food'")
Send("get food")
Send("eat food")
end--if

if StoneSkin == "Off" then
Send("|")
Send("cast 'stone skin'")
end--if

if IsThirsty == "Yes" then
Send("|")
Send("get barrel mass")
Send("drink barrel")
Send("cast 'create water' barrel")
end--if
</send>
  </trigger>
</triggers>



So far from what I see nothing is wrong.
Amended on Wed 19 Oct 2011 07:59 AM by Warbit
Australia Forum Administrator #7
So is this a question, or are you saying it is all working fine?
USA #8
No question, Well not with what I have. Right now I am trying to get the IsHungry to fire only once now.

I am monkeying with your wait.time function. Hoping that will fix it. Didn't expect such a quick response. So no question yet want to mess with it some more, before I ask. Thought the above was working perfectly until I got hungry.

Ok yes i do have question.

I think problem is that even thought I have trigger set to switch IsHungry from Yes to No. My script seems to me firing 3 or more times .

Here are all my Triggers
Mud tells me I am Hungry. So I made trigger Set Variable IsHungry to Yes.

<triggers>
  <trigger
   enabled="y"
   expand_variables="y"
   group="FoodandWater"
   match="*You are hungry.*"
   send_to="12"
   sequence="100"
  >
  <send>SetVariable("IsHungry","Yes")
IsHungry = "Yes"</send>
  </trigger>
</triggers>


Prompt Sees IsHungry is Yes
So it
casts create food spell
gets food
and i eat food.
I added wait 21 seconds in hopes that it would give propmpt time to see that ISHungry is Now No. That will come from trigger after prompt trigger.

This is current Prompt trigger.

<triggers>
  <trigger
   enabled="y"
   expand_variables="y"
   group="Prompt"
   match="&lt;*/*Hp */*Ma */*Mv AC:* Continent:* Weather:*&gt;"
   send_to="12"
   sequence="100"
  >
  <send>

SetVariable("CHp","%1")
SetVariable("MHp","%2")
SetVariable("CMa","%3")
SetVariable("MMa","%4")
SetVariable("CMv","%5")
SetVariable("MMv","%6")
SetVariable("AC","%7")
SetVariable("Continent","%8")
SetVariable("IndoorsOutdoors","%9")


CHp=GetVariable("CHp")
MHp=GetVariable("MHp")
CMa=GetVariable("CMa")
MMa=GetVariable("MMa")
CMv=GetVariable("CMv")
MMv=GetVariable("MMv")
AC=GetVariable("AC")
Continent=GetVariable("Continent")
IndoorsOutdoors=GetVariable("IndoorsOutdoors")

IndoorsOutdoors=GetVariable("IndoorsOutdoors")
IsFighting=GetVariable("IsFighting")
IsHungry=GetVariable("IsHungry")
IsRelaxing=GetVariable("IsRelaxing")
IsSleep=GetVariable("IsSleep")
IsStanding=GetVariable("IsStanding")
IsThirsty=GetVariable("IsThirsty")
Location=GetVariable("Location")
StoneSkin=GetVariable("StoneSkin")
Target=GetVariable("Target")
Trackie=GetVariable("Trackie")


if IndoorsOutdoors == "indoors" then
SetVariable("IndoorsOutdoors","Indoors")
IndoorsOutdoors ="Indoors"
else
SetVariable("IndoorsOutdoors","Outdoors")
IndoorsOutdoors ="Outdoors"
end--if


if IsHungry == "Yes" then
require "wait"
wait.make (function ()
wait.time (21)
Send("|")
Send("cast 'create food'")
Send("get food")
Send("eat food")
end)
end--if

if StoneSkin == "Off" and CMa&gt;25  then
Send("|")
Send("cast 'stone skin'")
end--if

if IsThirsty == "Yes" then
require "wait"
wait.make (function ()
wait.time (21)
Send("|")
Send("get barrel mass")
Send("drink barrel")
Send("cast 'create water' barrel")
end)
end--if
</send>
  </trigger>
</triggers>


After I eat Mud tell me I am no longer hungry.
So I want to make IsHungry equal to No.
Here is No longer hungry trigger.

<triggers>
  <trigger
   enabled="y"
   expand_variables="y"
   group="FoodandWater"
   match="*You are no longer hungry.*"
   send_to="12"
   sequence="100"
  >
  <send>SetVariable("IsHungry","No")
IsHungry=GetVariable("IsHungry")
IsHungry = "No"
</send>
  </trigger>
</triggers>


I have compare string to number error in prompt trigger but I will fix that later.


Amended on Wed 19 Oct 2011 08:19 AM by Warbit
USA #9
Sorry Physical Appearance of my prompt is.

<481/578Hp 97/104Ma 331/331Mv AC:-7.3 Continent:Vk Weather:overcast>



Send("|")

Sends command to mud to clear buffer of all previous commands.
Amended on Wed 19 Oct 2011 08:28 AM by Warbit
USA #10
I know easy way is to make trigger that fires on the words you are hungry. But I am mostly interested in learning to use variables.
Australia Forum Administrator #11
I don't understand what you are doing here:


if IndoorsOutdoors == "indoors" then
  SetVariable("IndoorsOutdoors","Indoors")
  IndoorsOutdoors ="Indoors"
else
  SetVariable("IndoorsOutdoors","Outdoors")
  IndoorsOutdoors ="Outdoors"
end--if


You are setting two types of variables everywhere - MUSHclient variables, and Lua variables. How about deciding which one you want to use and stick with that? This is just making your code twice as long and twice as confusing.

See this, it explains the difference:

http://www.gammon.com.au/forum/?id=10863
Australia Forum Administrator #12
I got your trigger to match (fire) - providing there is nothing else on the line. If you have something after the prompt, you may want to put in a trailing asterisk.
USA #13
Thanks Nick re watched video and it was big help.
Then I added HpNeeded = MHp - CHp

kept getting expected '=' near HpNeeded

Went through script and it was a capital IF instead of small if

fixed that.

Then I got trying to do math with nil value. So tried the SetVariable(GetVariable isnumber)) thing you showed me in wholist counter minus or zero thing.

Didn't work. So I tried to convert my trigget to regular expression. Like you showed on one of your forumn pages when you was naming wildcards and and changing wildcards from stings to decimals.

Summary How do I convert this:

<578/578Hp 104/104Ma 331/331Mv AC:-4.3 Continent:Vk Weather:overcast>

So that the wildcards I get are

<(Digit wildcard)/(Digit wildcard)Hp (Digit wildcard)/(Digit wildcard)Ma (Digit wildcard)/(Digit wildcard)Mv AC:(Signed Decimal wildcard) Continent:* Weather:*>

Using Regualar Expression.

Question
1. What is correct syntax for regular expression of prompt above.
2. Looking for Link to your tutorial showing how to do so, also. For reference.

Here is my attempt and it doesn't do anything now unfortunately. If I figure it out before you answer I will delete this.


<triggers>
  <trigger
   enabled="y"
   expand_variables="y"
   group="Prompt"
   match="^\&lt;(\D)\/(\D)Hp (\D)\/(\D)Ma (\D)\/(\D)Mv AC\:([0-9+-]) Continent\:(.*?) Weather\:(.*?)\&gt;$"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>Chp = %1
MHp = %2 
CMa = %3
MMa = %4
CMv = %5
MMv = %6




Hpneeded = MHp - CHp

if %7&gt;-5 then
Send("|")
Send("cast 'stone skin'")
end--if

if IsHungry =="Yes" then
Send("cast 'create food'")
Send("get food")
Send("get food mass")
Send("eat food")
end--if

if IsThirsty =="Yes" then
Send("get barrel mass")
Send("drink barrel")
Send("cast 'create water' barrel")
end--if



if HpNeeded&gt;16 and CMa&gt;16 then
Send("cast 'cure minor'")
end--if

if MyHpNeeded &gt; 77 and CMa&gt; 77 then
Send("cast 'cure normal'")
end--if</send>
  </trigger>
</triggers>


Here is link I used trying to get it right.
http://www.gammon.com.au/forum/?id=5089

USA #14
Ok Found your example.
The link is Here.
http://www.gammon.com.au/forum/?id=6030

OK added + signs
Still not firing.

<triggers>
  <trigger
   enabled="y"
   expand_variables="y"
   group="Prompt"
   match="^\&lt;(\D+)\/(\D+)Hp (\D+)\/(\D+)Ma (\D+)\/(\D+)Mv AC\:([0-9+-]) Continent\:(.*?) Weather\:(.*?)\&gt;$"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>Chp = %1
MHp = %2 
CMa = %3
MMa = %4
CMv = %5
MMv = %6




Hpneeded = MHp - CHp

if %7&gt;-5 then
Send("|")
Send("cast 'stone skin'")
end--if

if IsHungry =="Yes" then
Send("cast 'create food'")
Send("get food")
Send("get food mass")
Send("eat food")
end--if

if IsThirsty =="Yes" then
Send("get barrel mass")
Send("drink barrel")
Send("cast 'create water' barrel")
end--if



if HpNeeded&gt;16 and CMa&gt;16 then
Send("cast 'cure minor'")
end--if

if MyHpNeeded &gt; 77 and CMa&gt; 77 then
Send("cast 'cure normal'")
end--if</send>
  </trigger>
</triggers>

Amended on Thu 20 Oct 2011 07:06 AM by Warbit
Australia Forum Administrator #15
Get the capitalization right. \d is a digit \D is not a digit.
USA #16
Ok fix capitalization.
deleted MY from MyHpNeeded.
So both if statements are HpNeeded


<triggers>
  <trigger
   enabled="y"
   expand_variables="y"
   group="Prompt"
   match="^\&lt;(\d+)\/(\d+)Hp (\d+)\/(\d+)Ma (\d+)\/(\d+)Mv AC\:([0-9+-]) Continent\:(.*?) Weather\:(.*?)\&gt;$"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>Chp = %1
MHp = %2 
CMa = %3
MMa = %4
CMv = %5
MMv = %6




Hpneeded = MHp - CHp

if %7&gt;-5 then
Send("|")
Send("cast 'stone skin'")
end--if

if IsHungry =="Yes" then
Send("cast 'create food'")
Send("get food")
Send("get food mass")
Send("eat food")
end--if

if IsThirsty =="Yes" then
Send("get barrel mass")
Send("drink barrel")
Send("cast 'create water' barrel")
end--if



if HpNeeded&gt;16 and CMa&gt;16 then
Send("cast 'cure minor'")
end--if

if HpNeeded &gt; 77 and CMa&gt; 77 then
Send("cast 'cure normal'")
end--if</send>
  </trigger>
</triggers>


Still not firing.

Found and corrected Capitalization error, in Hpneeded
changed to HpNeeded

Current Trigger still not firing.

<triggers>
  <trigger
   enabled="y"
   expand_variables="y"
   group="Prompt"
   match="^\&lt;(\d+)\/(\d+)Hp (\d+)\/(\d+)Ma (\d+)\/(\d+)Mv AC\:([0-9+-]) Continent\:(.*?) Weather\:(.*?)\&gt;$"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>Chp = %1
MHp = %2 
CMa = %3
MMa = %4
CMv = %5
MMv = %6




HpNeeded = MHp - CHp

if %7&gt;-5 then
Send("|")
Send("cast 'stone skin'")
end--if

if IsHungry =="Yes" then
Send("cast 'create food'")
Send("get food")
Send("get food mass")
Send("eat food")
end--if

if IsThirsty =="Yes" then
Send("get barrel mass")
Send("drink barrel")
Send("cast 'create water' barrel")
end--if



if HpNeeded&gt;16 and CMa&gt;16 then
Send("cast 'cure minor'")
end--if

if HpNeeded &gt; 77 and CMa&gt; 77 then
Send("cast 'cure normal'")
end--if</send>
  </trigger>
</triggers>

Amended on Thu 20 Oct 2011 07:32 AM by Warbit
Australia Forum Administrator #17
Under AC you forgot to allow for the decimal point, plus you have to have "one or more" (a + sign) after it. This fires:


<triggers>
  <trigger
   enabled="y"
   expand_variables="y"
   group="Prompt"
   match="^\&lt;(\d+)\/(\d+)Hp (\d+)\/(\d+)Ma (\d+)\/(\d+)Mv AC\:([0-9+\-\.]+) Continent\:(.*?) Weather\:(.*?)\&gt;$"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>Chp = %1
MHp = %2 
CMa = %3
MMa = %4
CMv = %5
MMv = %6




HpNeeded = MHp - CHp

if %7&gt;-5 then
Send("|")
Send("cast 'stone skin'")
end--if

if IsHungry =="Yes" then
Send("cast 'create food'")
Send("get food")
Send("get food mass")
Send("eat food")
end--if

if IsThirsty =="Yes" then
Send("get barrel mass")
Send("drink barrel")
Send("cast 'create water' barrel")
end--if



if HpNeeded&gt;16 and CMa&gt;16 then
Send("cast 'cure minor'")
end--if

if HpNeeded &gt; 77 and CMa&gt; 77 then
Send("cast 'cure normal'")
end--if</send>
  </trigger>
</triggers>
Amended on Thu 20 Oct 2011 08:21 AM by Nick Gammon
USA #18
Thanks Nick for rewrite but am getting this error.


Error number: 0
Event:        Run-time error
Description:  [string "Trigger: "]:11: attempt to perform arithmetic on global 'CHp' (a nil value)

stack traceback:

	[string "Trigger: "]:11: in main chunk
Called by:    Immediate execution

Australia Forum Administrator #19
I got that too, but at least the trigger matched.

As to why, get the capitalization right, as I said before. Check the way you spelt that variable in two places.
USA #20
Ahhh !!! First CHp is wrong too.

<triggers>
  <trigger
   enabled="y"
   expand_variables="y"
   group="Prompt"
   match="^\&lt;(\d+)\/(\d+)Hp (\d+)\/(\d+)Ma (\d+)\/(\d+)Mv AC\:([0-9+\-\.]+) Continent\:(.*?) Weather\:(.*?)\&gt;$"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>CHp = %1
MHp = %2 
CMa = %3
MMa = %4
CMv = %5
MMv = %6




HpNeeded = MHp - CHp

if %7&gt;-5 then
Send("|")
Send("cast 'stone skin'")
end--if

if IsHungry =="Yes" then
Send("cast 'create food'")
Send("get food")
Send("get food mass")
Send("eat food")
end--if

if IsThirsty =="Yes" then
Send("get barrel mass")
Send("drink barrel")
Send("cast 'create water' barrel")
end--if



if HpNeeded&gt;16 and CMa&gt;16 then
Send("cast 'cure minor'")
end--if

if HpNeeded &gt; 77 and CMa&gt; 77 then
Send("cast 'cure normal'")
end--if</send>
  </trigger>
</triggers>

re-enabled so far no errors. but will need to remove work arounds. To see if it works.
Australia Forum Administrator #21
I would start indenting a bit, it makes it easier to debug. Also have you heard of multi-line literals? Instead of:


if IsHungry =="Yes" then
Send("cast 'create food'")
Send("get food")
Send("get food mass")
Send("eat food")
end--if


You can (if you wish) do:


if IsHungry == "Yes" then
Send([[
cast 'create food'
get food
get food mass
eat food]])
end--if
USA #22
AHHH Cool !!!
No never heard of it, but I will definitely use it.

Also I believe Trigger works perfectly!!! Thanks again for all your time and help. I will start indenting too. I did not know language would allow me to.

I know I will break prompt trigger again since I want to do so much more with it. It seems the perfect place to place, most of my character's future functionality.

I also plan on trying to tackle your tables tutorials. But that is a problem for a different thread. Thanks again Nick!