Function just stops other function
#1

Hey there.
I'm having a strange problem with my gamemode.
When I call a function within a function, the function where the function got called just stops at the call.
This only happens with some functions.
I just tested it with a simple test function which does nothing.
The result using that script and using the command /test was that he just left out everything after test();

Код:
forward test();
public test()
{

}

public OnPlayerCommandText(playerid, cmdtext[])
{
    if(strcmp(cmd, "/test", true) == 0)
    {
        SendClientMessage(playerid, COLOR_RED, "calling function");
        test();
        SendClientMessage(playerid, COLOR_RED, "after function call");
        return 1;
    }
    return 0;
}
Another strange thing happened: After adding the test() function, the function where the problem was before worked perfectly.
But well, since the test() function has no content in it and thus actually can't be crashing anything, I guess the problem is hidden somewhere in the gamemode.
Maybe someone had the same problem and knows why it occurs?
Thanks, Blay09.
Reply
#2

When an anomaly occurs in scripting, I usually find an indexed variable using an impossible cell.
For example
pawn Код:
new variable[500];
variable[555] = 1;
Because 555 is outside the reach of the indexed variable, it creates a script hault (same as using 'return 0')


You'll get this same affect when formatting (or any other string function) a string that doesn't have a large enough index.
example
pawn Код:
new variable[5];
format(variable,128,"This is a test");
Reply
#3

Thanks for your help, I'm going to search my script for those mistakes.
I also found out something new:
Only the last function in my script (so the one at the bottom of the code) does not work. That's why the other function worked when I added the test() function. For now, I'll just use this as a workaround until I found the real reason for that bug.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)