Page 1 of 1

Event Troubles?

Posted: Thu May 13, 2004 11:11 am
by Jerle69
Hey guys,

Before I start, let me say I was using MQ2-20040512a compiled with VS6 SP6.

Last night I was augmenting my RH script and tried to take advantage of the new #event system. Using Lax's examples (I wanted to acheive exactly what he demonstrated, actually), I didn't get the results I anticpated? :shock:

A snippit from the macro looked like this (included a little debug /echo so I could see what was going on)...

Code: Select all

#Event TogLeash  "[MQ2] Leash #1#" 
|
| ... some declares here with global doLeash and stake variables...
|
... and later on the event itself was written like this...

Code: Select all

Sub Event_TogLeash(string Line, string Command) 
  /if (${Command.Equal[OFF]} || (${Int[${Command}]}<0)) { 
    /varset doLeash FALSE 
    /echo ** Leashing is now OFF! 
  } else { 
    /varset doLeash TRUE 
    /varset leashlength ${Int[${Command}]} 
    /varset stakeX ${Me.X} 
    /varset stakeY ${Me.Y} 
    /echo ** Leashing is now ON! Leashlength: ${leashlength} ft. 
    /echo ** Stake planted at X:${stakeX}, Y:${stakeY} 
  } 
  |- This not working?! WTF?
  /echo Line: "${Line}" & Command: "${Command}"
/return 
The code executed but when I issued a "/echo Leash 400" for example, the output was:

** Leashing is now ON! Leashlength: 0 ft.
** Stake planted at X:45, Y:-23
Line: [MQ] Leash 400 & Command: "NULL"

I just sighed and went "BLAH, that's odd" Seems to me that it didn't paramaterize the event arguments as advertised. I just went ahead and rewrote it like this, which works but is less graceful and doesn't use any of the new #event stuff =(

Code: Select all

#Event TogLeash  "[MQ2] Leash#*#" 
|
| ... some declares here with global doLeash and stake variables...
|
... and the event itself...

Code: Select all

Sub Event_TogLeash(string Line) 
  /if (${Line.Arg[3].Equal[OFF]} || (${Int[${Line.Arg[3]}]}<0)) { 
    /varset doLeash FALSE 
    /echo ** Leashing is now OFF! 
  } else { 
    /varset doLeash TRUE 
    /varset leashlength ${Int[${Line.Arg[3]}]} 
    /varset stakeX ${Me.X} 
    /varset stakeY ${Me.Y} 
    /echo ** Leashing is now ON! Leashlength: ${leashlength} ft. 
    /echo ** Stake planted at X:${stakeX}, Y:${stakeY} 
  } 
/return 
Did I do something wrong or is this a bug?

Thanks,

Posted: Thu May 13, 2004 11:15 am
by ml2517
Lax commented about this in another thread. I believe your problem was that you had a space in your param section of your sub:


Code: Select all

Remove this space -------------o
                               |
                               v
Sub Event_TogLeash(string Line, string Command)

Posted: Thu May 13, 2004 11:20 am
by Jerle69
Woah, really? That's pretty odd behavior then. If removing the space fixes the problem, I'll go and rewrite those events tonight; however, should whitespace in an event header declaration between parameters cause parsing issues with the event itself? If I remove the space, that's certainly what's going on but I'd think that's a ... errr... bad feature :)

Posted: Thu May 13, 2004 11:21 am
by ml2517
Lax already fixed it for the next zip I believe.

Posted: Thu May 13, 2004 12:51 pm
by Lax
The issue has nothing to do with parsing the event matching text, and everything to do with parsing the Sub Event_MyEvent line. It's not a "feature" you're seeing, that's an "annoyance" or "bug" ;) Originally MQ was written with such specifications that extra spaces here and there where you may normally use them was not allowed. I'm working on fixing that as necessary. This case is fixed next zip as ml2517 pointed out :)

Here's what the problem is..
The parser looks for the comma. Previously, it would then take whatever follows it up to the next comma VERBATIM. This means including that space. So instead of "string myvar" it was " string myvar". Then it ended up doing something with " stri" and "ng myvar" ... i have no idea, dont ask me ;) And when it tried to assign the values from Blech to the sub call, it would try to set a variable named "ng myvar" instead of the right one. The variable named "Command" in your example would therefore be NULL.

Anyway, fixed next zip

Hm..

Posted: Thu May 13, 2004 1:52 pm
by Azum
That's odd, because my event seems to be working fine... as follows...

Code: Select all

#event togglemain "[MQ2] nuke1 #1#"

Code: Select all

sub event_togglemain(Line, Command)
/varset TempStr "${Command}"
/if (!${Me.Book[${TempStr}]}) {
/echo You dont appear to have ${TempStr} in your spellbook.
/return
} else {
/varset mainnuke ${TempStr}
/ini "${IniFile}" Settings mainnuke ${mainnuke}
/echo Your main nuke is now ${mainnuke}
/if (!${Me.Gem[${mainnuke}]}) {
/memspell ${mainnukegem.Right[1]} ${mainnuke}
/delay 5s
/return
}
   }
I'm not arguing there's not a bug, just thought I'd give an example of where it's actually doing what it's supposed to.

Posted: Thu May 13, 2004 1:59 pm
by Jerle69
Perhaps the bug behavior is different if you specify the parameter datatypes (I explicitly forced them to be strings, even though that's default; you didn't specify them). I'm guessing yours works because you have one less space than mine (you still got one space after the comma, you just don't have a datatype and therefore there is not a space after the datatype).

Dunno. Moot point really, since Lax said it's gonna be fixed =)

Thanks Lax! :wink:

Re: Hm..

Posted: Thu May 13, 2004 4:41 pm
by ml2517
Azum wrote:That's odd, because my event seems to be working fine... as follows...

Code: Select all

#event togglemain "[MQ2] nuke1 #1#"

Code: Select all

sub event_togglemain(Line, Command)
/varset TempStr "${Command}"
/if (!${Me.Book[${TempStr}]}) {
/echo You dont appear to have ${TempStr} in your spellbook.
/return
} else {
/varset mainnuke ${TempStr}
/ini "${IniFile}" Settings mainnuke ${mainnuke}
/echo Your main nuke is now ${mainnuke}
/if (!${Me.Gem[${mainnuke}]}) {
/memspell ${mainnukegem.Right[1]} ${mainnuke}
/delay 5s
/return
}
   }
I'm not arguing there's not a bug, just thought I'd give an example of where it's actually doing what it's supposed to.
Probably because you aren't specifying a variable type and just letting it assign string by default.