Similar to a recent question....

Posted by Tatewaki2365 on Thu 16 Dec 2004 01:38 AM — 17 posts, 69,848 views.

#0
I was wondering if there was a system of targetting - or, setting a target to complete an alias. As of now, I have this:

Alias: blind
Send: co 'blind'

But! This works only if in direct combat with the person. Now, if I'm CHASING the person, i'm outta luck, and have to type the whole string out (co 'blind' poor-victim) which ultimately takes time that I can't afford to waste. However, I was thinking that there would be a way to set it so that I could set a target (Or leave it blank for direct combat) so that when I'm chasing someone, I can type 'blind' and it will send [co 'blind' victim] - it would have to be easily toggled off (The target) though, because if I type 'blind' while in combat while I, myself, am blind, I'll get a message saying that I can't see that person (Or some such) and the effort is wasted, and I have to type it out anyway.
USA #1
This will do you, on both accounts. Well, targetting anyway. It also deals with optional arguements, but thats in the alias.

http://www.gammon.com.au/forum/bbshowpost.php?bbsubject_id=4695

To get the toggling going, you can simply make an alias to toggle the name off or on. Or you could have it trigger to a "you are blind" message, or some battle message, or something.
#2
That targetting system was... Incredibly confusing...
USA #3
Basically you set a variable (Mushclient variable) and then whenever you want to use it in a trigger/alias, you send @[variable] with 'expand variables' checked.

So, if you had a variable named "target" with the value of "victim", sending "cast blind @target" with expand variables checked would send "cast blind victim".

You can then use an alias to set the target variable.
Australia Forum Administrator #4
Here's an example. One alias "tar" sets the target. Use "tar none" to cancel it. The other casts blind using the variable "target" as the target ...


<aliases>
  <alias
   match="^tar (.*?)$"
   enabled="y"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>

if "%1" == "none" then
  SetVariable ("target", "")
  ColourNote ("white", "blue", "No current target")
else
  SetVariable ("target", "%1")
  ColourNote ("white", "blue", "Target is now %1")
end -- if

</send>
  </alias>
  <alias
   match="blind"
   enabled="y"
   expand_variables="y"
   sequence="100"
  >
  <send>co 'blind' @target</send>
  </alias>
</aliases>



The scripting is in Lua, but it is readily adaptable to other languages.
Amended on Thu 16 Dec 2004 02:48 AM by Nick Gammon
USA #5
Here it is in VB. Since Lua isn't exactly the friendliest language to new coders.


<aliases>
  <alias
   match="^tar (.*?)$"
   enabled="y"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>

if "%1" = "none" then
  SetVariable "target", ""
  ColourNote "white", "blue", "No current target"
else
  SetVariable "target", "%1"
  ColourNote "white", "blue", "Target is now %1"
end if

</send>
  </alias>
  <alias
   match="blind"
   enabled="y"
   expand_variables="y"
   sequence="100"
  >
  <send>co 'blind' @target</send>
  </alias>
</aliases>
Amended on Thu 16 Dec 2004 02:59 AM by Flannel
Australia Forum Administrator #6
Flannel, I don't think that there is much difference in friendliness between VB and Lua, especially in those examples:



Lua

if "%1" == "none" then
  SetVariable ("target", "")
  ColourNote ("white", "blue", "No current target")
else
  SetVariable ("target", "%1")
  ColourNote ("white", "blue", "Target is now %1")
end -- if




VB

if "%1" = "none" then
  SetVariable "target", ""
  ColourNote "white", "blue", "No current target"
else
  SetVariable "target", "%1"
  ColourNote "white", "blue", "Target is now %1"
end if




The intention in each case is pretty obvious. The main differences are:

  • Lua uses "==" for equality test, rather than "=".

    Personally I think it is less confusing to have two different symbols for two different operations. In VB, for example, you can write this:

    
    b = 2
    a = b = 2
    Note a    ' answer is -1 (true) because b = 2
    a = b = 3
    Note a    ' answer is 0 (false) because b <> 3
    


    Don't you think that "a = b = 2" is confusing, when the "=" symbols mean two different things in a single line?

    In Lua you would have to write:

    
    b = 2
    a = b == 2
    Note (a)    ' answer is true because b == 2
    a = b == 3
    Note (a)    ' answer is false because b ~= 3
    


    It is clear there you are doing two different things, assignment and comparison.
  • The other major difference is the parentheses on a function call.

    Say you are debugging something like this:

    
    DoAfter 0, "go north"  
    


    In VB you must not write parentheses here, because you are not calling DoAfter as a function. But if you want to check the results, you have to put them in:

    
    result = DoAfter (0, "go north")
    Note result
    


    However with Lua, you consistently put in the parentheses, eg.

    
    DoAfter (0, "go north")  -- use parentheses
    result = DoAfter (0, "go north")  -- still use them
    Note (result)
    

