• 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✓] Should I edit existing scripts?

853
Posts
3
Years
  • Age 33
  • Seen Nov 9, 2023
I've read about adding scripts to roms, so i know I need to find free space and then put my script in that offset, to add something new.

But I'm wondering, can I find the offset of a specific event i want to change can I just go in and add on to the script already there to make changes to what already exists, without having having to add something new?

Or is it really necessary to make a new offset, copy the entire script with the addition of my intended changes, and then repoint?

Like if I want to make a battle repeatable, I could check the sprite in advance map open the the script and then I'd just check,set,clear the flag for the battle.


Also if i'm wrong about how that would work please let me know, i'm hoping with that i can go through and rechallenge trainers all I want without having to worry about them constantly stopping and approaching me.
 
Last edited:

Asith

Uwao
237
Posts
3
Years
  • Age 22
  • Seen Apr 13, 2024
Essentially it depends on memory. If your changed script would take up the same(ish) amount of space as the original, then it'll work. If all you're doing is changing setflags to clearflags then you'd be safe. Adding new commands here and there might break the script though. Best thing to do is make a backup of your rom, change your script, and if it works then great. If it's broken, just go back to your backup. You'd have to do this on a case-by-case basis tbh
 
853
Posts
3
Years
  • Age 33
  • Seen Nov 9, 2023
Essentially it depends on memory. If your changed script would take up the same(ish) amount of space as the original, then it'll work. If all you're doing is changing setflags to clearflags then you'd be safe. Adding new commands here and there might break the script though. Best thing to do is make a backup of your rom, change your script, and if it works then great. If it's broken, just go back to your backup. You'd have to do this on a case-by-case basis tbh

Ok thanks I'll try that, but how do i test that exactly?
i've made copies (kept same name) and i also have .bak files from backups other programs made, that are still otherwise unaltered.
Do I just go into advancemap change the script and then save to the rom?

I know some theory but I haven't actually tested things yet, is there a way to preview changes like a sandbox?
 
853
Posts
3
Years
  • Age 33
  • Seen Nov 9, 2023

that is pretty interesting, but after staring at it for a while, I realized the reason his code didn't work at first, it sounds like he tried to just write in a different text at the bottom without actually changing the value of the offset for the message box.

It probably would have worked if he did that, but just changing to your pointers is probably the safest option, in case the existing ones get used again elsewhere.
 

Asith

Uwao
237
Posts
3
Years
  • Age 22
  • Seen Apr 13, 2024
Ok thanks I'll try that, but how do i test that exactly?
i've made copies (kept same name) and i also have .bak files from backups other programs made, that are still otherwise unaltered.
Do I just go into advancemap change the script and then save to the rom?

I know some theory but I haven't actually tested things yet, is there a way to preview changes like a sandbox?

Only way to really test it is to run the game in your emulator I'm afraid. Go into advancemap and then open the script in XSE or whatever script editor you use, change it, compile your edited script, and then see if it works in-game. You could also hit decompile after compiling just to see if your script is still the way you wrote it and hasn't been overwritten, but the best way to test it is to play your game.
 
853
Posts
3
Years
  • Age 33
  • Seen Nov 9, 2023
Only way to really test it is to run the game in your emulator I'm afraid. Go into advancemap and then open the script in XSE or whatever script editor you use, change it, compile your edited script, and then see if it works in-game. You could also hit decompile after compiling just to see if your script is still the way you wrote it and hasn't been overwritten, but the best way to test it is to play your game.

Ok great I'll do that, is script getting overwritten a common thing, is there a reason it happens?
 
853
Posts
3
Years
  • Age 33
  • Seen Nov 9, 2023

Only way to really test it is to run the game in your emulator I'm afraid. Go into advancemap and then open the script in XSE or whatever script editor you use, change it, compile your edited script, and then see if it works in-game. Y

