Support OpenKore:
Learn about
the Fund Pool

Coding guidelines

English | 正體中文


Contents

Introduction

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.


Coding style


Variable definitions

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";
    }
}

Use message(), not print()

See the Log.pm for more information.


Comment your code

Comments are important and often underestimated. In the long run, good comments will help you and potential contributors.

Write a Readme entry

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.