Skip to content

Error: silent script failure on top level script using int StartingConditional() when an #include script has a void main() #150

@alfa050moonshaes

Description

@alfa050moonshaes

As per the title. This is an issue because, regardless of whether the underlying problem is a user writing poor nwscript, nwn_script_comp creates a script that (a) does not trigger a compile error, and (b) fails silently when run in-game by a conversation event.

Script example:

[top-level script:]

#include "an_include_scr"
int StartingConditional()
{
SetCustomToken(4738571, STRING_FROM_INCLUDE_SCRIPT);
return TRUE;
}

[first include script:]

#include "constants_scr"
void main()
{
DoAThing();
[etc whatever other code may be here]
}

[second include script:]

string STRING_FROM_INCLUDE_SCRIPT = "thisisastring";

When compiled with Toolset, the top-level script works fine in-game.
When compiled with nwn_script_comp, there is no compile error but the script does not run in-game; it fails, silently without any error message.

The .ncs produced by the Toolset when compiling, will be much smaller than the .ncs produced by nwn_script_comp. It seems that the Toolset's compiler recognises that the void main() should not be #include'd. So it does not include it. But it will include the constants script (the bottom-level script). Whereas nwn_script_comp just includes everything and therefore it seems to compile the void main() which (presumably) runs - and terminates any conversation that the int StartingConditional() script is used in.

Have attached the two different .ncs's produced by Toolset compiler and nwn_script_comp respectively, that demonstrate the differences in .ncs that are produced. Also attached the .nss they are made from (which are identical for both .ncs's obviously).
Can provide the full include scripts for this as well if that's any help - contact El Grillo via NWN Dev Discord, thanks.

Daz comments on NWN Dev Discord:
The script compiler has two flags:
m_bCompileConditionalOrMain: if this is set to true the compiler will first try to find a void main(), if it can't find a main function, it'll try to find an int StartingConditional(), it'll try compile whatever it found.

m_bCompileConditionalFile: if this is true it'll only check for an int StartingConditional() to compile, if false it'll only check for a void main()

Now how do the toolset and nwn_script_comp differ?

For the toolset m_bCompileConditionalOrMain == false, so it'll compile based on the m_bCompileConditionalFile flag. What the toolset does is check the current file, not any includes for a void main(), if it finds one it sets m_bCompileConditionalFile to false, or if it can't find one it'll set it to true. (I think it'll also look at errors messages and flip the flag to try the other)

nwn_script_comp on the other hand has m_bCompileConditionalOrMain == true, meaning it'll always try to find a void main() first to compile and only if it can't find one, it'll look for an int StartingConditional().

This is why your nwn_script_comp ncs is 13kb, because it compiled the void main().

Many thanks

alfa_chatcolemot - toolset.zip

alfa_chatcolemot nwn_script_comp latest.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions