1. GOG.com logo

    Thanks to YOUR votes, GOG.com now sells:
    - Sea Dogs - Sea Dogs: Caribbean Tales
    - Sea Dogs: City of Abandoned Ships

    Vote now to add Pirates of the Caribbean to the list!

    Dismiss Notice
  2. Under the Crossbones Podcast

    A Pirate Podcast with Interviews
    Music, Comedy and all things Pirate!

    - Episode Guide - About - Subscribe -
    - Twitter - Facebook - iTunes - Android -
    - Youtube - Fill the Coffers -

    Dismiss Notice
  3. New Horizons logo

    Quick links for PotC: New Horizons
    - Download latest version
    - Wiki - FAQ - Report bugs here
    - ModDB profile

  4. GOF logo

    Quick links for AoP2: Gentlemen of Fortune 2
    - Downloads and info
    - Historical Immersion Supermod
    - ModDB Profile

Dismiss Notice
New to the forum?
Please take a moment to read our Welcome Message and Forum Rules.


Dec 22, 2015

  • Simple Storm Coding Tutorial(top)

    Go back to modding


    This tutorial will give you a basic understanding of Storm coding. We will explain some of the basic facts in this tutorial.
    The Storm engine uses a programming language which is similar but not the same as C. The initialization files aren't accessible without reverse engineering so we can only edit the runtime files. Still this gives us more than enough possibilities to edit the game. Just remember sometimes you might find a wall cause the part you want to edit is hardcoded into the engine. Sometimes you can work around this but sometimes you have to find another way of what you want to do or change it so it does work.

    What do you need?(top)

    In this tutorial we will do everything in the file console.c. This file can be changed during the runtime because its loaded every time its executed. You can execute this file by pressing f12 in the game.
    You only need a text editor to edit this file. I suggest using a program like Notedpad++ because it’s easier to read in there.

    Your first piece of code(top)

    So let’s start this off. Open the console.c file. You wil notice there is a lot of code in there already. At the top you will see this:
    void ExecuteConsole()
       ref pchar = GetMainCharacter();
       ref ch;
       int i;
       int limit;
    These lines initialize some variables which we might use later. But for now you can just ignore these lines. After these lines we will add our code (Before the switch(0) line).
    We are going to show a onscreen message when a user presses F12. You will notice when you press F12 there is always a message displayed already. We are going to add another one.
    We do this by using a function. This function is called Logit.
    Functions are pieces of code which serve a specific function (hence the name). They often require arguments as input and they can return a value back. Say for example there was a function to add two values together you would use it something like this:
    Answer = AddTogether(value1,value2);
    The function we are going to use only has 1 argument which is a string. The function doesn’t return a value. A string is a collection of characters together. They are always between “ “. So now we put down this piece of code:
    logit(“Hello World”);
    And we save console.c. Now open the game and go somewhere (not a menu). Now press f12. You will see besides the default message there will be a new message also. Congratulations you just did you first mod!


    Introduction into variables(top)

    Now we know how to display something on the screen we are going to look at variables. Variables are places to store data. There are a lot of different types of variables. For now we are going to look at 2 types:
    String – This is used to store text
    Int – This is used to store numbers
    If you want to use a variable you always have to define them first so the game knows what kind of variable it is. After this you can use them how you like. If a variable is defined within a function it will only be accessible by the code in this specific function. If a variable is defined outside a function it is a global variable and it will be accessible in all functions. For now we will only focus on the private variables (the ones inside a function).
    We are going to generate the same result as before but now we are going to use variables to do this. So instead of inputting the text directly in the function we are going to save this text in a variable first. We do this like this:
    string text = “Hello World”;
    We now made a string variable with the name text. It has a value of “Hello World”.
    Now if we want to show it on screen again we do it like this:
    string text = “Hello World”;
    If we execute this we will see the result is the same as in the previous example. This might sounds useless for now. But by using variables we can create very powerful systems.
    Now let’s look at the int type of variable. Int stands for integer. And integer is a number, this number can’t have a fraction so it must be a whole number. We define them like this:
    int number = 42;
    We now created an integer variable with a value of 42. You’ll notice we didn’t put it between “ “. This is because this is only used for strings. Numbers are inputted directly.

    More types of variables(top)

    Besides the string and int there are more types of variables which a beginner might use. These are bool and float.
    A bool variable is a Boolean variable which can only contain a true (1) or false (0) value. A float variable is a floating point number. This is a number with a fraction in it as well. You can use this variable to save for example the value of PI. They are defined like this:
    bool foo = true;
    float bar = 3.14;

    Choosing your type variable(top)

    Now you might think why not always use a float for every number and a string for the rest. Why would I need the bool and int. And if you where programming on a computer with infinite memory this would be true. But a bool only takes 1 bit of memory, while a int would require 16 bits of memory. A float would even require 32 bits of memory. So you see how this stacks up. Therefore always try to pick the datatype which fits best. But do note that they have theire limitations.
    A Boolean can only hold 0 and 1
    An int can only hold from -32,768 to 32,767
    An float can hold 1.2E-38 to 3.4E+38
    So if you have a value which might get higher than 32767 you want to consider using an float instead. Because if you add 1 to the value of 32767 it will become -32767 in an int. This could mess up your whole programming and take VERY long to find out in debugging.


    Introduction into operators(top)

    Operators are used to manipulate variables. Most of them you know already from math. They are operators like + and -. We are going to use the addition operator now. First we need to look at what this exactly does. The + will add two variables together. When both are a number it will do it like math. If one of them is a string it will do it by just putting them after each other and merging them into one string. So if we have something like this:
    string text = “Hello World”;
    int number = 42;
    string added = text+number;
    You will see when executing it, it will show “Hello World42” on the screen. If we have something like this:
    int number1 = 20;
    int number2 = 22;
    int added = number1+number2;
    It will show “42” on the screen. Now if you are paying attention you might have noticed we have given logit a int value as argument while it needs a string. This we can do because the engine will convert it to a string automaticly. Not all variables are converted with the same ease, but integers go fine. Else we would have to do it like this to be completely nice:
    int number1 = 20;
    int number2 = 22;
    int added = number1+number2;
    string text = “”+added;
    This would add a string and number so makes it a string. But the engine can do this for use instantly so that’s nice.

    Simple operators(top)

    Besides adding the other math operators are also avaible in potc. So you can use the following operators:
    + Adds two things together
    - Substract two things together
    * Multiplies two things together
    / Divides two things

    There will be cases where you want to add something to a existing variable. For example you want to add 2 to an existing int. You can do that like this:
    int number1 = 40;
    number1 = number1 + 2;
    But there is an easier way to write this. You can use a other kind of operator for this:
    int number1 = 40;
    number1 += 2;
    This code will do exactly the same but as you see it’s easier to write. Just like with the normal math operators this type is avaible for all:
    += Adds right to left
    - = Substract right from left
    *= Multiplies left by right
    /= Divides left by right

    You don’t have to use these operators if you don’t want to. In some cases it might be easier to read it you use the other way. But you can expect this kind of operator appearing something if you look trough the code.

    Logic operators(top)

    Logic operators are operators which examine two values and either return an boolean (TRUE or FALSE) value.
    Here is a list of logic operators:
    == checks if values are equal
    > checks if left is larger than right
    < checks if left is smaller than right
    != check if values are not equal
    >= checks if left is larger or equal than right
    <= checks if left is smaller or equal than right

    These operators will be mostly used for if statements but you can also use them in variables. Lets look at an example:
    int number1 = 40;
    int number2 = 30;
    bool check = number1 == number2;
    bool check2 = number1 != number2;
    bool check3 = number1 > number2;
    bool check4 = number1 < number2;
    This will result in the following values:
    check = 0 (false)
    check1 = 1 (true)
    check2 = 1 (true)
    check3 = 0 (false)

Share This Page