missing sub help please

Posted by Perrin on Sat 27 Nov 2010 07:33 AM — 19 posts, 91,279 views.

USA #0
  <alias
   match="spellup"
   enabled="y"
   group="aces"
   script="BuffOut"
   send_to="12"
   sequence="100"
  >
  <send> Sub BuffOut ()
dim setting
setting = world.getvariable ("prompt")
if setting = ("2") then world.execute "prompt;flex" else world.execute "flex"
end if
end sub</send>
  </alias>


This is small chunk of MUCH larger script the variable is valid and does savestate, but on install I receive this.

You have not specified a script file name:
The alias subroutine named "BuffOut" could not be found.

All help is greatly appreciated.
USA #1
That's because the <send> content isn't evaluated until the trigger matches. Further, it's evaluated every time the trigger matches, which means it's likely you'd get an error about redefining a sub after the second time it matches. Use this instead:

  <alias
   match="spellup"
   enabled="y"
   group="aces"
   send_to="12"
   sequence="100"
  >
  <send>dim setting
setting = world.getvariable ("prompt")
if setting = ("2") then world.execute "prompt;flex" else world.execute "flex"
end if</send>
  </alias>


The "script" attribute/field is only used to reference a function/sub defined elsewhere, most often in the script file (or <script> section of a plugin), where it's already been defined. For normal scripts embedded into an alias/trigger/timer, just put the code you want to execute in the send field.
Amended on Sat 27 Nov 2010 07:50 AM by Twisol
USA #2
ok did that now returns:


Script error
Plugin: aardspellup (called from world: aardwolfmud)
Execution of line 4 column 1
Immediate execution
Expected statement
Line in error:
end if
USA #3
Hmm. I'm not really an expert on VBscript, but try fixing the indentation.

  <alias
   match="spellup"
   enabled="y"
   group="aces"
   send_to="12"
   sequence="100"
  >
  <send>dim setting
setting = world.getvariable ("prompt")
if setting = "2" then
  world.execute "prompt;flex"
else
  world.execute "flex"
end if</send>
  </alias>
USA #4
Ah, yeah. If you look here \[1], you can see that there are two syntaxes for if-else-then. It explains that it decides which one you're using by looking at what comes after "then". In this case, it was expecting the single-line version, so the "end if" you added was invalid. I'd stick with the block syntax (what I posted) because it's easier to read and maintain though.

\[1] http://msdn.microsoft.com/en-us/library/5h27x7e9.aspx
USA #5
Thank you a ton now on to a slightly more complex problem.
I am trying to have a plugin expand itself and not quite sure them problem not receiving an error msg.
Here is the alias in question.

  <alias
   name="asa3"
   match="^(add trigger(s|)|addtrigger(s|))$"
   enabled="y"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>addtriggerex ""&amp;getvariable ("asv1")&amp;"3", ""&amp;getvariable ("asv4")&amp;"", 

"enabletrigger &amp;quot;"&amp;getvariable("asv1")&amp;"1&amp;quot;, 1", 1, -1, 0, "", "", 12, 100
addtriggerex ""&amp;getvariable ("asv1")&amp;"2", ""&amp;getvariable ("asv3")&amp;"", 

"world.enabletrigger &amp;quot;"&amp;getvariable("asv1")&amp;"1&amp;quot;, 1", 1, -1, 0, "", "", 

12, 100  
addtriggerex ""&amp;getvariable ("asv1")&amp;"1", "^You flex your muscles proudly\!$", "send 

&amp;quot;c "&amp;getvariable("asv2")&amp;"&amp;quot;", 1, -1, 0, "", "", 12, 100
addtriggerex ""&amp;getvariable ("asv1")&amp;"4", ""&amp;getvariable ("asv5")&amp;"", "send 

&amp;quot;c "&amp;getvariable("asv2")&amp;"&amp;quot;", 1, -1, 0, "", "", 12, 100  
enabletrigger "cancel", 0
</send>
  </alias>

USA #6
This is kind of nuts, you have weird XML bits in the code even after importing, like &amp;quot; becomes &quot;. Very odd, but I tried to fix it up.

<aliases>
  <alias
   name="asa3"
   match="^(add trigger(s|)|addtrigger(s|))$"
   enabled="y"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>addtriggerex getvariable ("asv1") &amp; "3", getvariable ("asv4"), "enabletrigger getvariable(""asv1"") &amp; ""1"", 1", 1, -1, 0, "", "", 12, 100