Amended on Thu 16 Dec 2004 05:13 AM by Nick Gammon
USA #7
No, not in those examples. Because its (basically) all mushclient functions.
But, if you get them onto lua, then once something comes up that isn't quite so easy, then they have to figure it out in Lua on their own. There isnt a ton of sites around for tutorials. If they use VB, I'll bet someone on their mud (probably a couple even) can help them figure something out.

So, no, for that example there wasn't hardly a difference at all, but once they have a handful of lua triggers, aliases, and scripts, switching to VB (which has a larger following, therefore more help outside these forums) will be time consuming. Which means a lot of them won't do it, and they will either give up, or use [random guy on their mud]'s XMud and his set of scripts instead because with MC they're 'stuck' with a language that none of their peers knows, and they don't think they can learn on their own (because there isn't a dozen tutorials out there, or whatever, some people can't just pick up a language from the docs, especially if they haven't coded before, I think anyone would be hard pressed to not know ANYONE who understands VB(S) since it's basically everywhere (BASIC anyway)).
#8
I switched from VB to Lua!

Of course I had a good... Ok well, not good, but I had several reasons for it.

1.) Gaging single words, and reprinting them is sexah
b.) I like learning new things
iii.) If Nick goes on and on about how good it is, and how he's more or less scripting exclusively in a new language, it probably means it's better. I mean he did write MC after all, and if it meshs with MC better, it's gotta be... better.
Australia Forum Administrator #9
Quote:

I think anyone would be hard pressed to not know ANYONE who understands VB(S) since it's basically everywhere (BASIC anyway)).


You make some good points, and I don't really want to get into a "language war". Probably at the end of the day everyone has to choose the language they feel most comfortable with, taking into account:

  • Availability
  • Ease of coding
  • Powerful enough to do what they want, whatever that is
  • Ease of debugging
  • Online documentation
  • Number of people who can help with support


My only comment in support of Lua is that, in cases like I described here:


http://www.gammon.com.au/forum/bbshowpost.php?bbsubject_id=4957


Lua makes it easier to do things like "do something" - "pause in the script" - "do something else". This is because of its co-routines (threads, effectively).

Now if you start off scripting in VB/Jscript/Perl, and get comfortable in that, and then in six months time want to build a pause into a script, then it gets complicated. Sure, it can be done, but the explanations of how to make it work can be a bit eye-glazing.

Let's look on the bright side - with plugins you can mix languages anyway. Maybe start with VB, and later on if you want to make a "pause inside a script" plugin, then you can, and perhaps learn Lua then.
#10
Alright, so using what little knowledge I have - and mainly logic, I see in the code the line "co 'blind' @target"... After having set the target to... Well... Myself... I didn't really notice that it cast the spell at me.

And before I continue, thank you this. Now then, I'm also looking for it to be associated with different spells as well such as the spell curse, faerie fire, etc etc. Having set aliases for those as well ('curse' = 'co 'curse', etc.), I was wondering if there was a way to make it add the target name after the spells syntax. This may be a little different than what you expected, I'm not sure.. I suppose I worded it wrongly.
Amended on Thu 16 Dec 2004 10:27 PM by Tatewaki2365
Australia Forum Administrator #11
What did you type, and what did it reply? Can you copy and paste it?
#12
Basically, the whole setup on my end is a little messed up;

I have the alias 'blind', send: 'co 'blind'. But there's nothing in that to string the target in there. So I can type 'tar [person]' all I want, but in the end, it won't do anything because my alias is set to use the target function...

I do 'tar [my character]' 'Target set to [my character]
'blind' (I'm in battle with a scarecrow)
A scarecrow appears to be blinded.
Australia Forum Administrator #13
So you haven't done what we suggested then? The alias was:

co 'blind' @target

That is, it adds the target after the word blind, and the other alias sets up target to be blank (for you) or the name of your target.
#14
Oh... Whoops, sorry about that. I suppose I got caught up in the complex system of numbers and letters... Heh, anyway, thanks alot.
#15
Now a new question arises;

When I used the 'blind' function it says "variable 'target' is not defined". Now, I know you mentions something about the 'target' before... But... I'm not sure what you mean.

And! For the last, and FINAL question (I swear) - should I copy and paste that code from above into the aliases section, and change the spell from blind to another spell each time?
Australia Forum Administrator #16
One of the aliases I gave should set up "target" variable. Did you install it? After installing it you should be able to type: tar blah

and "blah" will be put into variable "target". Check the variables window in world configuration to check it has done that.

To do other spells you shouldn't really have to have the tedium of copying and pasting lots of things. You could make the one alias do lots of things. Read up on regular expressions a bit more to see the power of them. Here is an example of what you could do:


<aliases>
  <alias
   match="^(blind|bop|heal)$"
   enabled="y"
   expand_variables="y"
   regexp="y"
   sequence="100"
  >
  <send>co '%1' @target</send>
  </alias>
</aliases>



Now that alias lets you "blind" or "bop" or "heal" someone. It casts the spell on the variable "Target" in each case.

See how the match text matches one or the other word? And then whatever word it matched is used as the spell to cast. Nice and simple.