The PokéCommunity Forums  

Go Back   The PokéCommunity Forums > Fan Games > Binary ROM Hacking
Reload this Page Other Adding new lines to an existing script

Notices
For all updates, view the main page.

Binary ROM Hacking Need a helping hand or just want to talk about binary ROM hacks? Get comments and answers to any ROM Hacking-related problems, questions or thoughts you have here.

Ad Content
Reply
 
Thread Tools
  #1   Link to this post, but load the entire thread.  
Old November 16th, 2014 (6:54 PM).
danmander danmander is offline
 
Join Date: Oct 2014
Posts: 14
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.
Reply With Quote
  #2   Link to this post, but load the entire thread.  
Old November 17th, 2014 (1:25 AM).
Nikolai Fox's Avatar
Nikolai Fox Nikolai Fox is offline
 
Join Date: Mar 2010
Gender: Male
Posts: 202
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.
Reply With Quote
  #3   Link to this post, but load the entire thread.  
Old November 17th, 2014 (1:45 AM). Edited November 17th, 2014 by Kasimsel.
Kasimsel's Avatar
Kasimsel Kasimsel is offline
 
Join Date: Nov 2014
Location: Germany
Gender: Male
Nature: Calm
Posts: 8
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
msgbox 0x8E3EAD4 MSG_NORMAL //"Why do humans always react like\nt..."
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
msgbox 0x8E3EAD4 MSG_NORMAL //"Why do humans always react like\nt..."
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.
Reply With Quote
  #4   Link to this post, but load the entire thread.  
Old November 17th, 2014 (2:22 AM).
Nikolai Fox's Avatar
Nikolai Fox Nikolai Fox is offline
 
Join Date: Mar 2010
Gender: Male
Posts: 202
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.
Reply With Quote
  #5   Link to this post, but load the entire thread.  
Old November 17th, 2014 (8:37 AM).
Blah's Avatar
Blah Blah is offline
Free supporter
 
Join Date: Jan 2013
Location: Unknown Island
Gender: Male
Posts: 1,924
Quote:
Originally Posted by Kasimsel View Post
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
msgbox 0x8E3EAD4 MSG_NORMAL //"Why do humans always react like\nt..."
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
msgbox 0x8E3EAD4 MSG_NORMAL //"Why do humans always react like\nt..."
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.
__________________
...
Reply With Quote
  #6   Link to this post, but load the entire thread.  
Old November 17th, 2014 (12:21 PM).
Joexv's Avatar
Joexv Joexv is offline
ManMadeOfGouda
joexv.github.io
 
Join Date: Oct 2012
Location: Oregon
Age: 25
Gender: Male
Nature: Sassy
Posts: 1,035
Quote:
Originally Posted by FBI agent View Post
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
__________________
New living flesh vessel who dis?
Reply With Quote
  #7   Link to this post, but load the entire thread.  
Old November 17th, 2014 (2:20 PM).
danmander danmander is offline
 
Join Date: Oct 2014
Posts: 14
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.
Reply With Quote
  #8   Link to this post, but load the entire thread.  
Old November 17th, 2014 (2:21 PM).
Blah's Avatar
Blah Blah is offline
Free supporter
 
Join Date: Jan 2013
Location: Unknown Island
Gender: Male
Posts: 1,924
Quote:
Originally Posted by joexv View Post
Lol that is definately not true. I ran out of space the other day.XD
You can simply expand you ROM. lmao...
__________________
...
Reply With Quote
  #9   Link to this post, but load the entire thread.  
Old November 17th, 2014 (2:33 PM).
Joexv's Avatar
Joexv Joexv is offline
ManMadeOfGouda
joexv.github.io
 
Join Date: Oct 2012
Location: Oregon
Age: 25
Gender: Male
Nature: Sassy
Posts: 1,035
Quote:
Originally Posted by FBI agent View Post
You can simply expand you ROM. lmao...
Yea but thats effort... ITS LIKE 5 WHOLE CLICKS AND AINT NOBODY GOT TIME FOR DAT.
__________________
New living flesh vessel who dis?
Reply With Quote
  #10   Link to this post, but load the entire thread.  
Old November 17th, 2014 (3:16 PM).
Nikolai Fox's Avatar
Nikolai Fox Nikolai Fox is offline
 
Join Date: Mar 2010
Gender: Male
Posts: 202
Wait setting the var to 0001 and having a script setvar 0x0001 didn't work?

It should have. Glitched map maybe?
Reply With Quote
  #11   Link to this post, but load the entire thread.  
Old November 17th, 2014 (4:47 PM).
danmander danmander is offline
 
Join Date: Oct 2014
Posts: 14
Quote:
Originally Posted by Nikolai Fox View Post
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.
Reply With Quote
  #12   Link to this post, but load the entire thread.  
Old November 17th, 2014 (10:56 PM).
Kasimsel's Avatar
Kasimsel Kasimsel is offline
 
Join Date: Nov 2014
Location: Germany
Gender: Male
Nature: Calm
Posts: 8
Quote:
Originally Posted by danmander View Post
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.
Reply With Quote
Reply

Quick Reply

Join the conversation!

Create an account to post a reply in this thread, participate in other discussions, and more!

Create a PokéCommunity Account
Ad Content

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -8. The time now is 9:07 AM.