addtriggerex getvariable ("asv1") &amp; "2", getvariable ("asv3"), "world.enabletrigger getvariable(""asv1"") &amp; ""1"", 1", 1, -1, 0, "", "", 12, 100  
addtriggerex getvariable ("asv1") &amp; "1", "^You flex your muscles proudly\!$", "send ""c " &amp; getvariable("asv2") &amp; """", 1, -1, 0, "", "", 12, 100
addtriggerex getvariable ("asv1") &amp; "4", getvariable ("asv5"), "send ""c " &amp; getvariable("asv2") &amp; """", 1, -1, 0, "", "", 12, 100  

enabletrigger "cancel", 0
</send>
  </alias>
</aliases>


[EDIT]: Are you dead set on using VBscript? Lua is way easier to use in my opinion. I only bring it up because this looks insane. :D
Amended on Sat 27 Nov 2010 08:41 AM by Twisol
USA #7
Been thinking about it and, reading random forum posts.
Starting to look like i will have to use a exportXML
to save the triggers as variables and importXML them back.
but can't figure out how to export then import a large list

  <alias
   name="asa3"
   match="^(add trigger(s|)|addtrigger(s|))$"
   enabled="y"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>addtriggerex ""&amp;getvariable ("asv1")&amp;"3", ""&amp;getvariable ("asv4")&amp;"", 

"enabletrigger &amp;quot;"&amp;getvariable("asv1")&amp;"1&amp;quot;, 1", 1, -1, 0, "", "", 12, 100
addtriggerex ""&amp;getvariable ("asv1")&amp;"2", ""&amp;getvariable ("asv3")&amp;"", 
  
addtriggerex ""&amp;getvariable ("asv1")&amp;"1", "^You flex your muscles proudly\!$", "send 

&amp;quot;c "&amp;getvariable("asv2")&amp;"&amp;quot;", 1, -1, 0, "", "", 12, 100
addtriggerex ""&amp;getvariable ("asv1")&amp;"4", ""&amp;getvariable ("asv5")&amp;"", "send 

&amp;quot;c "&amp;getvariable("asv2")&amp;"&amp;quot;", 1, -1, 0, "", "", 12, 100  
exportxml (0, ""&amp;getvariable ("asv1")&amp;"1")
exportxml (0, ""&amp;getvariable ("asv1")&amp;"2")
exportxml (0, ""&amp;getvariable ("asv1")&amp;"3")
exportxml (0, ""&amp;getvariable ("asv1")&amp;"4")

enabletrigger &amp;quot;"&amp;getvariable("asv1")&amp;"1&amp;quot;, 1", 1, -1, 0, "", "", 12, 100
enabletrigger "cancel", 0
</send>
  </alias>

Is my best attempt.
USA #8
Did you try what I posted? What error occurred, if any?
USA #9
no error just no change to script or state
USA #10
&amp;quot: is a special entity for "
and &amp; is a special entity for &
thanks for that catch twisol

<send>addtriggerex ""&amp;getvariable ("asv1")&amp;"3", ""&amp;getvariable ("asv4")&amp;"", 

"enabletrigger &amp;quot;"&amp;getvariable("asv1")&amp;"1&amp;quot;, 1", 1, -1, 0, "", "", 12, 100
addtriggerex ""&amp;getvariable ("asv1")&amp;"2", ""&amp;getvariable ("asv3")&amp;"", 
  
addtriggerex ""&amp;getvariable ("asv1")&amp;"1", "^You flex your muscles proudly\!$", "send 

&amp;quot;c "&amp;getvariable("asv2")&amp;"&amp;quot;", 1, -1, 0, "", "", 12, 100
addtriggerex ""&amp;getvariable ("asv1")&amp;"4", ""&amp;getvariable ("asv5")&amp;"", "send 

&amp;quot;c "&amp;getvariable("asv2")&amp;"&amp;quot;", 1, -1, 0, "", "", 12, 100  


ok asuming the other triggers function correctly
and set values to the variables to

asv1="manna"
asv2="123"
asv3="you feel a surge of power."
asv4="you feel you extra power drain."
asv5="you fail at casting manna."

my code should output

<send>addtriggerex "manna3", "you feel a surge of power.", "enabletrigger "manna1", 1", 1, -1, 0, "", "", 12, 100

addtriggerex "manna1", "^You flex your muscles proudly\!$", "send "c 123"", 1, -1, 0, "", "", 12, 100

addtriggerex "manna4", "you fail at casting manna.", "send "c 123"", 1, -1, 0, "", "", 12, 100
Amended on Sat 27 Nov 2010 01:43 PM by Perrin
USA #11
Your translation is incorrect, unless you repeat on the same character every time. "&amp;quot;" actually translates to "&quot;", otherwise there would be no way to literally write "&quot;".

