trying my hand at building a trigger in C

Posted by Dragonlord on Sat 02 Apr 2016 06:19 PM — 9 posts, 28,000 views.

#0
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>
Amended on Sun 03 Apr 2016 10:10 AM by Nick Gammon
USA Global Moderator #1
April 1 was yesterday.
#2
I am asking a serious question
USA Global Moderator #3
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.
Australia Forum Administrator #4
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.
Australia Forum Administrator #5
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
#6
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>
Australia Forum Administrator #7

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


Your brackets are in the wrong place there. utils.split takes two arguments, not three.
USA Global Moderator #8
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?