Alright update time, so I haven't tried changing a battle script yet, but I did a test on the guy in fire red that gives a potion on the first route.
I added a line that cleared the set flag at the end of the script and tried compiling, but like asith said for some reason it changed. it became nop and nothing changed... actually I may need to try that again, first time I was a complete noob and didn't realize I had to reload my rom.

Anyway after that failure I tried something else, and went back to pallet and changed the script for the pokeball left on the table.
Several times my changes did nothing, because I didn't know what the variables did so I was mostly guessing and trying to be safe.

Got mad, just copy pasted the pointer from one section to another without changing the variables to create a different path.

Worked, I now have 2 starters but it also retriggered the rival battle but he had the other starter this time, (that was probably that special) also may have reset the parcel mission (can't remember if I already completed it as it was a while since I played.) anyway he took the parcel gave me a pokeball, and then a pokedex.

I think it did reset the parcel mission as I already had pokeballs at that point.

Oh and the rival sprite was invisible while the pre-rival battle dialogue played and after the battle.
But he reappeared correctly for the parcel part.

I'm about to save and trigger the next rival battle in viridian if he has the starter he originally had, (charmander) I'll consider this a success, but right now either he'll have the one my main is strong to, the one I'm weak to (the right one), or the game will get confused and crash.

edit:
Yeah looks like he's running a last result function or something, he had the one I'm strong to....wait I'm stupid, it wasn't the one I'm strong to its the same one I had. So its actually more difficult neither of my starters have an advantage. uhh but either way I'm gonna go back and try to reset it, by trying to pick the same pokemon again, but I'll have to unhide the pokeball...sigh.

started with bulbasaur then I picked squirtle so he picked the strong one to that, bulbasaur.
ok i cant figure out how to reset it.
 
Last edited:
853
Posts
3
Years
  • Age 33
  • Seen Nov 9, 2023
I freakin did it. XD

Took staring at the code an extremely long time, and checking a few guides, but I realized the best thing was to make a new offset in free space and then point to the part of the code that gave that specific pokemon.

that said looks like the script for the first rival battle isn't built for switching pokemon so my team sprite kept going invisible until I attacked.
but because I already had bulbasaur it didn't give me another so this is just fixing that weird bug I caused where the rival has the wrong pokemon.

Also another bug with the fight, because it isn't built to read anything but the starter sprite if your pokemon dies it expects you to white out but if you have more pokemon it just gets stuck, luckily I saved beforehand. So I'm going to use a different pokemon and try to win, if that fails I'll leave only 1 in my party.

Take 2 I put squirtle in front and his sprite showed through perfectly. Ok I won the battle and as before the parcel script played again and I received more pokeballs.

I've just inadvertently created an infinite pokeball scheme lol. man I'm happy I got that working.

oh and if y'all are interested the code ended up being as simple as
lock
faceplayer
goto 0x8169C14

and creating a new sprite in professor oak's lab to run it. lol and because its a new sprite the built in hide sprite code doesn't get rid of it.
My code is extremely janky but it feels good to succeed here.

For anyone trying to edit things I highly recommend checking this thread for the full list of fire red flags variables etc.
https://www.pokecommunity.com/showthread.php?t=302347
 
990
Posts
4
Years
that is pretty interesting, but after staring at it for a while, I realized the reason his code didn't work at first, it sounds like he tried to just write in a different text at the bottom without actually changing the value of the offset for the message box.

It probably would have worked if he did that, but just changing to your pointers is probably the safest option, in case the existing ones get used again elsewhere.

I'd have to specify a new start offset, which is what I did. It doesn't matter, since yes, you can use previous movement/text/goto and call offsets in a completely new script; but I believe you've solved it.

And this is an updated and more accurate list of flags and vars in FR, so make sure to follow it:
https://github.com/pret/pokefirered/blob/master/include/constants/flags.h
https://github.com/pret/pokefirered/blob/master/include/constants/vars.h
 
Last edited:
853
Posts
3
Years
  • Age 33
  • Seen Nov 9, 2023

very nice, thanks a few did seem (possibly) a bit different from what they had on the list.

and I don't know if its a limited byte thing but for some things I could change existing code(without a new offset) without too much trouble I think that was only when I moved around pointers or changed values of variables.
I could probably get away with removing lines (strings?) too, but when I tried adding new lines on is when I had problems.

Part of that is also probably because I don't know how to count how much space I'm taking up with my code/script.

and I think i may have been using wrong terminology when I said that, I was thinking if you went to the offset where that message was stored and changed that (at the source) instead of changing it within the script you were on it might work.
But then you may run into the same memory problem I did so maybe not.

btw would you happen to know how to multiply or divide via script, I've heard its possible but not simple, or was that asm?
 
Last edited:
853
Posts
3
Years
  • Age 33
  • Seen Nov 9, 2023
Alright further testing my doesn't seem to cause any bugs, and the special var/flag that triggers the intro rival battle also heals your pokemon after, so as long as you win AND COMPLETE THE FULL SEQUENCE (win battle talk to oak, deliver parcel, and receive pokedex) before doing it again you're perfectly fine to repeat it all you want for quick experience a little money and 5 more pokeballs.

I reload the map every time (leave come back in) just to be safe but it works just fine for me. Its a nice little trick to help me try different teams and catch more pokemon early on.

edit.
but it does also reset the teach tv guy in viridian.
 
Last edited:
853
Posts
3
Years
  • Age 33
  • Seen Nov 9, 2023
Welp I done goofed, so I was getting some quick experience with my script while accelerated, so I wrote off some unusual text that popped up one time. Looks like I shouldn't have because somehow the code accidentally gave me the evolved form of my starter, maybe because he was already in my party?

Well anyway I now have a bulbasaur, a squirtile, and an ivysaur. o.o
 
990
Posts
4
Years

Do keep in mind that if the modified script has a lesser size than the original script, you can simply compile it via the grey "Gears" button without mentioning a start offset (a window will pop up without giving you any offsets; just select "Close").
I'm not sure about what's happening with your script since I write all my scripts by my own instead of modifying the original game ones.
 
853
Posts
3
Years
  • Age 33
  • Seen Nov 9, 2023
dot dash dot dot dash

yeah I think that's how I got my first test to work, and why it didn't work when I tried adding things to existing code. The first time I just removed a flag, or changed a value.

lol yeah my script is a little crazy, but in essence I just copied a part of an existing event script, and pasted that into a new event I created.

Its only weird because I didn't/don't understand how to remove the flags that hid sprites or change the battle script.

and I haven't test it yet, but it gives a pokemon from buffer, I don't know if it checks if I already have it (I think it does), because I think the reason it gave me an ivysaur was I already had bulbasaur in the party with me when I activated the script, but he wasn't in the 1st pokemon slot.

My assumption is it tried to give me bulbasaur but having him in my party already for some reason tripped it out, and it went to the next variable/byte idk which I guess is for ivysaur.

The most I could do with actually editing existing scripts was to repoint some variables to move me into different sections of the script and allow me to take the last starter pokeball. But that caused the whole cascading issue of changing the rival's pokemon so I had to do make that new event to reset what I did that time, because I coudn't figure out how to unhide via existing code.

So the lesson here I guess is the only changes that work with existing code are repointing and ones that subtract from it, like removing strings.
 
853
Posts
3
Years
  • Age 33
  • Seen Nov 9, 2023
Ok know its been a while but right as I was about to give up all together, inspiration, so I finally figured out what flag the trainers were using, its the same one in the trainerbattle script, but just up 500 in hex. ex. trainer battle 0x0 0x6e would be flag 0x56e.

I was able to clear it and make it work exactly as I wanted, now I can refight trainers all I want, and not have to worry about being stopped every time I walk back through the area. I just put the clear flag message in their post battle message, I thought I would have to go in and do a whole "lasttalked" or 800d super script but it was super simple.

I'll probably mess around with it some more later. But I'm satisfied.
 
Back
Top