Community
    • Login

    Add the same amount to every selected value?

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    23 Posts 5 Posters 3.6k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Diz HydronD
      Diz Hydron
      last edited by

      Hi! Thanks for getting back to me!

      I’m having a little bit of trouble understanding what you’re saying, but I think I get the gist. If it finds values instead of selecting them then I’m not too sure it would work. I have a lot of values and many of them are the same, but I need to be specific about which change. Here’s a bit more of what I’m working with.

      4.PNG

      What I’m trying to do is to quickly be able to change every X or Y value for player 1 or 2 by a set amount and speed up the workflow.

      the values after player 1 and 2 define X and Y values. If I told the program to find every instance of 15 and add 100 for example, then it would presumably change the values for player 1 and 2. I could try and define it as “player1”: [ then the value afterward, but I’d need to type that out for every value I’d want to change and that takes as much work, if not more than just changing them manually. Unless there’s some way to define a chunk of characters as a variable. For example, “player1”: [X where X = every character prior to the , that separates the X from Y co-ordinate. Y may be possible too if I can exclude chunks of characters as in “player1”: [X, Y where X is any characters between [ and , and Y is the value to be changed.

      I don’t even know if groupings of characters is definable in python. I just said it because I could see things getting complicated with double/triple-digit and negative numbers. From what you’re saying though it sounds like I’d need to manually put in “player1”: [ for every player 1 X value in order to get this mehtod to work. At that point, it’s slower than just adding a set amount to each value manually.

      Alan KilbornA 1 Reply Last reply Reply Quote 0
      • Alan KilbornA
        Alan Kilborn @Diz Hydron
        last edited by Alan Kilborn

        @diz-hydron

        If you search for this, you’ll see it only hits player1 values:

        Find: "player1": \\[\K-?\d+
        Search mode: Regular expression

        That might be the key to understanding enough for the scripted solution shown above to do the job for you.

        1 Reply Last reply Reply Quote 0
        • Diz HydronD
          Diz Hydron
          last edited by

          I don’t know how to properly implement the string you provided, but I gave it a shot. Didn’t do anything when I ran the script.

          test.PNG

          Here’s what I have. I’m guessing I need to do something in line 3.

          Neil SchipperN 1 Reply Last reply Reply Quote 0
          • Neil SchipperN
            Neil Schipper @Diz Hydron
            last edited by

            @diz-hydron Alan’s intention was that you revise the search criteria in the editor.rereplace function call (which identifies every instance of the targeted numeric fields to undergo the math operation and replacement).

            In other words, go back to the original script you showed (after “Ok, Everything is installed…”) and replace line 9 with editor.rereplace('"player1": \[\K-?\d+')

            Didn’t see anything like that in the FAQ linked by PeterJonez.

            Although he is a rapper by night, in this forum we try to stick with his daytime persona, that of a software professional.

            Neil SchipperN PeterJonesP 2 Replies Last reply Reply Quote 0
            • Diz HydronD
              Diz Hydron
              last edited by

              Is this correct? Still doesn’t seem to be doing anything when I try to run it. Then again, maybe my attempts at running it/defining the values are the problem. I know nothing about python.

              5.PNG

              Also, my apologies for the typo. It was not intentional, nor was it my intention to offend.

              Neil SchipperN 2 Replies Last reply Reply Quote 0
              • Neil SchipperN
                Neil Schipper @Diz Hydron
                last edited by

                @diz-hydron Let’s just first verify core functionality by asking the script to do something very simple: use '47' inside the parentheses, and see if the 47 for player1 under singRIGHT line undergoes the change.

                Also, it’s much preferred that you place your scripts in

                a literal text box like this
                

                using lines with triple backquotes as explained here; look for Literal Text Blocks and Red Typewriter Text. It’s preferred over images because it enables text copying while also protecting against being altered by this forum’s software.

                Also, my apologies for the typo. It was not intentional, nor was it my intention to offend.

                I was only being silly. Some typos are too delicious to pass over without comment.

                Neil SchipperN 1 Reply Last reply Reply Quote 0
                • Neil SchipperN
                  Neil Schipper @Diz Hydron
                  last edited by

                  @diz-hydron Also, if you want to apologize for a typo, here’s a much better candidate: in your prior attempt, the (much needed) backslash before the left brace is missing.

                  1 Reply Last reply Reply Quote 0
                  • Neil SchipperN
                    Neil Schipper @Neil Schipper
                    last edited by

                    @neil-schipper said in Add the same amount to every selected value?:

                    while also protecting against being altered by this forum’s software

                    Yeah, annoyingly and amusingly, there’s a flaw in that text box rendering code, and it impacts text that’s part of this discussion:

                    unfortunately, <backslash><left brace> renders as: \[
                    so you need <backslash><backslash><left brace> in order to make this appear: \\[
                    
                    1 Reply Last reply Reply Quote 0
                    • Neil SchipperN
                      Neil Schipper @Neil Schipper
                      last edited by

                      @neil-schipper said in Add the same amount to every selected value?:

                      In other words, go back to the original script you showed (after “Ok, Everything is installed…”) and replace line 9 with editor.rereplace(‘“player1”: [\K-?\d+’)

                      Oh, heck, it was me that introduced the dropped backslash…

                      editor.rereplace('"player1": \\[\K-?\d+')

                      Alan KilbornA 1 Reply Last reply Reply Quote 1
                      • Alan KilbornA
                        Alan Kilborn @Neil Schipper
                        last edited by Alan Kilborn

                        @neil-schipper said in Add the same amount to every selected value?:

                        editor.rereplace(‘“player1”: \[\K-?\d+’)

                        Because it includes backslashes, probably want this instead:

                        editor.rereplace(r'"player1": \\[\K-?\d+')

                        (note the leading r)

                        1 Reply Last reply Reply Quote 2
                        • Diz HydronD
                          Diz Hydron
                          last edited by

                          I appreciate all the help! I’ll need to get to this a bit later though. Busy day today.

                          In the meantime, I’d like to make sure that I’m not trying to drive the car without the key and make sure I understand how to run a plugin in the first place.

                          First, I go plugins/python script/new script. Then, I populate the file with the script I want to run and save it to the scripts folder. Finally, I open the text that I want the script to change, use a shortcut key as described in the FAQ, or run it by selecting plugins/python script/scripts/“Custom Script” Then if the script works, it should apply the change.

                          Is my understanding of that part correct? I can take a closer look at fixing the script itself a bit later.

                          Alan KilbornA 1 Reply Last reply Reply Quote 1
                          • Alan KilbornA
                            Alan Kilborn @Diz Hydron
                            last edited by

                            @diz-hydron said in Add the same amount to every selected value?:

                            Is my understanding of that part correct?

                            Sounds right, although for sure don’t bother with the shortcut key thing right out of the box. That would only be useful if this whole thing actually works for you, and if you need to do it multiple times. Just run the script from the menus to start with.

                            1 Reply Last reply Reply Quote 1
                            • PeterJonesP
                              PeterJones @Neil Schipper
                              last edited by

                              @neil-schipper said in Add the same amount to every selected value?:

                              he is a rapper by night,

                              I have never been accused of that particular moonlighting before…

                              @Diz-Hydron ,

                              Is my understanding of that part correct?

                              That seems a reasonable summary of the process.

                              If nothing happens, I would tell PythonScript to show the console, and you can look to see if there is an error message.

                              1 Reply Last reply Reply Quote 0
                              • guy038G
                                guy038
                                last edited by guy038

                                Hello, @diz-hydron and All,

                                Well, @diz-hydron, I suppose you could begin with this very simple script, named diz.py

                                def player_1(m):
                                    return str(int(m.group(1)) + X1) + ', ' + str(int(m.group(2)) + Y1)
                                
                                def player_2(m):
                                    return str(int(m.group(1)) + X2) + ', ' + str(int(m.group(2)) + Y2)
                                
                                editor.rereplace('"player1": \\[\K(-?[0-9]+), (-?[0-9]+)', player_1);
                                
                                editor.rereplace('"player2": \\[\K(-?[0-9]+), (-?[0-9]+)', player_2);
                                

                                Before running the script, of course, change the X1, Y1, X2 and Y2 values for true positive or negative integers ( e.g. +7 or -3 )

                                It should work nicely with your text posted here


                                In a next step, it would be better to enter the different values with, for instance, the notepad.prompt python command and assign the 4 typed numbers to the X1, X1, X2 and Y2 variables…

                                Best Regards,

                                guy038

                                1 Reply Last reply Reply Quote 0
                                • First post
                                  Last post
                                The Community of users of the Notepad++ text editor.
                                Powered by NodeBB | Contributors