[Home] [Downloads] [Search] [Help/forum]

Gammon Software Solutions forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Lua
. . -> [Subject]  Prompt Trigger Problems
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?
(New message)
Subject: Prompt Trigger Problems
Name:
Your forum user name.
Register forum user name
Password:
Your forum password.
Forgotten password?
Message:
Message to be posted (in English, please)
Maximum of 6000 characters. Text only please, no HTML.
Forum codes:
Check this if your message uses 'forum codes' or templates (auto-detected for new posts).
Forum codes Templates

Save this message ...


Subject review (reverse sequence)

Pages: 1 2  

Posted by Warbit   USA  (47 posts)  [Biography] bio
Date Thu 20 Oct 2011 09:44 PM (UTC)  quote  ]
Message
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!
[Go to top] top

Posted by Nick Gammon   Australia  (19,537 posts)  [Biography] bio   Forum Administrator
Date Thu 20 Oct 2011 08:33 PM (UTC)  quote  ]
Message
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

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Warbit   USA  (47 posts)  [Biography] bio
Date Thu 20 Oct 2011 11:35 AM (UTC)  quote  ]
Message
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.
[Go to top] top

Posted by Nick Gammon   Australia  (19,537 posts)  [Biography] bio   Forum Administrator
Date Thu 20 Oct 2011 11:00 AM (UTC)  quote  ]
Message
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.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Warbit   USA  (47 posts)  [Biography] bio
Date Thu 20 Oct 2011 08:37 AM (UTC)  quote  ]
Message
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

[Go to top] top

Posted by Nick Gammon   Australia  (19,537 posts)  [Biography] bio   Forum Administrator
Date Thu 20 Oct 2011 08:20 AM (UTC)  quote  ]

Amended on Thu 20 Oct 2011 08:21 AM (UTC) by Nick Gammon

Message
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>

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Warbit   USA  (47 posts)  [Biography] bio
Date Thu 20 Oct 2011 07:28 AM (UTC)  quote  ]

Amended on Thu 20 Oct 2011 07:32 AM (UTC) by Warbit

Message
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>

[Go to top] top

Posted by Nick Gammon   Australia  (19,537 posts)  [Biography] bio   Forum Administrator
Date Thu 20 Oct 2011 07:20 AM (UTC)  quote  ]
Message
Get the capitalization right. \d is a digit \D is not a digit.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Warbit   USA  (47 posts)  [Biography] bio
Date Thu 20 Oct 2011 07:00 AM (UTC)  quote  ]

Amended on Thu 20 Oct 2011 07:06 AM (UTC) by Warbit

Message
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>

[Go to top] top

Posted by Warbit   USA  (47 posts)  [Biography] bio
Date Thu 20 Oct 2011 06:58 AM (UTC)  quote  ]
Message
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

[Go to top] top

Posted by Nick Gammon   Australia  (19,537 posts)  [Biography] bio   Forum Administrator
Date Thu 20 Oct 2011 12:29 AM (UTC)  quote  ]
Message
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.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Nick Gammon   Australia  (19,537 posts)  [Biography] bio   Forum Administrator
Date Wed 19 Oct 2011 08:34 PM (UTC)  quote  ]
Message
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

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Warbit   USA  (47 posts)  [Biography] bio
Date Wed 19 Oct 2011 08:33 AM (UTC)  quote  ]
Message
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.
[Go to top] top

Posted by Warbit   USA  (47 posts)  [Biography] bio
Date Wed 19 Oct 2011 08:26 AM (UTC)  quote  ]

Amended on Wed 19 Oct 2011 08:28 AM (UTC) by Warbit

Message
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.
[Go to top] top

Posted by Warbit   USA  (47 posts)  [Biography] bio
Date Wed 19 Oct 2011 08:02 AM (UTC)  quote  ]

Amended on Wed 19 Oct 2011 08:19 AM (UTC) by Warbit

Message
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.


[Go to top] top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


4,178 views.

This is page 1, subject is 2 pages long: 1 2  [Next page]

It is now over 60 days since the last post. This thread is closed.   [New subject]  Start a new subject   [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

[Home]

Written by Nick Gammon - 5K

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( http://www.gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Web site powered by FutureQuest.Net]