trigger to assign variable name

Posted by Kingjames_IV on Thu 13 Feb 2003 10:29 PM — 13 posts, 43,394 views.

#0
ok i've been trying to figure it out but i must be missing something. I want to make a trigger/script that will for instance react to 'you poke XXX' and change the variable badGuy to be XXX. I've managed to make a trigger that will send XXX to the world and a script that will change variables but can't get the trigger to send XXX to the script. I use Jscript and can't figure out how to get it to let me pass a parameter to a function.
Greece #1
You don't need scripting for that:
Trigger: You poke *
Send: %1
Enabled, Keep Evaluating
Send to: Variable (label is name)
Label: badGuy
#2
your misunderstanding, i can already do that. What i want is for the trigger to change a variable to XXX or to send XXX to a script that will change the variable, i can already send XXX to the world.
#3
oops missed the one line in that post, you did understand, thanks i'll try that.
#4
Is there also a way to do this with an alias? Went to do it and it would be much more useful to me as an alias rather than a trigger.
USA #5
Yeah you can by getting the alias to call a script to set the variable, but if you hang on a bit, the next version of MUCHclient will apparently have aliases set up like triggers are at the moment, so you can send direct to the variable.

From what Nick has indicated in recent threads (December/January), it should hopefully be released very very soon (mid Feb?). I've been checking the site like every 2 hours for the last couple of days to see if the new vers is out yet heh.. keen as.



Amended on Sat 15 Feb 2003 08:58 PM by Guest1
#6
I know i can call an alias to run a script but is there a way to pass a parameter to scripts? I tried similar to java programming putting it in the declaration of the function ( eg. script(str String) ) but thats no good.
USA #7
Aiases and triggers both pass predefined parameters. The are:

(name, output, wildcards)

name - The alias or trigger that called this script.
output - The entire original text that was matched.
wildcards - The information passed as other parameters.

Thus for instance with the trigger example earlier in the thread, if it was used to call a script instead:

Trigger: You poke *
Enabled, Keep Evaluating
Label: badGuy
Script: SaveBadGuy

name = badGuy
output = You poke Fred
wildcards(1) = Fred
wildcards(2)-(9) = Empty

An alias would produce identical results. Basically the parameters are automatically generated and passed based on how many things you told it to pass using * in normal ones or () around the item to be passed in regular expressions. This means of course that in regexp you can match a trigger (or while silly and alias) on an unknown word and actually have the script ignore it as a parameter. i.e. like - 'A (.*) .* into the room', where the second .* could be squishes, hops, wanders or anything else. The sub would only be passed the one in between ( and ). ;)
#8
i tried using wildcards(1) in a script and it keeps giving me an error saying object expected. How exactly do you use it? i tried using it in world.send(wildcards(1)); and i got an error tried a few other ways and still no good.
USA #9
It would help to see the 'exact' script you are trying to use. Sounds like you are incorrectly defining something in the script and it is complaining because the array 'wildcards' doesn't actually exist. Without showing us the exact code you are trying to use, we are flying blind here.

However I suspect you are doing something a bit silly. The procedure you call needs to be like:
function SaveBadGuy (name, output, wildcards)
  {
    world.send(wildcards(1));
  }

If you defined the routine this way, then I haven't a clue why it doesn't work. One thing to note though is that the names: name, output and wildcards are 'your' names, not ones that the script engine or mushclient automatically uses. For all anyone knows mushclient thinks they are xyzzy, ziggy and glug. You have to make sure that the number of them are the same as what mushclient expects and it helps to have them be something you understand, but they can be anything you want. In your case 'if' you defined the script like above, then it should have worked as expected.

Note however that since sending the contents of the wildcard 'to' the mud is quite silly, you probably should have used 'world.note(wildcards(1));', which displays it in output, but doesn't try to send it to the mud itself.
Australia Forum Administrator #10
VB arrays cannot be directly used in Jscript. The example script files that ship with MUSHclient show what you need to do. Here is an example, from what Shadowfyr was describing, but coded so it will work in Jscript:


function SaveBadGuy (name, output, wildcardsVB)
{

var wildcards;

  wildcards = VBArray(wildcardsVB).toArray();	

  world.note (wildcards [0]);

}
#11
ah ok think i got it now, wasn't putting 3 parameters in my declaration of my function.

And i know sending it to the mud is useless and stupid but i was just using that to test if the script was reading the wildcard, thats not at all what i'm planning to do with it.
#12
thanks a lot, works perfectly now.