• Our software update is now concluded. You will need to reset your password to log in. In order to do this, you will have to click "Log in" in the top right corner and then "Forgot your password?".
  • Welcome to PokéCommunity! Register now and join one of the best fan communities on the 'net to talk Pokémon and more! We are not affiliated with The Pokémon Company or Nintendo.

[Other✓] Adding new lines to an existing script

  • 14
    Posts
    9
    Years
    • Seen Feb 26, 2016
    Hi Guys

    I'm having trouble adding new lines to existing scripts, and I'm wondering if it's just because you can't. I have a script that I want to run early in the rom which will set various flags and variables for scripts later in the rom. I want to be able to add flags and variables to the script as I go, but it seems that if I try to make a new line through XSE it either just won't add it after compiling it, or adds a few lines of completely unrelated script. It works perfectly fine if I am just replacing an existing line.

    Is there a particular way to add new lines, or will I need to put 50 lines of the same script (like 50 lines of "checkflag 0x2000" or something similar) and replace them as I go? It's not just this particular script that I have had trouble with, but every script where I have tried adding a new line which makes me think you cannot add new lines.
     
  • 202
    Posts
    14
    Years
    • Seen Jan 6, 2017
    Wow 50? There's really no need to have that many. You can re-use the same VAR so many times.

    And any more VARs and Flags you need later on, you can easily just put in a level script on or before the map they're needed.

    But yeah you're right, you can't add onto an existing script. To change it you either need to create a new dynamic offset for it, or make sure you keep it exactly the same size or smaller.

    So yeah you can add 50 blank setflags/vars.


    There's really no need to set a var at the start though. If you make the script you don't want to run yet's "Var Number" in Advancemap the variable you want to have set later on, and the "Var Value" as 0001, then the script won't run until Var you put in "Var Number" has been set to 0x1.

    An example:

    In "Town 1" I have a script that is set as with a Var Number of "4055" and Var Value of "0001"

    Nothing will happen when I go over the script.

    Then in "Town 2" I have a script that is set with a Var Number of "4055" and a Var Value or "0000"

    Because Var 4055 is 0 by default, this script will trigger. Now at the end of this script, I use the command "Setvar 4055 0x1"

    Now if I try to trigger the even in Town 2 again, it won't because the Var Value is different now.

    But if I go back to "Town 1", the script will run now, because it required 4055 to have a value of 1.


    Now, to use the same var again, we'll set a script in "Town 3" with a Var Number of "4055" and a Var Value of "0002".

    If in the end of the "Town 1" script we have the command "Setvar 4055 0x2", then the script in "Town 3" will run, but not before. Also, once Setvar 4055 is 0x2, neither the script in "Town 1" or "Town 2" will run, and only the one in "Town 3" will.


    I hope I didn't make that too complicated for you haha.
     
  • 8
    Posts
    9
    Years
    Well you have to be carefull with adding new lines, since that increases the size of the script.
    And since there is usually another script that comes after it you would overwrite that one. The same goes for any "#org" lines within your script.

    It could be possible to avoid this, by outsourcing your script (or however that is called).
    Basically you replace a line in the script by a call command (hope that is the right one, haven't used it yet) and this call then opens a different script that has enough free space. In this new script you first write the line you replaced, then write whatever you want and finally return to the place you left off. I haven't done this so far, so it might work a little different, but that is the basic idea behind it.

    example:
    Imagine this is your original script (or a part of it) and you want to add new orders after the red line:
    Code:
    #org 0xE3EA68
    msgbox 0x8E3EABB MSG_NORMAL //"Now don't get startled"
    applymovement MOVE_PLAYER 0x8E3EBCE
    waitmovement 0x0
    [COLOR=Red]msgbox 0x8E3EAD4 MSG_NORMAL //"Why do humans always react like\nt..."[/COLOR]
    setflag 0xAAAC
    release
    end
    so you replace the red line with
    Code:
    call 0x800000
    or whereever your replacement script is found.

    the replacement might then look like this:
    Code:
    #org 0x800000
    [COLOR=Red]msgbox 0x8E3EAD4 MSG_NORMAL //"Why do humans always react like\nt..."[/COLOR]
    fanfare 0x13E 
    msgbox @3 0x4 
    waitfanfare
    return
    You can also insert your new script in front of the replaced lines, this is determined by where you place them in your new script.


    Be carefull
    , the call command needs 5 Bytes, the msgbox needs 8, so there is no problem here. But the setflag would only need 3 Bytes, so if you want to replace it with a call you need to replace at least one additional line, until the deleted lines give you enough space for the call.
    In this case you would need to replace "release" and "end" as well (both 1 byte).
    You might want add some nop lines (1 byte, no function) after the call to have it exactly the same size as the deleted lines.

    Hope this was understable and correct, as I haven't made my way to the call command yet.
     
    Last edited:
  • 202
    Posts
    14
    Years
    • Seen Jan 6, 2017
    Good addition by Kasimel there.

    There are two ways of doing what he mentioned, the call command like he said, which calls another script, or the goto command, which goes to another script.

    Example of call:

    #dynamic 0x800000
    #org @start
    lock
    faceplayer
    msgbox @blah 0x6
    call @secondscript
    release
    end

    #org @secondscript
    setflag 0x105
    return


    See, this one "calls" the second script, which need you to return back to the original script where it will continue where it left off. This one is mostly used if you want the @secondscript to be used more than once in the script. If you want an advanced example of this just ask.

    An example of goto:

    #dynamic 0x800000
    #org @start
    lock
    faceplayer
    msgbox @blah 0x6
    goto @secondscript

    #org @secondscript
    setflag 0x105
    release
    end

    Now the difference here is at the end of the @start script, there is no "release end", because there's no need as that script will never be finished, as it "goes to" another script and isn't returned to.

    Of course the other difference is the second script has a "release end" instead of returning to the original script.
     

    Blah

    Free supporter
  • 1,924
    Posts
    11
    Years
    Well you have to be carefull with adding new lines, since that increases the size of the script.
    And since there is usually another script that comes after it you would overwrite that one. The same goes for any "#org" lines within your script.

    It could be possible to avoid this, by outsourcing your script (or however that is called).
    Basically you replace a line in the script by a call command (hope that is the right one, haven't used it yet) and this call then opens a different script that has enough free space. In this new script you first write the line you replaced, then write whatever you want and finally return to the place you left off. I haven't done this so far, so it might work a little different, but that is the basic idea behind it.

    example:
    Imagine this is your original script (or a part of it) and you want to add new orders after the red line:
    Code:
    #org 0xE3EA68
    msgbox 0x8E3EABB MSG_NORMAL //"Now don't get startled"
    applymovement MOVE_PLAYER 0x8E3EBCE
    waitmovement 0x0
    [COLOR=Red]msgbox 0x8E3EAD4 MSG_NORMAL //"Why do humans always react like\nt..."[/COLOR]
    setflag 0xAAAC
    release
    end
    so you replace the red line with
    Code:
    call 0x800000
    or whereever your replacement script is found.

    the replacement might then look like this:
    Code:
    #org 0x800000
    [COLOR=Red]msgbox 0x8E3EAD4 MSG_NORMAL //"Why do humans always react like\nt..."[/COLOR]
    fanfare 0x13E 
    msgbox @3 0x4 
    waitfanfare
    return
    You can also insert your new script in front of the replaced lines, this is determined by where you place them in your new script.


    Be carefull
    , the call command needs 5 Bytes, the msgbox needs 8, so there is no problem here. But the setflag would only need 3 Bytes, so if you want to replace it with a call you need to replace at least one additional line, until the deleted lines give you enough space for the call.
    In this case you would need to replace "release" and "end" as well (both 1 byte).
    You might want add some nop lines (1 byte, no function) after the call to have it exactly the same size as the deleted lines.

    Hope this was understable and correct, as I haven't made my way to the call command yet.

    This is a good way to do it if you're inserting in the middle. Otherwise I'd just append a "jump" right before "release end" to a new script of whatever it is that you needed to add and just compile.

    That being said, it's probably a good idea to just make your own script (especially if you're changing so much of it). I mean, running out of space isn't really an issue.
     

    Joexv

    ManMadeOfGouda joexv.github.io
  • 1,037
    Posts
    11
    Years
    This is a good way to do it if you're inserting in the middle. Otherwise I'd just append a "jump" right before "release end" to a new script of whatever it is that you needed to add and just compile.

    That being said, it's probably a good idea to just make your own script (especially if you're changing so much of it). I mean, running out of space isn't really an issue.

    Lol that is definately not true. I ran out of space the other day.XD
     
  • 14
    Posts
    9
    Years
    • Seen Feb 26, 2016
    Thanks guys. Its good to know i'm not doing something wrong.

    I had tried doing what Nikolai Fox suggested on a previous script, but the only way it would work is if the var started at 0000 and then a script tile set it to 0001 early in the rom, to then be set to 0000 later on when i wanted it to run. I spent hours and hours trying to figure out what was going wrong, and I just don't have the time to do that for every script. The method I am going to use is basically just a safe way of me making sure it works.

    cheers guys.
     
  • 202
    Posts
    14
    Years
    • Seen Jan 6, 2017
    Wait setting the var to 0001 and having a script setvar 0x0001 didn't work?

    It should have. Glitched map maybe?
     
  • 14
    Posts
    9
    Years
    • Seen Feb 26, 2016
    Wait setting the var to 0001 and having a script setvar 0x0001 didn't work?

    It should have. Glitched map maybe?

    I think it was something to do with it being a header script. It worked ok when it was on a script tile, but when it was a header script it would either freeze when the script was set to not run, or make the screen black when it was set to run. I've had that happen on other header scripts too and I can't figure out why.
     
  • 8
    Posts
    9
    Years
    I think it was something to do with it being a header script. It worked ok when it was on a script tile, but when it was a header script it would either freeze when the script was set to not run, or make the screen black when it was set to run. I've had that happen on other header scripts too and I can't figure out why.

    Maybe this will help (I got frustrated by header scripts too, so I bookmarked it :D).
    pokecommunity.com/showthread.php?t=191500 (can't insert links, sry)
    The interesting part starts at the two ingame pictures.


    Make sure to check the button with the single black wrench in the topright of the XSE when decompiling the "map script offset", I missed that and wasted soooo much time trying to figure out the problem.
     
    Back
    Top