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

Gammon Forum

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

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  General
. . -> [Subject]  trying my hand at building a trigger in C
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

trying my hand at building a trigger in C

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Posted by Dragonlord   (24 posts)  [Biography] bio
Date Sat 02 Apr 2016 06:19 PM (UTC)

Amended on Sun 03 Apr 2016 10:10 AM (UTC) by Nick Gammon

Message
I am trying my hand at C programming, because it has a Switch - Case statements but seem to run into an issue here. what I am trying to do is take reagents: G_Reagent = {reagent-water, reagent-fire, reagent-air, reagent-earth, gem, reagent-ethereal} and it have so when my bag is full with one of the reagents but not the other type it will ignore trying to fill that container. I hope that I am making sense.


<triggers>
  <trigger
   enabled="y"
   group="(reagents)"
   ignore_case="y"
   keep_evaluating="y"
   match="Your Vandemaar's Reagent Bag glows white as it accumulates possessions from the ether."
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>Send ("open itemg")
Send ("get all itemg")
Send ("close itemg")
switch(G_Reagent) { 
  case "reagent-air" 
    Send ("put all\.", G_Reagent, " airreagents");
    Break;
  case "reagent-earth"
    Send ("put all\.", G_Reagent, " earthreagents");
    Break;
  case "reagent-water" 
    Send ("put all\.", G_Reagent, " waterreagents");
    Break;
  case "reagent-fire" 
    Send ("put all\.", G_Reagent, " firereagents");
    Break;
  case "gem" 
    Send ("put all\.", G_Reagent, " gemreagents");
    Break;
  case "reagent-ethereal" 
    Send ("put all\.", G_Reagent, " etherealreagents");
    Break;
}</send>
  </trigger>
</triggers>
[Go to top] top

Posted by Fiendish   USA  (1,641 posts)  [Biography] bio   Global Moderator
Date Reply #1 on Sat 02 Apr 2016 06:40 PM (UTC)
Message
April 1 was yesterday.

https://github.com/fiendish/aardwolfclientpackage
[Go to top] top

Posted by Dragonlord   (24 posts)  [Biography] bio
Date Reply #2 on Sat 02 Apr 2016 07:00 PM (UTC)
Message
I am asking a serious question
[Go to top] top

Posted by Fiendish   USA  (1,641 posts)  [Biography] bio   Global Moderator
Date Reply #3 on Sat 02 Apr 2016 07:06 PM (UTC)
Message
Dragonlord said:

I am asking a serious question

Oh. Ok, then the answer is that you can't make triggers with C because C is not one of the languages that MUSHclient understands.

Also, there's nothing special about switch/case that you can't just as easily do with if/elseif/else.

https://github.com/fiendish/aardwolfclientpackage
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #4 on Sun 03 Apr 2016 10:11 AM (UTC)
Message
It would be very simple in Lua to make a lookup table that converts (say) "reagent-air" into "airreagents" - and ditto for all the others you have there.

- Nick Gammon

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

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #5 on Sun 03 Apr 2016 10:15 AM (UTC)
Message
Or even do it with a regular expression:


G_Reagent = "reagent-air"   -- testing

whichReagent = string.match (G_Reagent, "^reagent%-(%a+)$")

if whichReagent then
  Send ("put all\.", G_Reagent, " " .. whichReagent .. "reagents")
end -- if

- Nick Gammon

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

Posted by Dragonlord   (24 posts)  [Biography] bio
Date Reply #6 on Sun 03 Apr 2016 09:52 PM (UTC)
Message
thank you it worked to a point. I ran into an issue with - reagent-water|reagent-fire|reagent-air|reagent-earth|gem|reagent-ethereal - so I tried to add utils.split (G_Reagent, "|" into the line to help with splitting and ran into an error

Run-time error
World: Materia Magica GMCP
Immediate execution
[string "Alias: G_Reagent_items"]:7: bad argument #3 to 'split' (number expected, got string)
stack traceback:
[C]: in function 'split'
[string "Alias: G_Reagent_items"]:7: in main chunk

Any ideal on what I did wrong?

<aliases>
<alias
name="G_Reagent_items"
match="G_Reagent_items"
enabled="y"
group="G_Reagent_items"
send_to="12"
ignore_case="y"
sequence="100"
>
<send>G_Reagent = "reagent-water|reagent-fire|reagent-air|reagent-earth|gem|reagent-ethereal"

Send ("open itemg")
Send ("get all\.", G_Reagent, " itemg")
Send ("close itemg")

whichReagent = string.match (utils.split (G_Reagent, "|", "^reagent%-(%a+)$"))

if whichReagent then
Send ("put all\.", G_Reagent, " " .. whichReagent .. "airreagents")
elseif whichReagent then
Send ("put all\.", G_Reagent, " " .. whichReagent .. "earthreagents")
elseif whichReagent then
Send ("put all\.", G_Reagent, " " .. whichReagent .. "waterreagents")
elseif whichReagent then
Send ("put all\.", G_Reagent, " " .. whichReagent .. "firereagents")
elseif whichReagent then
Send ("put all\.", G_Reagent, " " .. whichReagent .. "gemreagents")
elseif whichReagent then
Send ("put all\.", G_Reagent, " " .. whichReagent .. "etherealreagents")
else
Send ("drop all\.", G_Reagent)
end -- if</send>
</alias>
</aliases>
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #7 on Mon 04 Apr 2016 05:28 AM (UTC)
Message

 whichReagent = string.match (utils.split (G_Reagent, "|", "^reagent%-(%a+)$"))


Your brackets are in the wrong place there. utils.split takes two arguments, not three.

- Nick Gammon

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

Posted by Fiendish   USA  (1,641 posts)  [Biography] bio   Global Moderator
Date Reply #8 on Mon 04 Apr 2016 10:49 AM (UTC)

Amended on Mon 04 Apr 2016 10:50 AM (UTC) by Fiendish

Message
Back this thread up a little bit. Whatever you are trying to do, I have a very hard time seeing how your code (broken or otherwise) will accomplish it. Can you please explain what you're trying to do again step by step?

https://github.com/fiendish/aardwolfclientpackage
[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.


2,925 views.

It is now over 60 days since the last post. This thread is closed.     [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.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

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

[Best viewed with any browser - 2K]    [Hosted at FutureQuest]