PHO - Pokémon Hackers Online
Go Back   PHO - Pokémon Hackers Online > Other Generations Hacking > Guides & Documentation

Guides & Documentation Learn how to make your own Pokémon game through the process of ROM Hacking, or help out the community by sharing your information.

Reply
 
Thread Tools Display Modes
Old 5th December 2013, 04:14 PM   #1
Miksy91
Gotta fill something here.
 
Miksy91's Avatar
 
Join Date: Jul 2013
Location: Northern Europe
Age: 26
Posts: 127
Miksy91
Default Learn how to script well!

The following are examples of good and bad script codes. These should help out beginners to see how to divide good code from bad one, and thus, also help out in learning how to script better. Good code is always more readable, and fixing and enhancing it by giving it more possibilities (with if-cases for instance), is easier than by trying to do the same thing with badly written code.

Most of the meanings behind these commands are self-explanotary, so I'm not going to comment them. I'll also try to bother to expand these guidelines over time - especially if this thread starts to interest readers!


Example #1

Avoid copy pasting.

Quote:
Originally Posted by Part #1
:case1
lockPlayer
checkBit bit1
if = 1, jump to :case2
printText :text1
printText :text2
closeTextBox
unlockPlayer
setBit bit1
return
-----------------
:case2
printText :text2
closeTextBox
unlockPlayer
return
This code contains a lot of unnecessary copy pasting, and there are various different ways of fixing the problem. Now what we want to do though is to combine :case2 as part of the main routine. It could work like this:
Quote:
Originally Posted by Part #2
:case1
lockPlayer
checkBit bit1
if = 1, jump to :case2
printText :text1
setBit1 bit1
jump to :case2
-----------------
:case2
printText :text2
closeTextBox
unlockPlayer
return


...or, in a way that there are no separate cases at all!
Quote:
Originally Posted by Part #3
:case1
lockPlayer
checkBit bit1
if = 1, jump to :case2
printText :text1
setBit1 bit1
printText :text2 // address of :case2
closeTextBox
unlockPlayer
return
Now our new, improved script takes much less space than before, and is built in a more expandable way. For example, if we want to add another functionality to the code that should happen after address :case2 (yeah, you can refer to that part of the script as an address!), it would happen in both cases unlike in Part #1. I personally prefer, and advise, using the method I introduced in Part #2 although it does require an unnecessary "jump to" command. Thus, working out with the script code later on would be less painful.

Now here was the first example about avoiding copy pasting and I'll try to come up with more good examples later on. Having some feedback, especially from users that are already familiar with this kind of stuff, would be appreciated!
(Thus, I would get to know if something needs to be explained better and perhaps ideas on what to cover next.)
Edit:
I can't seem to be able to format this post so that there would be line breaks inside quotes, or sentences like here at the end of the post..
__________________

Last edited by Miksy91; 5th December 2013 at 04:34 PM.
Miksy91 is offline   Reply With Quote
Sponsored Links
Old 5th December 2013, 07:42 PM   #2
Pia Carrot
Orange Developer
Administrator
 
Pia Carrot's Avatar
 
Join Date: Aug 2010
Location: Valencia Island
Age: 22
Posts: 848
Pia Carrot Pia Carrot Pia Carrot Pia Carrot
Default

I assume this is for PKSV?

Also, I don't think [code] works inside of [quote], if that's what you mean.
__________________

I'm a boob
Pia Carrot is offline   Reply With Quote
Old 5th December 2013, 07:55 PM   #3
Miksy91
Gotta fill something here.
 
Miksy91's Avatar
 
Join Date: Jul 2013
Location: Northern Europe
Age: 26
Posts: 127
Miksy91
Default

Quote:
Originally Posted by Pia Carrot View Post
I assume this is for PKSV?

Also, I don't think (code) works inside of (quote), if that's what you mean.
This actually isn't PKSV language either. I wanted to pick up names for commands that would make it self-explanotary to understand what they do.

Actually no. I couldn't put line breaks between case1 and case2, so I had to write "-----------------" instead.
__________________

Last edited by Miksy91; 5th December 2013 at 07:59 PM.
Miksy91 is offline   Reply With Quote
Reply

Tags
learn, script, [Tutorial]

Thread Tools
Display Modes

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. The time now is 07:09 PM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2017, vBulletin Solutions, Inc. User Alert System provided by Advanced User Tagging (Lite) - vBulletin Mods & Addons Copyright © 2017 DragonByte Technologies Ltd.
Feedback Buttons provided by Advanced Post Thanks / Like (Lite) - vBulletin Mods & Addons Copyright © 2017 DragonByte Technologies Ltd.
Pokémon characters and images belong to Pokémon USA, Inc. and Nintendo.
Pokémon Hackers Online (PHO) is in no way affiliated with or endorsed by Nintendo LLC, Creatures, GAMEFREAK inc,
The Pokémon Company, Pokémon USA, Inc., The Pokémon Company International, or Wizards of the Coast.
All forum/site content (unless noted otherwise) and site designs are © 2006-2013 Pokémon Hackers Online (PHO).
Green Charizard Christos TreeckoLv100

"Black 2" by ARTPOP. Kyurem artwork by XOUS.

no new posts