Frictional Games Forum (read-only)

Full Version: Problem adding a diary page (i'm nooby)
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello, I'm making my first real map, and I haven't been able to find ANY tutorials on adding diary entries. So basically, I'm playing it by ear. When I run my map, the error that shows is a fatal error on line 15,28.


Here is the segment of code that I have.

[Image: scriptproblem.png]

Note: The name of the diary page is "diarypage1" and the CustomSubItemTypeName is "servantdiary".

Some help in this matter would be appreciated.
Your main issue deals with syntax errors. In order to help you solve your own problems, you would have to learn how to properly define a function, how to properly declare variables, how to properly call a function, et cetera; pretty much, you'd have to learn a few things about programming. I'm not going to try to teach you everything (since there are better places to learn from than from me), but i'll mention a couple of things.

Variables

Think of a variable as a container for data. Each variable contains a specific type of data (search "data types"). A valid variable name consists of letters, which could also include either underscores (_) and numbers. When storing information in a variable, you must specify the type of data you're storying (again, see "data types").

Example:
Code:
int number = 0;
string text = "some text";
float number_2 = 2.0;

Functions

A function can be considered a group of statements that can be executed by calling the function. A function can be declared with or without parameters. Parameters are a comma-delimited list of expressions. An expression is basically a line of code to be executed (usually ending with a semicolon). Functions can also return a certain data type.

Example functions:
Code:
// Without parameters
void function_name()
{
     // some code here...
}

// With parameters
int function_name(string &in name, int state)
{
     // some code here...
     return state;
}

Calling one of the example functions:
Code:
int state = function_name("object_1", 1);
function_name();

In any given script, there cannot be two functions with the same name with the same return type and with the same kind of parameters. This confuses the parser (or compiler) and will toss out an error.

The HPL2 engine (the engine of Amnesia) already has functions reserved for use. Overriding these functions will confuse the engine.

Try to figure out what you did wrong.
Hint:

You have more info than you need in each of the peramaters. Take a look at this, and compair it to yours:

(DO NOT USE THIS CODE, IT WONT WORK FOR YOU)
Code:
void FirstScriptArea(string &in asParent, string &in asChild, int alState)
{
        SetMessage("Messages", "DerrekMother", 0);
        SetPlayerMoveSpeedMul(0.5f);
        SetPlayerJumpDisabled(true);
        SetPlayerCrouchDisabled(true);
        PlayMusic("EndFile1.ogg", false, 20, 0, 0, true);
}

Now try to see what is different besides the obvious difference in code.
(08-22-2011, 05:06 AM)JetlinerX Wrote: [ -> ]Hint:

You have more info than you need in each of the peramaters. Take a look at this, and compair it to yours:

(DO NOT USE THIS CODE, IT WONT WORK FOR YOU)
Code:
void FirstScriptArea(string &in asParent, string &in asChild, int alState)
{
        SetMessage("Messages", "DerrekMother", 0);
        SetPlayerMoveSpeedMul(0.5f);
        SetPlayerJumpDisabled(true);
        SetPlayerCrouchDisabled(true);
        PlayMusic("EndFile1.ogg", false, 20, 0, 0, true);
}

Now try to see what is different besides the obvious difference in code.

Thanks for your initial reply! I have made a few changes after looking thought what you have said. This is what I have:
Code:
void SetEntityCallbackFunc("diarypage1", "OnPickup")
{
    OnPickup("servantdiary", "AddDiary");
    AddDiary("servantdiary_Name" && "servantdiary_Text", "");
}

Now the error says that it is "Expected data type." Does this mean I have to indicate whether it is int, f, bool, or string?[/code]