Trouble with a plugin targeting alias

Posted by Metsuro on Wed 20 Oct 2004 01:50 AM — 8 posts, 31,492 views.

USA #0
Well I made a targeting system. Along with a few other things.

<?xml version="1.0" encoding="iso-8859-1" ?>
<!DOCTYPE muclient (View Source for full doctype...)>
- <!-- Saved on Tuesday, October 19, 2004, 9:20 PM
-->
- <!-- MuClient version 3.50
-->
- <!-- Plugin "KnightsHeaven" generated by Plugin Wizard
-->
- <muclient>
<plugin name="KnightsHeaven" author="Kotetsu" id="cb0d7d383ccf120351a6f4b7" language="VBscript" purpose="Knightly Defense" save_state="y" date_written="2004-10-19 21:19:38" requires="3.50" version="1.0" />
- <!-- Get our standard constants
-->
<include name="constants.vbs" />
- <!-- Triggers
-->
- <triggers>
- <trigger enabled="y" match="*. 'OK' to commence the lesson." sequence="100">
<send>ok</send>
</trigger>
<trigger match="^(\d+)h, (\d+)m, (\d+)e, (\d+)p (\D{0,7})*\-$" regexp="y" sequence="100" />
<trigger custom_colour="5" enabled="y" expand_variables="y" ignore_case="y" keep_evaluating="y" match="(@!friendlist)" regexp="y" repeat="y" sequence="100" />
<trigger enabled="y" match="You are in the Prime Material Plane." sequence="100" />
<trigger custom_colour="11" enabled="y" group="BattleInfo" match="You have recovered balance on all limbs." sequence="100" />
<trigger custom_colour="11" enabled="y" group="BattleInfo" match="You have recovered balance on your * arm." sequence="100" />
<trigger custom_colour="11" enabled="y" group="BattleInfo" match="You have recovered equilibrium." sequence="100" />
- <trigger enabled="y" match="'OK' to commence the lesson." sequence="100">
<send>ok</send>
</trigger>
</triggers>
- <!-- Aliases
-->
- <aliases>
- <alias match="fadd *" enabled="y" send_to="12" sequence="100">
<send>SetVariable "friendlist", getvariable("friendlist") & "|%1"</send>
</alias>
- <alias match="swing" enabled="y" expand_variables="y" sequence="100">
<send>swing @target</send>
</alias>
- <alias script="OnTarget" match="x *" enabled="y" send_to="12" sequence="100">
<send>world.ColourNote "limegreen", "black", "%1 is now Targeted"</send>
</alias>
</aliases>
- <!-- Timers
-->
- <timers>
- <timer enabled="y" second="2" send_to="12">
<send>world.InfoClear world.InfoBackground "black" world.InfoColour "red" world.InfoFont "FixedSys", 12, 1 world.Info " Target: " & getvariable("target") & " |"</send>
</timer>
</timers>
- <!-- Variables
-->
- <variables>
<variable name="target">rat</variable>
<variable name="friendlist">|Metsuro</variable>
</variables>
- <!-- Script
-->
- <script>
- <![CDATA[
sub OnTarget (strTriggerName, trig_line, arrWildCards)
world.setvariable "target", arrWildcards (1)
target = arrWildcards (1)
end sub


]]>
</script>
</muclient>

Thats the plugin in and i get this error

scripting error
error number -2146827788
Event Execution of line 135 column 3
description Variable is undefined: 'target'
Called by Function/Sub: OnTarget called by alias

Not sure how to fix it, any help would be nice
#1
For every scripting variable, you need to define them before you try to put something in them.


For instence, instead of

Quote:
sub OnTarget (strTriggerName, trig_line, arrWildCards)
  world.setvariable "target", arrWildcards (1)
  target = arrWildcards (1)
end sub


You should have


Quote:
Dim target
sub OnTarget (strTriggerName, trig_line, arrWildCards)
  world.setvariable "target", arrWildcards (1)
  target = arrWildcards (1)
end sub


When you do that, it tells the intepreter or whatever that Hey, we have a variable called target now. Then you can put stuff in it

I don't know how it works exactly, but if I'm wrong could someone lemme know? :p
Greece #2
VBScript doesn't require you to declare variables. Maybe something is messing with the include file? Try to change the name to strTarget or something like that and see what happens.
USA #3
Why dont you just put that sub in the alias? That alias is already sending to script, and youre not reusing it.

And why are you setting a vbscript variable "target"?

And you dont need that include file anyway, I cant imagine it'd cause problems though.
USA #4
The way i have it set up when you do "x rat" is sends the world a note saying that and then i have a timer to display on info, and I couldn't find another way to work it.
USA #5
You never use the VBScript variable "trigger" though.

Youre using the MC variable trigger (using getvariable).

Which you can set with the alias using:
setvariable "target, "%1"
put that before (or after) your note about the target being set.

Then you dont need to worry about the script. Which is extraneous anyway.
Australia Forum Administrator #6
Quote:

VBScript doesn't require you to declare variables.


Unless you have:


option explicit


Then it does. That line is in some of the supplied files (eg. exampscript.vbs).

However, this is too complicated:

Quote:


sub OnTarget (strTriggerName, trig_line, arrWildCards)
  world.setvariable "target", arrWildcards (1)
  target = arrWildcards (1)
end sub



You don't need the line "target = arrWildcards (1)" at all, and since you don't need it, you don't need to declare it.

Having got that far, just set the trigger to "send to variable", and put %1 in the "send" field. Then you don't need any scripting at all.

USA #7
He wants to have a note on the world as well.

So he just has to add the setvariable line to his trigger (which is already send to script).