• Just a reminder that providing specifics on, sharing links to, or naming websites where ROMs can be accessed is against the rules. If your post has any of this information it will be removed.
  • Ever thought it'd be cool to have your art, writing, or challenge runs featured on PokéCommunity? Click here for info - we'd love to spotlight your work!
  • Our weekly protagonist poll is now up! Vote for your favorite Conquest protagonist in the poll by clicking here.
  • 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.

Using variables for wildbattle?

  • 3
    Posts
    5
    Years
    • Seen Nov 25, 2019
    I am trying to, for the purposes of my problem, debug part of a script that generates a random shiny to battle. The game immediately crashes when after waitcry. I have no idea why this is or how to fix this. Anyone try working with random numbers on wildbattle here before? Will I have to do each individual pokemon or will this have a workaround. I made an account to ask this question, im somewhat new to actually romhacking but not new to the concepts in it.

    #org @gen2
    callasm 0x9C0B21
    setvar 0x8003 0x1
    random 0x60
    addvar LASTRESULT 0x97
    cry LASTRESULT 0x0
    waitcry
    wildbattle LASTRESULT 0x32 0x0
    setflag 0x930
    release
    end
     
    Last edited:
    The wildbattle command doesn't appear to accept variables at all despite having word parameters. This means that its taking the parameter at face value and trying load the 32781th (0x800D) Pokemon which is obviously a bad idea. There are other commands that don't accept variables, but they're not used often so it isn't an issue that regularly comes up. Interestingly in this case, Emerald crashes, but you have a battle with a ??? Pokemon in FR.

    Anyway, whenever you come across a scripting command that needs a word-sized parameter but won't accept variable values, the best scripting-related option is to use eval. It will allow you to read directly from the RAM, where you have the value of your variable and can directly read from it. The thread I linked does a far better job of explaining it, so here's a confirmed working example of what you're trying to achieve:

    Code:
    #org @Gen2
    setvar 0x8000 0xB600
    random 0x60
    copyvar 0x8001 0x800D
    addvar 0x8001 0x97
    setvar 0x8002 0x0032
    setvar 0x8003 0x0300
    call 0x020375D8 // Beginning of variable 0x8000 in Emerald
    dowildbattle
    release
    end

    By setting the variables up like this, we've created the following commands in the RAM, with XXXX being whatever the value of 0x8001 is:

    Code:
    nop // 00
    setwildbattle 0x8001 0x32 0x0000 // B6 XXXX 32 0000
    return // 03

    The nop byte at the start is needed in order to align the command with the contents of 0x8001 so you'll need to keep it in there. Good luck with your hack!
     
    Last edited:
    Thank you so much! I had a feeling thats what I was calling, and i certainly dont have 37000 pokemon...
    I have to rearrange some variables since 0x8003 is used by shinyzer, but now its feasible.
     
    Last edited:
    Heres the full script [emerald] if anyone wanted to use it in their games:

    Code:
    #dynamic 0x800000
    
    #org @start
    lock
    checkdailyflags
    checkflag 0x930 // This is a berry girl I got rid of to take her daily flag.
    if 0x1 goto @nope
    msgbox @prompt 0x5
    compare LASTRESULT 0x1
    if 0x1 goto @yes
    msgbox @cancel 0x6
    release
    end
    
    #org @nope
    msgbox @cant 0x6
    release
    end
    
    #org @cant
    = You can't throw money in right\nnow.
    
    #org @prompt
    = Toss a coin into the fountain?
    
    #org @yes
    checkmoney 0x1 0x0
    compare LASTRESULT 0x1
    if 0x0 goto @nope
    paymoney 0x1 0x0
    random 0x03
    compare LASTRESULT 0x0
    if 0x1 goto @gen1
    compare LASTRESULT 0x1
    if 0x1 goto @gen2
    compare LASTRESULT 0x2
    if 0x1 goto @gen3
    
    #org @gen1
    setvar 0x8004 0xB600
    callasm 0x9C0B21 // Shinyzer location + 1, different for any shinyzed game
    setvar 0x8003 0x1
    fadescreen 0x1
    random 0x8E
    copyvar 0x8005 0x800D
    addvar 0x8005 0x1
    setvar 0x8006 0x0032
    setvar 0x8007 0x0300
    cry 0x8005 0x0
    waitcry
    call 0x020375E0
    dowildbattle
    setflag 0x930 // make sure to change this with the other flag!
    release
    end
    
    #org @gen2
    setvar 0x8004 0xB600
    callasm 0x9C0B21 // Shinyzer location + 1, different for any shinyzed game
    setvar 0x8003 0x1
    fadescreen 0x1
    random 0x60
    copyvar 0x8005 0x800D
    addvar 0x8005 0x97
    setvar 0x8006 0x0032
    setvar 0x8007 0x0300
    cry 0x8005 0x0
    waitcry
    call 0x020375E0
    dowildbattle
    setflag 0x930 // make sure to change this with the other flag!
    release
    end
    
    #org @gen3
    setvar 0x8004 0xB600
    callasm 0x9C0B21 // Shinyzer location + 1, different for any shinyzed game
    setvar 0x8003 0x1
    fadescreen 0x1
    random 0x78
    copyvar 0x8005 0x800D
    addvar 0x8005 0x115
    setvar 0x8006 0x0032
    setvar 0x8007 0x0300
    cry 0x8005 0x0
    waitcry
    call 0x020375E0
    dowildbattle
    setflag 0x930 // make sure to change this with the other flag!
    release
    end
    
    #org @cancel
    = Decided not to for now.
     
    Back
    Top