Jump to content

A REPLACE_TEXTUALLY problem


temnix

Recommended Posts

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


    

Link to post

It's the brackets.  Use REPLACE_TEXTUALLY EXACT_MATCH

edit: add CASE_INSENSITIVE just to be on the safe side.

Edited by Lauriel
Link to post

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)~

Link to post
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 by Ardanis
Link to post
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.

Link to post
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
 

Link to post
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 by Ardanis
Link to post

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.

Link to post

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.

Link to post
Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...