temnix Posted May 22, 2020 Share Posted May 22, 2020 For some reason Weidu won't replace some of the text in scripts. The script code compiles by itself, in the editor, but nothing ends up rewitten here. Am I using the patching function wrong? COPY_EXISTING_REGEXP GLOB ~.*\.BCS~ ~override~ DECOMPILE_AND_PATCH BEGIN REPLACE_TEXTUALLY ~IF AttackedBy([GOODCUTOFF],DEFAULT) Allegiance(Myself,NEUTRAL)~ ~IF AttackedBy([GOODCUTOFF],DEFAULT) !Allegiance(Myself,ENEMY)~ REPLACE_TEXTUALLY ~IF AttackedBy([GOODCUTOFF],DEFAULT) !Allegiance(Myself,ENEMY)~ ~IF AttackedBy([GOODCUTOFF],DEFAULT) !Allegiance(Myself,ENEMY) HPPercentGT(Myself,50) CheckStat(LastAttackerOf,14,CHR) THEN RESPONSE #1 RESPONSE #7 Enemy() END IF AttackedBy([GOODCUTOFF],DEFAULT) !Allegiance(Myself,ENEMY) HPPercentGT(Myself,50) CheckStat(LastAttackerOf,15,CHR) THEN RESPONSE #2 RESPONSE #7 Enemy() END IF AttackedBy([GOODCUTOFF],DEFAULT) !Allegiance(Myself,ENEMY) HPPercentGT(Myself,50) CheckStat(LastAttackerOf,16,CHR) THEN RESPONSE #3 RESPONSE #8 Enemy() END IF AttackedBy([GOODCUTOFF],DEFAULT) !Allegiance(Myself,ENEMY) HPPercentGT(Myself,50) CheckStat(LastAttackerOf,17,CHR) THEN RESPONSE #4 RESPONSE #9 Enemy() END IF AttackedBy([GOODCUTOFF],DEFAULT) !Allegiance(Myself,ENEMY) HPPercentGT(Myself,50) CheckStat(LastAttackerOf,18,CHR) THEN RESPONSE #5 RESPONSE #10 Enemy() END IF AttackedBy([GOODCUTOFF],DEFAULT) !Allegiance(Myself,ENEMY) HPPercentGT(Myself,50) CheckStatGT(LastAttackerOf,18,CHR) THEN RESPONSE #6 RESPONSE #10 Enemy() END IF AttackedBy([GOODCUTOFF],DEFAULT) !Allegiance(Myself,ENEMY)~ END BUT_ONLY Quote Link to comment
Lauriel Posted May 23, 2020 Share Posted May 23, 2020 (edited) It's the brackets. Use REPLACE_TEXTUALLY EXACT_MATCH edit: add CASE_INSENSITIVE just to be on the safe side. Edited May 23, 2020 by Lauriel Quote Link to comment
Lauriel Posted May 23, 2020 Share Posted May 23, 2020 Sorry, didn't see the multiple lines. I'd not put in the IF for certain. Replace textually doesn't work well with that sort of thing, I've noticed. Make it as small as possible. Like REPLACE_TEXTUALLY ~Allegiance(Myself,NEUTRAL)~ ~!Allegiance(Myself,ENEMY)~ Quote Link to comment
Lauriel Posted May 23, 2020 Share Posted May 23, 2020 Look at @DavidW's alter_script.tpa library. It has a lot of wonderful macros for altering scripts. I think REPLACE_SCRIPT_BLOCK would do exactly what you need to do. Quote Link to comment
temnix Posted May 24, 2020 Author Share Posted May 24, 2020 This isn't about replacing blocks, though. Inserting blocks, maybe, in the more important longer addition. Quote Link to comment
Lauriel Posted May 24, 2020 Share Posted May 24, 2020 Well, then try the delete and insert macros. Those macros of his will accomplish what you need. Quote Link to comment
Ardanis Posted May 24, 2020 Share Posted May 24, 2020 (edited) DECOMPILE_AND_PATCH BEGIN REPLACE_TEXTUALLY ~IF AttackedBy([GOODCUTOFF],DEFAULT) Allegiance(Myself,NEUTRAL)~ You need to \ the square brackets, to make WeiDU recognize them as literal characters rather than expression: DECOMPILE_AND_PATCH BEGIN REPLACE_TEXTUALLY ~IF AttackedBy(\[GOODCUTOFF\],DEFAULT) Allegiance(Myself,NEUTRAL)~ Edited May 24, 2020 by Ardanis Quote Link to comment
temnix Posted May 24, 2020 Author Share Posted May 24, 2020 23 minutes ago, Ardanis said: DECOMPILE_AND_PATCH BEGIN REPLACE_TEXTUALLY ~IF AttackedBy([GOODCUTOFF],DEFAULT) Allegiance(Myself,NEUTRAL)~ You need to \ the square brackets, to make WeiDU recognize them as literal characters rather than expression: DECOMPILE_AND_PATCH BEGIN REPLACE_TEXTUALLY ~IF AttackedBy(\[GOODCUTOFF\],DEFAULT) Allegiance(Myself,NEUTRAL)~ If that works, I might end up making the little mod I was thinking of. Thanks anyway, Ardanis. The macros would be too complicated. Quote Link to comment
temnix Posted June 22, 2020 Author Share Posted June 22, 2020 On 5/25/2020 at 2:00 AM, Ardanis said: DECOMPILE_AND_PATCH BEGIN REPLACE_TEXTUALLY ~IF AttackedBy([GOODCUTOFF],DEFAULT) Allegiance(Myself,NEUTRAL)~ You need to \ the square brackets, to make WeiDU recognize them as literal characters rather than expression: DECOMPILE_AND_PATCH BEGIN REPLACE_TEXTUALLY ~IF AttackedBy(\[GOODCUTOFF\],DEFAULT) Allegiance(Myself,NEUTRAL)~ Okay, this is for a different script, but I get an "empty token error" now. By the way, Ardanis, your code suggestion here - are you sure the \s are in the right place? Shouldn't it be \[GOODCUTOFF]\ ? Anyhow, the error I get is in this: COPY_EXISTING ~SHOUT.BCS~ ~override~ DECOMPILE_AND_PATCH BEGIN REPLACE_TEXTUALLY ~Heard(\[NOTEVIL\],99)~ <<< ~Heard(\[NOTEVIL\],99) Detect(LastHeardBy)~ REPLACE_TEXTUALLY ~Heard(\[NOTGOOD\],99)~ ~Heard(\[NOTGOOD\],99) Detect(LastHeardBy)~ END BUT_ONLY Quote Link to comment
Lauriel Posted June 22, 2020 Share Posted June 22, 2020 Will REPLACE_TEXTUALLY EXACT_MATCH work in this case? Quote Link to comment
Ardanis Posted June 22, 2020 Share Posted June 22, 2020 (edited) 7 hours ago, temnix said: By the way, Ardanis, your code suggestion here - are you sure the \s are in the right place? Shouldn't it be \[GOODCUTOFF]\ ? I am - special characters need to be preceded by \, to reverse them as a part of regexp formula. 7 hours ago, temnix said: Okay, this is for a different script, but I get an "empty token error" now. A-aand it only needs to be done when matching the string COPY_EXISTING ~SHOUT.BCS~ ~override~ DECOMPILE_AND_PATCH BEGIN REPLACE_TEXTUALLY ~Heard(\[NOTEVIL\],99)~ ~Heard([NOTEVIL],99) Detect(LastHeardBy)~ REPLACE_TEXTUALLY ~Heard(\[NOTGOOD\],99)~ ~Heard([NOTGOOD],99) Detect(LastHeardBy)~ END BUT_ONLY IIRC the only regexp allowed in replacement string is \1, \2 etc. to denote a match variable: REPLACE_TEXTUALLY ~\(Heard\)~ ~True() \1~ // WeiDu will substitute \1 with whatever has been matched by the first \(\) expression, \2 - with the second etc. As you can see, in case of match expression the parenthesis and numbers get preceded by \, to mark them as regexp and not part of a string. Fun, huh? Edited June 22, 2020 by Ardanis Quote Link to comment
critto Posted June 22, 2020 Share Posted June 22, 2020 I'll just chime in and say that sometimes a space symbol is not just a space symbol, especially at the end of the line. You might get a lot of headache trying to figure this out, since the files could've been saved under different operating systems and have various hidden line termination symbols applied, etc. To match any space symbol this snippet could be used: [ %TAB%%LNL%%MNL%%WNL%]+ This matches a group consisting of one or more spaces, tab characters or linux/mac/windows new line symbols. Enjoy. Quote Link to comment
DavidW Posted June 22, 2020 Share Posted June 22, 2020 I've taken to just doing REPLACE_TEXTUALLY "\(%TAB\|%LNL%\|%MNL%\|%WNL%\)" " " before doing any complicated search-and-replace on a BCS file. Quote Link to comment
Lauriel Posted June 22, 2020 Share Posted June 22, 2020 Seriously...just use exact_match. Much easier if you don't have multiple lines and spaces and such. REPLACE_TEXTUALLY CASE_INSENSITIVE EXACT_MATCH ~Clicked([ANYONE])~ ~Clicked([ANYONE]) !Global("#L_SarvQuests","GLOBAL",8)~ The above works perfectly without any special characters. Quote Link to comment
Recommended Posts
Join the conversation
You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.