What should an event return ?

Started by Sebastian, Mar 11, 2015, 01:09 PM

Previous topic - Next topic

Sebastian

I loaded the CMSS_v2.nut via dofile( "scripts/CMSS_v2.nut" );, but it doesn't seem to be loaded...
The messages from onScriptLoad of CMSS is not appearing, but also the commands are not working, and maybe more.

I really think this is caused by the values I return/don't return in events, so tell me:
What should an event return, in order for it to call other events from other loaded script ?

PS: When I remove the onPlayerCommand from CMSS_v2.nut, the command from main.nut is called, and works. (not entirely, but I really think the problem is the wrong returns I have)

PS2: I have understood that some events requires return 0, and some return 1, to work properly.

.

The function `dofile(...)` is not a part of the Squirrel module. It's part of the Squirrel standard library. And therefore it does not trigger any `onScriptLoad` events.



dofile(path, [raiseerror]);

compiles a squirrel script or loads a precompiled one and executes it. returns the value returned by the script or null if no value is returned. if the optional parameter 'raiseerror' is true, the compiler error handler is invoked in case of a syntax error. If raiseerror is omitted or set to false, the compiler error handler is not ivoked. When squirrel is compiled in unicode mode the function can handle different character ecodings, UTF8 with and without prefix and UCS-2 prefixed(both big endian an little endian). If the source stream is not prefixed UTF8 ecoding is used as default.

.

.

#2
Quote from: sseebbyy on Mar 11, 2015, 01:09 PMPS: When I remove the onPlayerCommand from CMSS_v2.nut, the command from main.nut is called, and works. (not entirely, but I really think the problem is the wrong returns I have)

Because the function was overwritten by another data with the same name. Let me prove what I mean with an example of how these things work:
function onPlayerCommand(text)
{
    print("I'm the first: " + text);
}

function onPlayerCommand(text)
{
    print("I'm the Second: " + text);
}

function onPlayerCommand(text)
{
    print("I'm the third: " + text);
}

onPlayerCommand("In line!\n");

print(typeof onPlayerCommand + "\n");

onPlayerCommand <- 32;

print(typeof onPlayerCommand + "\n");

onPlayerCommand <- { Name = "Jon", Age = 27 };

print(typeof onPlayerCommand + "\n");

function onPlayerCommand(text)
{
    print("I'm the fourth: " + text);
}

onPlayerCommand("In line!\n");

print(typeof onPlayerCommand);

Output:
I'm the third: In line!
function
integer
table
I'm the fourth: In line!
function
.

.

That's why I advise anyone to avoid using the <- operator everywhere. Because you never know what you'll overwrite.
.

.

Quote from: sseebbyy on Mar 11, 2015, 01:09 PMWhat should an event return, in order for it to call other events from other loaded script ?

See the above example and you'll see why only one function with that name can be called.  And that function will be the last one implemented that either created that slot in the global table or simply overwrote it.
.

Sebastian

Pretty well. Thanks for clarification. I thought it works like in Pawn, when we talk about these returns.
(in pawn you could use the same callback in more filterscripts)

Stormeus

Quote from: sseebbyy on Mar 11, 2015, 08:55 PMPretty well. Thanks for clarification. I thought it works like in Pawn, when we talk about these returns.
(in pawn you could use the same callback in more filterscripts)

Filterscript-like functionality is planned in a major Squirrel update, but that's still some ways off.