Hmm, it shouldn't be necessary to use a spun off task for this, I'm not sure what's going on as someone else pointed out your original code looked fine. A different idiom you can use for toggleable behaviour now what WHILE exists would be this one:
This did not work for me either. I have tried running some very simple tests to find out what is going on with the user defined flags. Here are the tests I have ran:
TOGGLE(myflag);
LOG("$myflag%");
This always returns 'True'. It never toggles to false. It should switch back and forth to True and False as I hit the key.
To reiterate a few issues:There seems to be a problem with RegEx on any CHAT that has multiple lines
Ok thanks for the bug report, I'll see what I can do to fix the issue. Hopefully it should be as straightforward as jsut splitting any incoming chat messages using line breaks and then raising onChat the relevant number of times. I didn't realise that multi-line chat messages even existed so it hadn't occurred to me that it might be an issue.
There seems to be a problem (or I am not understanding something?) with using modules.
The API for the current version has not been released (because nobody has actually requested it, I'm still only handing it out to those that ask because it's still being developed and I can't fully support it yet) so there won't be any modules for the current version. Old modules will be recognised but not loaded because the API version tag will not match, I realise that the console output may make it appear that the module was loaded but to prevent crashes it will be ignored if the API version is wrong. I'll update the message to indicate when modules are being ignored because they are outdated.
This did not work for me either. I have tried running some very simple tests to find out what is going on with the user defined flags. Here are the tests I have ran:
TOGGLE(myflag);
LOG("$myflag%");
This always returns 'True'. It never toggles to false. It should switch back and forth to True and False as I hit the key.
This always returns '%myflag%' being shown as text in the log instead of True or False. Not sure why this is...
The last bit is as expected, if a flag isn't defined then using %flagname% will just spit out %flagname%. The rest is, not to put too fine a point on it, bloody weird. Is there any chance you could zip and send me your macros directory so I can see whether anything has gotten screwed up in the configuration. Local flags are persisted in the template so you should even see the flags being set in the config file. I really can't imagine what's going on here because everything you've posted looks fine
Check your code to make sure you have semicolons after every line. You are missing a few here...
and semicolons are optional (only required if putting multiple commands on one line, if spreading across multiple lines they can be ignored). All I can think is that there's something wonky in the config that's causing flags to not be properly persisted.
How would I do that surely I have to put that on a macro key ?
Macros can be triggered by keys, but in the more recent versions you now have the ability to have macros triggered by other events too, such as when you take damage, pick up an item, etc. One such event is "onJoinGame" which triggers immediately when you join the game, so you can put any commands that you want to always execute in that event and they will always trigger.
Hey, I was just wondering how to make it so when I press SHIFT it holds sneak without me having to hold down on SHIFT?
You can't send specific key events (well, ok you can but they won't help you in this case) but you can have a macro which presses minecraft's SNEAK key. The problem is that you can't have a macro on the sneak key, so to use SHIFT you'd have to bind SNEAK somewhere else, for example (in the options bind SNEAK to, say [PAGEUP]). Once you've re-bound the SNEAK key, you can put a macro on SHIFT which just contains the following code
$${TOGGLEKEY(sneak)}$$
which will then act like a toggle for SNEAK. Just bear in mind that your real sneak key is now PAGE UP (or whatever you assign it to).
Ok thanks for the bug report, I'll see what I can do to fix the issue. Hopefully it should be as straightforward as jsut splitting any incoming chat messages using line breaks and then raising onChat the relevant number of times. I didn't realise that multi-line chat messages even existed so it hadn't occurred to me that it might be an issue.
The API for the current version has not been released (because nobody has actually requested it, I'm still only handing it out to those that ask because it's still being developed and I can't fully support it yet) so there won't be any modules for the current version. Old modules will be recognised but not loaded because the API version tag will not match, I realise that the console output may make it appear that the module was loaded but to prevent crashes it will be ignored if the API version is wrong. I'll update the message to indicate when modules are being ignored because they are outdated.
I thought you had updated the SHELL module?
Anyway, it would be nice if there was a flag in the settings to disable version checking, so we can run (possibly) unsafe modules at our own risk.
Anyway, it would be nice if there was a flag in the settings to disable version checking, so we can run (possibly) unsafe modules at our own risk.
No I didn't update it, the last update was kind of packed in between 1.2.5 coming out and me going away to The Gadget Show so I didn't get to update ancilliary stuff like the API and the SHELL module. I'll update both now I'm back in the real world.
Wouldn't "always override" also make it work?
if not, what does it do?
Macros can't be triggered by whatever key SNEAK is assigned to because SNEAK is used as the modifier to access the GUI, therefore it won't do anything.
Just looking at the code you have here, I should mention that the 4th parameter to MATCH is the capturing subgroup to return, which defaults to 0 and returns the entire match. But knowing this you can see there's really no need to make all of the other subgroups noncapturing, just change the number to a different group.
Also, your regex to capture player names seems to have an issue in that it will capture invalid player names. Since minecraft player names are guaranteed to be only alphanumeric characters or underscore, and between 2 and 16 characters, a better regex for matching player names is [a-zA-Z0-9_]{2,16}.
There's no problem with making the the subgroups noncapturing, it's just that regexps can be tricky to read at the best of times, and all the ?: just make it more so.
Im trying to make a AFK Button (As we cant do /afk on this server) So that its like a forever toggle button until I press it again heres my code for the chat matching and replying I think
Well IFMATCHES takes a regex as its second parameter, so the 3rd, 4th and 5th parameters there will be ignored, I think what you're looking for is something like this:
That regex gave the error message: Error: Unclosed counted closure near index 14
I put it in like this:
MATCH(%CHAT%,[a-zA-Z0-9_]{2,16},@&lastmsgname,1)
Sorry I think you misunderstood me, I meant that you should use that pattern to match the player name rather than using the ungreedy any-character match just because it's less error prone. It's also a good idea to wrap the regexp in quotes to help the mod recognise the pattern.
For example:
IFMATCHES(%CHAT%,"^- ([a-z0-9_]{2,16}):");
MATCH(%CHAT%,"^- ([a-z0-9_]{2,16}):(.*)$",@&lastmsgname,1);
MATCH(%CHAT%,"^- ([a-z0-9_]{2,16}):(.*)$",@&lastmsgtext,2);
IFMATCHES(%@&lastmsgtext%,"wiylvl");
WAIT(1);
ECHO("/msg %@&lastmsgname% Some random text");
LOG("/msg %@&lastmsgname% Some random text");
ENDIF;
ENDIF;
If you see what I mean.
The main differences here are that now the regexp is anchored and will only match valid names, the regex you had before would have actually happily matches against the text:
<someotherplayer> - play\er: not the message you want to match
because you hadn't anchored the pattern to the start of the string, and would also happily match invalid characters in the player name.
Also, notice that now I'm using the same pattern for each part of the check it's much easier to read, since it's clear we're doing a comparison and then two matches against the same regex, but just doing a check, then a capture, and then a capture of a different group. Making your regex's as clear as possible is a big step towards making them easier to troubleshoot.
AH HA! I think I know the problem. The regex is capturing the color code that is used to color the player's name as well as the actual name. So you are sending ?#PlayerName instead of just PlayerName. Change the regex to this:
&[a-fA-F0-9] will filter out any legitimate character codes (I think. If it doesn't work, change the ampersand "&" to a period ".")
\w is a special character that matches all upper and lower case letters, as well as numbers and the underscore. Its just a bit faster than typing [a-fA-F0-9_].
EDIT: Ok, following Mumfrey's suggestion above, I would do this:
IFMATCHES(%CHAT%,^- &[a-fA-F0-9](\w{2,16}): (.*)$);
MATCH(%CHAT%,^- &[a-fA-F0-9](\w{2,16}): (.*)$,@&lastmsgname,1);
MATCH(%CHAT%,^- &[a-fA-F0-9](\w{2,16}): (.*)$,@&lastmsgtext,2);
IFMATCHES(%@&lastmsgtext%,"wiylvl");
WAIT(1);
ECHO("/msg %@&lastmsgname% Some random text");
LOG("/msg %@&lastmsgname% Some random text");
ENDIF;
ENDIF;
EDIT AGAIN: That won't work either. You will need to place an additional &[a-fA-F0-9] in between the carrot "^" and the first hyphen "-" to match the color code at the beginning of the text.
AH HA! I think I know the problem. The regex is capturing the color code that is used to color the player's name as well as the actual name. So you are sending ?#PlayerName instead of just PlayerName.
Well spotted, I didn't realise there were colour codes in the message he was matching. This really highlights the problem with using matches which are too open-ended, such as any-character matches.
&[a-fA-F0-9] will filter out any legitimate character codes (I think. If it doesn't work, change the ampersand "&" to a period ".")
The mod replaces colour codes in ampersand form with the "real" colour code, so putting for example "&c" in a regex will be converted to the real colour code string, but &[a-f0-9] will not, so the best approach would be to use the hex representation of the colour code and write it as \xa7[a-f\d] (note that I use case-insensitive match so it's not necessary to cater for upper and lower-case letters).
\w is a special character that matches all upper and lower case letters, as well as numbers and the underscore. Its just a bit faster than typing [a-fA-F0-9_].
Good point, I didn't realise that java's \w captured underscore as well.
EDIT: Ok, following Mumfrey's suggestion above, I would do this:
IFMATCHES(%CHAT%,^- &[a-fA-F0-9](/w{2,16}): (.*)$);
MATCH(%CHAT%,^- &[a-fA-F0-9](/w{2,16}): (.*)$,@&lastmsgname,1);
MATCH(%CHAT%,^- &[a-fA-F0-9](/w{2,16}): (.*)$,@&lastmsgtext,2);
IFMATCHES(%@&lastmsgtext%,"wiylvl");
WAIT(1);
ECHO("/msg %@&lastmsgname% Some random text");
LOG("/msg %@&lastmsgname% Some random text");
ENDIF;
ENDIF;
you've accidentally typed /w instead of \w here.
EDIT: Also, I just realised I ignored my own advice when correcting the code above, the regex should really be in quotes otherwise weird things tend to happen.
The mod replaces colour codes in ampersand form with the "real" colour code, so putting for example "&c" in a regex will be converted to the real colour code string, but &[a-f0-9] will not, so the best approach would be to use the hex representation of the colour code and write it as \xa7[a-f\d] (note that I use case-insensitive match so it's not necessary to cater for upper and lower-case letters).
Ah, that will be immensely helpful, I think. I currently just use a .[a-fA-F0-9] to match a character code, which hasn't caused any issues for me yet, though it could easily cause problems in a less exact regex than the ones I usually use.
EDIT: Also, I just realised I ignored my own advice when correcting the code above, the regex should really be in quotes otherwise weird things tend to happen.
Darn it, I'm always doing that, mixing up my backslashes with my forward slashes. Also, what weird things happen if the regex isn't in quotes? I don't use quotes at all when matching regexes, and I've never had any problems.
Yes, there is a color code at the beginning of the string that is not being matched due to the carrot, which markes the beginning of the string. This causes the regex to fail.
Using the info that Mumfrey said above, change you're regex to this:
IFMATCHES(%CHAT%,^\xa7[a-fA-F0-9]- \xa7[a-fA-F0-9](\w{2,16}): (.*)$);
MATCH(%CHAT%,^\xa7[a-fA-F0-9]- \xa7[a-fA-F0-9](\w{2,16}): (.*)$,@&lastmsgname,1);
MATCH(%CHAT%,^\xa7[a-fA-F0-9]- \xa7[a-fA-F0-9](\w{2,16}): (.*)$,@&lastmsgtext,2);
IFMATCHES(%@&lastmsgtext%,"wiylvl");
WAIT(1);
ECHO("/msg %@&lastmsgname% Some random text");
LOG("/msg %@&lastmsgname% Some random text");
ENDIF;
ENDIF;
\xa7 will match the actual section sign ("§") used to color text in Minecraft.
EDIT²: Also, Mumfrey, could you add an option in the next version that makes you return to the text file selection screen after exiting out of the text file editor? Its not necessary, but it would be nice for when you are editing several different text files at once.
Did not work either
And I can't see why because I am a noob with RegEX. I basicly knows [a-zA-Z]
Trying to learn thouge...
Here, try changing all of the /xa7 with /u00a7 . This will change it from the ASCII version to the Unicode version, and may work.
Also, I am going to have you do something for me, which will let us see if you have any weird things in your chat format.
First, I need you to put this in your onChat:
set(@&lastchat,%CHAT%);
Then, I need you to bind this to a key (doesn't matter which):
echo("%@&lastchat%")
Then, in your options, enable "Store sent messages in local history".
Next, say "Test" in the chat.
After that, activate the macro I had you bind to a key.
Now, open chat and press up. Copy all of that (hold shift and press the arrow keys) and copy and paste it here.
That will give us the exact string your server is using for messages, color codes and all. The server's chat mod probably has doubled-up chat codes (like &f&e or something) somewhere. I had to do this with my server, as we use Herochat (it was a nightmare, let me tell you).
This is always the danger with adding regex support to anything, 99% of the discussion thereafter becomes about regexps Would it be worth moving this ongoing discussion into a PM thread until it's worked out? Especially since these forums support multi-way PM's.
EDIT²: Also, Mumfrey, could you add an option in the next version that makes you return to the text file selection screen after exiting out of the text file editor? Its not necessary, but it would be nice for when you are editing several different text files at once.
This is always the danger with adding regex support to anything, 99% of the discussion thereafter becomes about regexps Would it be worth moving this ongoing discussion into a PM thread until it's worked out? Especially since these forums support multi-way PM's.
Yeah. I think that I have it figured out though. That line format he provided help immensely.
You may want to make a separate thread specifically for RegEx help. Just a thought
Can i get an answer to my (i think) simple question?
You could try putting
$${toggle(@toggle)}$$
In a key state macro (put it in the Key Down and Key Held sections, and putting a delay of 1), then setting the modifier key to control. That probably won't work for a mouse button though.
Hey, this mod Is awesome and I use it every day.
However, I can't seem to figure out how to use the variables in the events.
E.g. Adding the "JOINEDPLAYER" that joined into the "onPlayerJoined" event or the variables in the "onPickupItem" event.
Hey, this mod Is awesome and I use it every day.
However, I can't seem to figure out how to use the variables in the events.
E.g. Adding the "JOINEDPLAYER" that joined into the "onPlayerJoined" event or the variables in the "onPickupItem" event.
Just surround them with percent signs, and make sure they are in all caps. For example: %JOINEDPLAYER%.
Maybe we could create a seperate forum all together. Then we could seperate all issues and make it easier to keep track of evrything. Could have categories and all. There are a bunch off free forums out there.
Ya, at this point ModMacros should probably have its own space on the internet.
This did not work for me either. I have tried running some very simple tests to find out what is going on with the user defined flags. Here are the tests I have ran:
This always returns 'True'. It never toggles to false. It should switch back and forth to True and False as I hit the key.
Returns 'True' as expected.
Returns 'FALSE' as expected.
This always returns '%myflag%' being shown as text in the log instead of True or False. Not sure why this is...
Check your code to make sure you have semicolons after every line. You are missing a few here...
Ok thanks for the bug report, I'll see what I can do to fix the issue. Hopefully it should be as straightforward as jsut splitting any incoming chat messages using line breaks and then raising onChat the relevant number of times. I didn't realise that multi-line chat messages even existed so it hadn't occurred to me that it might be an issue.
The API for the current version has not been released (because nobody has actually requested it, I'm still only handing it out to those that ask because it's still being developed and I can't fully support it yet) so there won't be any modules for the current version. Old modules will be recognised but not loaded because the API version tag will not match, I realise that the console output may make it appear that the module was loaded but to prevent crashes it will be ignored if the API version is wrong. I'll update the message to indicate when modules are being ignored because they are outdated.
The last bit is as expected, if a flag isn't defined then using %flagname% will just spit out %flagname%. The rest is, not to put too fine a point on it, bloody weird. Is there any chance you could zip and send me your macros directory so I can see whether anything has gotten screwed up in the configuration. Local flags are persisted in the template so you should even see the flags being set in the config file. I really can't imagine what's going on here because everything you've posted looks fine
and semicolons are optional (only required if putting multiple commands on one line, if spreading across multiple lines they can be ignored). All I can think is that there's something wonky in the config that's causing flags to not be properly persisted.
Macros can be triggered by keys, but in the more recent versions you now have the ability to have macros triggered by other events too, such as when you take damage, pick up an item, etc. One such event is "onJoinGame" which triggers immediately when you join the game, so you can put any commands that you want to always execute in that event and they will always trigger.
You can't send specific key events (well, ok you can but they won't help you in this case) but you can have a macro which presses minecraft's SNEAK key. The problem is that you can't have a macro on the sneak key, so to use SHIFT you'd have to bind SNEAK somewhere else, for example (in the options bind SNEAK to, say [PAGEUP]). Once you've re-bound the SNEAK key, you can put a macro on SHIFT which just contains the following code
which will then act like a toggle for SNEAK. Just bear in mind that your real sneak key is now PAGE UP (or whatever you assign it to).
Thanks for taking a look.
I thought you had updated the SHELL module?
Anyway, it would be nice if there was a flag in the settings to disable version checking, so we can run (possibly) unsafe modules at our own risk.
EDIT: And I guess I will request that API then.
=o, Timesaver, yay!
Wouldn't "always override" also make it work?
if not, what does it do?
'Cause tomorrow spring is here
No I didn't update it, the last update was kind of packed in between 1.2.5 coming out and me going away to The Gadget Show so I didn't get to update ancilliary stuff like the API and the SHELL module. I'll update both now I'm back in the real world.
Okay, I'll update it and send you a PM.
Macros can't be triggered by whatever key SNEAK is assigned to because SNEAK is used as the modifier to access the GUI, therefore it won't do anything.
Just looking at the code you have here, I should mention that the 4th parameter to MATCH is the capturing subgroup to return, which defaults to 0 and returns the entire match. But knowing this you can see there's really no need to make all of the other subgroups noncapturing, just change the number to a different group.
Also, your regex to capture player names seems to have an issue in that it will capture invalid player names. Since minecraft player names are guaranteed to be only alphanumeric characters or underscore, and between 2 and 16 characters, a better regex for matching player names is [a-zA-Z0-9_]{2,16}.
There's no problem with making the the subgroups noncapturing, it's just that regexps can be tricky to read at the best of times, and all the ?: just make it more so.
Well IFMATCHES takes a regex as its second parameter, so the 3rd, 4th and 5th parameters there will be ignored, I think what you're looking for is something like this:
onChat
Then bound to a key:
Sorry I think you misunderstood me, I meant that you should use that pattern to match the player name rather than using the ungreedy any-character match just because it's less error prone. It's also a good idea to wrap the regexp in quotes to help the mod recognise the pattern.
For example:
If you see what I mean.
The main differences here are that now the regexp is anchored and will only match valid names, the regex you had before would have actually happily matches against the text:
because you hadn't anchored the pattern to the start of the string, and would also happily match invalid characters in the player name.
Also, notice that now I'm using the same pattern for each part of the check it's much easier to read, since it's clear we're doing a comparison and then two matches against the same regex, but just doing a check, then a capture, and then a capture of a different group. Making your regex's as clear as possible is a big step towards making them easier to troubleshoot.
AH HA! I think I know the problem. The regex is capturing the color code that is used to color the player's name as well as the actual name. So you are sending ?#PlayerName instead of just PlayerName. Change the regex to this:
&[a-fA-F0-9] will filter out any legitimate character codes (I think. If it doesn't work, change the ampersand "&" to a period ".")
\w is a special character that matches all upper and lower case letters, as well as numbers and the underscore. Its just a bit faster than typing [a-fA-F0-9_].
EDIT: Ok, following Mumfrey's suggestion above, I would do this:
EDIT AGAIN: That won't work either. You will need to place an additional &[a-fA-F0-9] in between the carrot "^" and the first hyphen "-" to match the color code at the beginning of the text.
Well spotted, I didn't realise there were colour codes in the message he was matching. This really highlights the problem with using matches which are too open-ended, such as any-character matches.
The mod replaces colour codes in ampersand form with the "real" colour code, so putting for example "&c" in a regex will be converted to the real colour code string, but &[a-f0-9] will not, so the best approach would be to use the hex representation of the colour code and write it as \xa7[a-f\d] (note that I use case-insensitive match so it's not necessary to cater for upper and lower-case letters).
Good point, I didn't realise that java's \w captured underscore as well.
you've accidentally typed /w instead of \w here.
EDIT: Also, I just realised I ignored my own advice when correcting the code above, the regex should really be in quotes otherwise weird things tend to happen.
Ah, that will be immensely helpful, I think. I currently just use a .[a-fA-F0-9] to match a character code, which hasn't caused any issues for me yet, though it could easily cause problems in a less exact regex than the ones I usually use.
Darn it, I'm always doing that, mixing up my backslashes with my forward slashes. Also, what weird things happen if the regex isn't in quotes? I don't use quotes at all when matching regexes, and I've never had any problems.
EDIT:
Yes, there is a color code at the beginning of the string that is not being matched due to the carrot, which markes the beginning of the string. This causes the regex to fail.
Using the info that Mumfrey said above, change you're regex to this:
\xa7 will match the actual section sign ("§") used to color text in Minecraft.
EDIT²: Also, Mumfrey, could you add an option in the next version that makes you return to the text file selection screen after exiting out of the text file editor? Its not necessary, but it would be nice for when you are editing several different text files at once.
Here, try changing all of the /xa7 with /u00a7 . This will change it from the ASCII version to the Unicode version, and may work.
Also, I am going to have you do something for me, which will let us see if you have any weird things in your chat format.
First, I need you to put this in your onChat:
Then, I need you to bind this to a key (doesn't matter which):
Then, in your options, enable "Store sent messages in local history".
Next, say "Test" in the chat.
After that, activate the macro I had you bind to a key.
Now, open chat and press up. Copy all of that (hold shift and press the arrow keys) and copy and paste it here.
That will give us the exact string your server is using for messages, color codes and all. The server's chat mod probably has doubled-up chat codes (like &f&e or something) somewhere. I had to do this with my server, as we use Herochat (it was a nightmare, let me tell you).
D'oh! Of course it will. Try this instead:
onChat
Yes I can add this.
Yeah. I think that I have it figured out though. That line format he provided help immensely.
You may want to make a separate thread specifically for RegEx help. Just a thought
You could try putting In a key state macro (put it in the Key Down and Key Held sections, and putting a delay of 1), then setting the modifier key to control. That probably won't work for a mouse button though.
Just put something like this in another macro key:
However, I can't seem to figure out how to use the variables in the events.
E.g. Adding the "JOINEDPLAYER" that joined into the "onPlayerJoined" event or the variables in the "onPickupItem" event.
Just surround them with percent signs, and make sure they are in all caps. For example: %JOINEDPLAYER%.
Ya, at this point ModMacros should probably have its own space on the internet.