Jump to content

Problems with REPLACE_TEXTUALLY, again


temnix

Recommended Posts

I need to add a casting of a special spell to all instances in dialogues where the NPC turns hostile in the end or commands others to turn hostile. I'm using this code:

COPY_EXISTING_REGEXP GLOB ~.*\.DLG~ ~override~

DECOMPILE_AND_PATCH BEGIN
REPLACE_TEXTUALLY CASE_INSENSITIVE EXACT_MATCH ~DO %Enemy()
% EXIT~ ~DO %ApplySpellRES("REPOFF_#",Myself) Enemy()% EXIT~
REPLACE_TEXTUALLY CASE_INSENSITIVE EXACT_MATCH ~DO %Enemy() %~ ~DO %ApplySpellRES("REPOFF_#",Myself) Enemy() %~
REPLACE_TEXTUALLY ~,Enemy())~ ~,Enemy()) ReallyForceSpellRES("REPOFF_#",Myself))~
END
BUT_ONLY

The second one includes a space near the end in case Enemy() is not the last action in the sequence, though it usually is. The last one is for ActionOverride, for cases where, say, Hobgoblin 1 does ActionOverride("hob2",Enemy()). Starting from the comma should cover all script names. But either I'm not writing these correctly or it's some funkiness with REPLACE again. Ideas?

Link to comment
Guest Gob Oafenplug

Percentage signs by themselves are just string delimiters; inside of other string delimiters they %EVALUATE_THE_VARIABLE%. In neither case are they doing anything for you in this code. Also,  depending on what you intend this REPOFF_# to do, you may want to apply it to the creature going hostile rather than repeatedly applying it to the creature performing the ActionOverride(). You'll need a regular expression match to do this.

 Something like this may be closer to what you're intending to do.

COPY_EXISTING_REGEXP GLOB ~^.+\.DLG$~ override
  COUNT_REGEXP_INSTANCES ~Enemy()~ enemy_num
  PATCH_IF enemy_num > 0 BEGIN
    DECOMPILE_AND_PATCH BEGIN
      REPLACE_TEXTUALLY "~Enemy()"                             %~Enemy() ApplySpellRES("REPOFF_#",Myself)%
      REPLACE_TEXTUALLY "^Enemy()"                             %Enemy() ApplySpellRES("REPOFF_#",Myself)%
      REPLACE_TEXTUALLY ~ActionOverride("\([^"]+\)",Enemy())~  ~ ReallyForceSpellRes("REPOFF_#","\1") ActionOverride("\1",Enemy())~
    END
  END
BUT_ONLY

 

Link to comment

Now I'm having trouble replacing an action. This bit of code should insert a special block before all StealFailed([ANYONE]) lines in scripts, and I put backslashes before the brackets, but it won't compile.

REPLACE_TEXTUALLY ~StealFailed(\[ANYONE\])~               ~IF
      StealFailed(\[ANYONE\])
      
      THEN
      
      RESPONSE #1
            
      ApplySpellRES("REPPR2_#",Player1)
      Continue()
      END
      
      IF
      StealFailed(\[ANYONE\])~

Edited by temnix
Link to comment

Get rid of the backslashes in the second (replacement) string. They're there to indicated that [ and ] are being quoted directly and not used as special characters, but you don't need to do that in the replacement string because it can't contain special characters anyway.

Link to comment

Yes, and I had an extra IF in the substituting string, this is why it wasn't compiling. But now I have gotten rid of all that, and compiling happens, only nothing changes in the end. I used an extra bit you have recommended for spaces. Neither of this changes ought:

REPLACE_TEXTUALLY "\(%TAB\|%LNL%\|%MNL%\|%WNL%\)" " "
REPLACE_TEXTUALLY CASE_INSENSITIVE EXACT_MATCH ~IF
    StealFailed([ANYONE])~ ~IF
      
      StealFailed([ANYONE])
      
      THEN
      
      RESPONSE #1
            
      ApplySpellRES("REPPR2_#",Player1)
      Continue()
      END
      
      IF
      
      StealFailed([ANYONE])~

And

REPLACE_TEXTUALLY "\(%TAB\|%LNL%\|%MNL%\|%WNL%\)" " "
REPLACE_TEXTUALLY ~IF
    StealFailed(\[ANYONE\])~ ~IF
      
      StealFailed([ANYONE])
      
      THEN
      
      RESPONSE #1
            
      ApplySpellRES("REPPR2_#",Player1)
      Continue()
      END
      
      IF
      
      StealFailed([ANYONE])~

I just gotta love this code. It compiles so smoothly and "successfully installed"! And doesn't change jack shit.

Link to comment

This has come up again. I'm replacing PartyGold(...) and its LT and GT versions, in dialogues, with CheckStat(LastTalkedToBy,...,GOLD). The private purse instead of the party pool. This is the code I'm using, and nothing is getting changed after it, example:

REPLACE_TEXTUALLY ~\bPartyGoldGT(\([.]+\))~ %CheckStatGT(LastTalkedToBy,\1,GOLD)%

\b In the beginning, for start of the word, is to prevent replacement of the GivePartyGold action. Why does this fail? The first parenthesis in the matched expression is there, the final paranthesis is also real, between them is a regular expression: \([.]+\) Seems in order to me. With this code Weidu complains of "spurious \\ in regulation expression."

Edited

 

Edited by temnix
Link to comment

@qwerty1234567So you are saying there is no problem? I wish it were so, but Weidu doesn't agree. Or do you mean that . is a literal fullstop? Not in Weidu's code it isn't. See the documentation: 

.      matches any character except newline

 

Edited by temnix
Link to comment

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.

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...