Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.
 Entire forum ➜ MUSHclient ➜ Jscript ➜ trigger to assign variable name

trigger to assign variable name

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Kingjames_IV   (10 posts)  Bio
Date Thu 13 Feb 2003 10:29 PM (UTC)
Message
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.
Top

Posted by Poromenos   Greece  (1,037 posts)  Bio
Date Reply #1 on Fri 14 Feb 2003 11:01 AM (UTC)
Message
You don't need scripting for that:
Trigger: You poke *
Send: %1
Enabled, Keep Evaluating
Send to: Variable (label is name)
Label: badGuy

Vidi, Vici, Veni.
http://porocrom.poromenos.org/ Read it!
Top

Posted by Kingjames_IV   (10 posts)  Bio
Date Reply #2 on Fri 14 Feb 2003 07:17 PM (UTC)
Message
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.
Top

Posted by Kingjames_IV   (10 posts)  Bio
Date Reply #3 on Fri 14 Feb 2003 07:18 PM (UTC)
Message
oops missed the one line in that post, you did understand, thanks i'll try that.
Top

Posted by Kingjames_IV   (10 posts)  Bio
Date Reply #4 on Fri 14 Feb 2003 07:49 PM (UTC)
Message
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.
Top

Posted by Guest1   USA  (256 posts)
Date Reply #5 on Fri 14 Feb 2003 09:00 PM (UTC)

Amended on Sat 15 Feb 2003 08:58 PM (UTC) by Guest1

Message
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.



Top

Posted by Kingjames_IV   (10 posts)  Bio
Date Reply #6 on Sun 16 Feb 2003 04:18 AM (UTC)
Message
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.
Top

Posted by Shadowfyr   USA  (1,788 posts)  Bio
Date Reply #7 on Sun 16 Feb 2003 07:53 PM (UTC)
Message
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 ). ;)
Top

Posted by Kingjames_IV   (10 posts)  Bio
Date Reply #8 on Thu 20 Feb 2003 09:56 PM (UTC)
Message
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.
Top

Posted by Shadowfyr   USA  (1,788 posts)  Bio
Date Reply #9 on Fri 21 Feb 2003 05:59 PM (UTC)
Message
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.
Top

Posted by Nick Gammon   Australia  (23,120 posts)  Bio   Forum Administrator
Date Reply #10 on Fri 21 Feb 2003 09:09 PM (UTC)
Message
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]);

}

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Kingjames_IV   (10 posts)  Bio
Date Reply #11 on Sat 22 Feb 2003 08:37 AM (UTC)
Message
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.
Top

Posted by Kingjames_IV   (10 posts)  Bio
Date Reply #12 on Sat 22 Feb 2003 05:51 PM (UTC)
Message
thanks a lot, works perfectly now.
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


31,050 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.