Did you check the triggers list after running the alias? When I used it, it added them. (Test it in the world aliases, not the plugin aliases, because there's no easy way to look at the list of triggers in a plugin like that.)
USA #12
yes tested trigger with world aliases and still cannot find created trigger

"check triggers" returns:
name 'manna' spellnum '123' spellon 'you feel a surge of power.' spelloff 'you feel you extra power drain.' spellfail 'you fail at casting manna.'

which is correct but "add triggers" doesn't seem to do anything
Amended on Sat 27 Nov 2010 02:30 PM by Perrin
Australia Forum Administrator #13
I'm completely confused about what you are trying to do here. First, the regexp:


^(add trigger(s|)|addtrigger(s|))$


For one optional letter, just put a question mark, eg.


^add ?triggers?$


That makes the space optional and the "s" optional.

And then inside the addtrigger alias you do this:


addtriggerex ""&getvariable ("asv1")&"3", ""&getvariable ("asv4")&"", 

"enabletrigger &quot;"&getvariable("asv1")&"1&quot;, 1", 1, -1, 0, "", "", 12, 100
addtriggerex ""&getvariable ("asv1")&"2", ""&getvariable ("asv3")&"", 
  
addtriggerex ""&getvariable ("asv1")&"1", "^You flex your muscles proudly\!$", "send 

&quot;c "&getvariable("asv2")&"&quot;", 1, -1, 0, "", "", 12, 100
addtriggerex ""&getvariable ("asv1")&"4", ""&getvariable ("asv5")&"", "send 

&quot;c "&getvariable("asv2")&"&quot;", 1, -1, 0, "", "", 12, 100  
exportxml (0, ""&getvariable ("asv1")&"1")
exportxml (0, ""&getvariable ("asv1")&"2")
exportxml (0, ""&getvariable ("asv1")&"3")
exportxml (0, ""&getvariable ("asv1")&"4")

enabletrigger &quot;"&getvariable("asv1")&"1&quot;, 1", 1, -1, 0, "", "", 12, 100
enabletrigger "cancel", 0


Whatever it is you are trying to achieve, this is not the way to do it. Honestly.

Perhaps if you explain what the real problem is - not "trying to add a heap of triggers".

Twisol said:

... there's no easy way to look at the list of triggers in a plugin like that ...


Load the "summary" plugin. Type "summary". That shows, amongst other things, your plugins. Next to each plugin is a link like [Tr] which, if you click on it will list that plugin's triggers. Then you can look at individual triggers.
USA #14
Nick Gammon said:
Load the "summary" plugin. Type "summary". That shows, amongst other things, your plugins. Next to each plugin is a link like [Tr] which, if you click on it will list that plugin's triggers. Then you can look at individual triggers.

Ack. I keep forgetting about that thing. :S
USA #15
Well then honestly nick the real problem is my proficiency
with scripting. I was attempting to make a spellup plugin that grows with the user without a large database using skill and lvl checks since muds evolve and spellmsgs change.


If what I am trying to do isn't really feasible. All I can do is drop the matter since it works fine for me if I move the problematic code to world aliases. Was just trying to make something cool for my friends.
Amended on Tue 30 Nov 2010 12:58 AM by Perrin
Australia Forum Administrator #16
It's feasible - I did a spellups plugin myself a while back.

But I think the idea of adding thousands of triggers (or aliases) isn't the way to do it. It just gets confusing.

I suspect that you are taking a tintin approach (or maybe you are used to another client) where you typically have a file which loads up lots of aliases from a big list.

Just as an example, say you were planning to do lots of spellups, and as each new spell was learnt you added a new alias, eg.


spellup heal
spellup major heal
spellup cure light
spellup cure heavy


Well personally, instead of adding dozens of aliases I would have one alias with a wildcard, eg.


spellup *


Then you look up the wildcard (ie. %1 in the alias send window) and see if you know that spell, and if so, cast it.

Then you just need a database (table) of spells you know, rather than a database of aliases. It's just simpler and easier to understand.
#17
Not sure if this thread is dead or how correct my assumptions are but seems to me Perrin is only using a few aliases in total and about 3-5 triggers per spell to track certain things such as:

the cast was successful, the affect is active, the affect wore off, the cast failed, and if the cast failed to recast.

Seems he is only using the alias in the original post to cause the enabled triggers to fire (only makes sense to me that way at least) instead of causing all the spells to cast. But i have no idea how to make the client add triggers to a plugin if that's what he's trying to do.

Nick didn't think he could use tables unless he switches to Lua.

Just trying to clarify something that was mentioned on the thread wouldn't &amp;quot; translate out to " since &quot; translates to " but don't really see a reason to use it unless for personal readability
Amended on Tue 24 Jul 2012 04:21 AM by Notaskixa
Australia Forum Administrator #18
The XML sequence &quot; will become a quote sign once that is imported into the client.