Contents |
OpenKore is written in Perl, a scripting language. Although Perl is a fine language, due to the language's extreme flexibility, many developers (including Kura, the original author of Kore, and many modders) make coding mistakes. The goal of this document is to inform developers about how to properly write code for OpenKore.
createFile() attackMonster() $superWeapon
sub fooBar {
my $canProceed = $_[0];
if ($canProceed) {
bar(1);
} else {
bar(0);
}
}
Wrong example:
sub
FooBar()
{
my $CanProceed = $_[0];
if ($CanProceed)
{ bar(1); }
else
{
bar(0);
}
}
If the variable is only used temporary (only within one function or statement), make the variable local by defining it with "my". Example:
sub foo {
...
# Defines multiple local variables:
my ($switch, $msg);
$msg = "01";
$switch = "ABCD";
if ($switch eq "ABCD") {
my $level = unpack("S1", substr($msg, 0, 2));
message "/me uses Dummy Skill lv $level\n";
}
}
See the Log.pm for more information.
Comments are important and often underestimated. In the long run, good comments will help you and potential contributors.
} elsif ($switch eq "DEFG") {
# Someone used SuperBlessing lv 99 on you. All your stats
# are boosted by +99. Take advantage of this while we
# still can.
# (describe algorithm if you're doing something really
# complex)
...
(hundreds of lines follow)
...
In Readme.txt, you write down a brief, high-level overview of changes. Readme.txt is intended for users, who want to read what has changed in each release. You should also write down new config options so users can update their config files correctly.