|
Private Adept
Joined: 10 Jan 2002 Posts: 264 Location: USA
|
Posted: Thu Apr 08, 2010 12:28 pm
JScript/PerlScript/VBScript in cmud and "%1" expansion |
Code: |
//Set the two dates
today=new Date()
var christmas=new Date(today.getFullYear(), 11, 25) //Month is 0-11 in JavaScript
if (today.getMonth()==11 && today.getDate()>25) //if Christmas has passed already
christmas.setFullYear(christmas.getFullYear()+1) //calculate next year's Christmas
//Set 1 day in milliseconds
var one_day=1000*60*60*24
//Calculate difference btw the two dates, and convert to days
var days_till=Math.ceil((christmas.getTime()-today.getTime())/(one_day))
//Show or send to channel...
"%1" == "" ? sess.EchoStr("[1;32m"+days_till+" [1;31mdays [1;32mleft [1;31muntil [1;32mChristmas[1;31m!",15) : sess.ProcessCommand("%1 ~@ROnly ~@G"+days_till+" ~@Rdays ~@Gleft ~@Runtil ~@GChristmas~@R!~@G!~@R!~@w")
|
Jscript, PerlScript, others,,, i NEED to parse %1 WITH quotes, cmud balks
Any help? |
|
Last edited by Private on Thu Apr 08, 2010 9:36 pm; edited 2 times in total |
|
|
|
Taz GURU
Joined: 28 Sep 2000 Posts: 1395 Location: United Kingdom
|
Posted: Thu Apr 08, 2010 5:02 pm |
Try sess.ProcessCommand(%1 + " ~@ROnly instead.
|
|
_________________ Taz :) |
|
|
|
Private Adept
Joined: 10 Jan 2002 Posts: 264 Location: USA
|
Posted: Thu Apr 08, 2010 5:12 pm |
well... that aint the only place it is used in that part...
Code: |
"%1" == "" ? sess.EchoStr(
|
basically... anywhere i need to get command input in JScript/PerlScript/VBScript...
Perl: if ("%1") {$code = "%1";}
VBScript: Result = Ping. DoPing("%1")
JScript: "%1" == "" ? sess.EchoStr() : |
|
|
|
MattLofton GURU
Joined: 23 Dec 2000 Posts: 4834 Location: USA
|
Posted: Thu Apr 08, 2010 5:23 pm |
Any details? I assume you ran this code and went "Dammit, it's not supposed to do that!", so what happened? What were you expecting to happen?
Don't remember the ins and outs of jscript, so all I can say is that the cmud parser demands you don't put %1 in double-quotes unless you actually want to use % and 1 as a literal string rather than a variable reference. If you want the variable reference, try using different types of brackets instead--single quotes, curly braces, etc. |
|
_________________ EDIT: I didn't like my old signature |
|
|
|
Private Adept
Joined: 10 Jan 2002 Posts: 264 Location: USA
|
Posted: Thu Apr 08, 2010 5:38 pm |
in cmud:
>tillxmas gt
@ROnly @G261 @Rdays @Gleft @Runtil @GChristmas@R!@G!@R!@w
That is not a command. Type 'Commands' for a complete list.
because the %1 is not expanded in ""
remove quotes from 1st "%1"...
>tillxmas gt
Error Processing command:
Syntax error [Microsoft JScript compilation error]
%1 == "" ? sess.EchoStr("[1;32m"+days_till+" [1;31mdays [1;32mleft [1;31muntil [1;32mChristmas[1;31m!",15) : sess.ProcessCommand(%1 ~@ROnly ~@G"+days_till+" ~@Rdays ~@Gleft ~@Runtil ~@GChristmas~@R!~@G!~@R!~@w")
you can make a brand new alias... test, set to JScript...
//make a test var from input...
test=%1
>test
Error Processing command:
Syntax error [Microsoft JScript compilation error]
test=%1
even using that same concept... %1 is not expanded
//Show or send to channel...
channel=%1
channel == "" ? sess.EchoStr("[1;32m"+days_till+" [1;31mdays [1;32mleft [1;31muntil [1;32mChristmas[1;31m!",15) : sess.ProcessCommand(channel+"~@ROnly ~@G"+days_till+" ~@Rdays ~@Gleft ~@Runtil ~@GChristmas~@R!~@G!~@R!~@w")
putting single quotes aint enough...
channel=%1
%1 is not expanded
@ROnly @G261 @Rdays @Gleft @Runtil @GChristmas@R!@G!@R!@w
Sorry Ozzy, I don't understand you.
expecting:
gt @ROnly @G261 @Rdays @Gleft @Runtil @GChristmas@R!@G!@R!@w
(Group) Ozzy: 'Only 261 days left until Christmas!!!'
this was in zmud |
|
|
|
Rahab Wizard
Joined: 22 Mar 2007 Posts: 2320
|
Posted: Thu Apr 08, 2010 6:13 pm |
I've tested, and using "@myvar" works just fine in Jscript on Cmud. Which may indicate a bug, that it cannot handle "%1". Either that, or Jscript requires something other than %1 to represent the first parameter. I've also tried %param1, with no success. It looks like a bug to me.
|
|
|
|
Private Adept
Joined: 10 Jan 2002 Posts: 264 Location: USA
|
Posted: Thu Apr 08, 2010 9:32 pm |
hrm, guess i can call my Perl/J/VBscript alias from another, define %1 in it, then call it from a var in the Perl/J/VBscript
Ill try it out.
Update:
Code: |
#MSS {MinDiff = DateDiff("n", "@t1", "@t2")}
min_uptime = %mss( MinDiff)
|
well, that dont work out too well for this
gets a type mismatch from the VBScript compiler...
this is a bug, there is no workaround that i can find... need to parse vars inside double quotes for most languages inside z/cmud |
|
|
|
Taz GURU
Joined: 28 Sep 2000 Posts: 1395 Location: United Kingdom
|
Posted: Fri Apr 09, 2010 8:48 am |
Use a named argument then you can refer to it by name rather than %1.
|
|
_________________ Taz :) |
|
|
|
Private Adept
Joined: 10 Jan 2002 Posts: 264 Location: USA
|
Posted: Fri Apr 09, 2010 9:13 am |
for some that might work Taz, but look at my last example, @t1/@t2 ... VBScript expects it's params be in double quotes, i tried single, {}, [], (), <>... none work
the issue is with cmud not parsing between double quotes, it NEEDS to in scripting languages other then zscript |
|
|
|
Taz GURU
Joined: 28 Sep 2000 Posts: 1395 Location: United Kingdom
|
Posted: Fri Apr 09, 2010 10:28 am |
Lets say we were messing about outside of CMUD with a scripting language, what would @t1 mean to it? Not a great deal I suspect.
Ok so now we're messing about inside of CMUD with a scripting language, what does @t1 mean to it? Still not a great deal! However there is a COM object exposed and we can use that instead.
#MSS {MinDiff = DateDiff("n", zvar.t1, zvar.t2)}
min_uptime = %mss( MinDiff) |
|
_________________ Taz :) |
|
|
|
Taz GURU
Joined: 28 Sep 2000 Posts: 1395 Location: United Kingdom
|
Posted: Fri Apr 09, 2010 10:33 am |
At a guess you can use zvar.param1 for %1.
|
|
_________________ Taz :) |
|
|
|
Private Adept
Joined: 10 Jan 2002 Posts: 264 Location: USA
|
Posted: Fri Apr 09, 2010 12:11 pm |
i just learned this from someone asking for PerlScript help, $zvar->variable_name
didnt know about zvar.param1 , thanks :) |
|
|
|
|
|