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

[Script✓] [AdvanceMap/XSE] Map/level scripts not running when they use the same variable with different value.

17
Posts
5
Years
    • Seen Sep 23, 2020
    I've run into an issue with the Map Scripts section in Advance map.
    I want a script to execute when the player enters a house, and a variable is equal to either 1, 2 or 3. (Afterwards, the variable will be set to 4)

    So I added 3 map scripts, each checking the value of variable 4055:
    [AdvanceMap/XSE] Map/level scripts not running when they use the same variable with different value.
    (the only difference is map script number, the variable and value)

    However, only script #1 will execute.
    • If 0x4055 equals to 1, the script will run.
    • But if 0x4055 equals to 2 or 3, the script won't run.
    • If I set the value box for script #1 to 0002 or 0003, the script will run when 0x4055 is either 2 or 3, respectively.
    So the problem seems to be that it only compares the variable against the value of the first script, then ignores the other two?

    Any ideas how I can fix this?

    Spoiler:
     
    Last edited:
    14
    Posts
    3
    Years
    • Seen Jul 29, 2021
    If you want a level script to run differently according to variable values, just put that in the script proper.

    So you would have two variables, one 4055 (for the levelscript) and one 4056 (the thing you're calculating) all in one script:

    setvar 0x4055 0x1 (<- this is the var for the levelscript proper)

    and then:

    compare 0x4056 0x1 (<- this is the variable you're comparing against + the value you're comparing)
    if 0x1 goto @pointer1

    the above would lead to a script for var 0x4056 set at 1.

    Then you'd have:
    compare 0x4056 0x2
    if 0x1 goto @pointer2

    and:
    compare 0x4056 0x3
    if 0x1 goto @pointer3

    I should disclaim I'm pretty new to all this so if someone has a more elegant solution, I'm all ears. :)
     
    990
    Posts
    4
    Years

  • The above solution may work, but you can also put only one script there, and use the compare or checkflag commands in that script to execute all the other scripts which are in small snippets. And I'm not sure, but I think the variable 0x4055 is used.
     
    17
    Posts
    5
    Years
    • Seen Sep 23, 2020
    If you want a level script to run differently according to variable values, just put that in the script proper.

    So you would have two variables, one 4055 (for the levelscript) and one 4056 (the thing you're calculating) all in one script:

    setvar 0x4055 0x1 (<- this is the var for the levelscript proper)

    and then:

    compare 0x4056 0x1 (<- this is the variable you're comparing against + the value you're comparing)
    if 0x1 goto @pointer1

    the above would lead to a script for var 0x4056 set at 1.

    Then you'd have:
    compare 0x4056 0x2
    if 0x1 goto @pointer2

    and:
    compare 0x4056 0x3
    if 0x1 goto @pointer3

    I should disclaim I'm pretty new to all this so if someone has a more elegant solution, I'm all ears. :)

    Thanks for the reply! The thing is, I'm trying to solve this without using a second variable if possible.
    The script will run exactly the same no matter if 0x4055 is 1, 2, or 3, it's just that i'm having trouble triggering the script in the header section in Advance Map, since it requires to check a variable against a specific value. And for some reason I can't check it against 3 different values (like i tried to do in the screenshot of the original post).




    The above solution may work, but you can also put only one script there, and use the compare or checkflag commands in that script to execute all the other scripts which are in small snippets. And I'm not sure, but I think the variable 0x4055 is used.

    I tried putting only 1 map script there and then check the value of the variable from within the script, but then I had to use Script Type 03 to make it trigger regardless of the variable's value.
    However, since my script uses movement code, the game will freeze if I don't use Script Type 02 or 04 and supply a variable there.

    also yeah, 4055 is used by vanilla FireRed at the start of the game:
    Spoiler:
     
    Last edited:
    17
    Posts
    5
    Years
    • Seen Sep 23, 2020
    I managed to get it working!
    I'll post the solution in case anyone else has this issue in the future.
    I had to decompile the map script code generated by Advance Map and make some changes to it.

    First, I added a map script with advance map:
    [AdvanceMap/XSE] Map/level scripts not running when they use the same variable with different value.

    Then, went to the "professional header menu" by pressing Ctrl+H so I could find and copy the map script offset:
    [AdvanceMap/XSE] Map/level scripts not running when they use the same variable with different value.

    Then i opened XSE, pasted the offset (1), pressed the level script button (2), and then pressed decompile (3).
    [AdvanceMap/XSE] Map/level scripts not running when they use the same variable with different value.

    The relevant code will look something like this:
    (i added some comments to describe the lines)
    Code:
    '---------------
    #org 0x71A334              '<--- the map script offset
    #raw 0x2              '<--- script type 02
    #raw pointer 0x871A3F1     '<--- pointer to script offset
    #raw 0x0
    
    '---------------
    #org 0x71A3F1
    #raw word 0x4055              '<--- the variable to check
    #raw word 0x1               '<--- the value to compare against
    #raw pointer 0x8800440        '<--- pointer to my custom script
    #raw word 0xFFFF               '<---- bad line of code

    First off, Advance Map messes up the last line (#raw word 0xFFFF).
    Normally it has to end in 0x0 instead of 0xFFFF or you will run into issues.
    But in this case I needed to add more variable checks because I needed it to check if variable 4055 is either 1, 2 or 3.

    So I changed the code to this:
    Code:
    '---------------
    #org 0x71A334
    #raw 0x2
    #raw pointer [B]0x88004C0[/B]
    #raw 0x0
    
    '---------------
    #org [B]0x8004C0[/B]
    #raw word 0x4055
    #raw word 0x1              '<--- check if var 4055 is 1
    [B]#raw pointer 0x8800440
    #raw word 0x4055
    #raw word 0x2[/B]              '<--- check if var 4055 is 2[B]
    #raw pointer 0x8800440
    #raw word 0x4055
    #raw word 0x3[/B]              '<--- check if var 4055 is 3[B]
    #raw pointer 0x8800440
    #raw word 0x0[/B]

    Before compiling this, I had to change the pointer 0x71A3F1 to prevent overwriting data, so I changed it to 0x8004C0 after finding free space.
    After that, all that was left to do was to compile it!


    In all honesty, I have little experience with this and solved it through trial and error, and by simply guessing this might be possible.
    All I know is that this worked for me, but if anybody else has a different solution, don't be afraid to post it!
     
    Last edited:
    17
    Posts
    5
    Years
    • Seen Sep 23, 2020
    Oh, I thought you had already done that part. Yes, before executing a level script in-game, you have to do those steps. I'm 100% sure there is a Level Script tutorial somewhere.

    Yeah I had done the part where I change 0xFFFF to 0x0 to make the level script work properly. I just wanted to write down the full steps in this thread :p.
    But none of the tutorials I found had any information about the part where I compared against multiple values of a variable, so that's where i originally got stuck
     
    Back
    Top