IS4Code / PawnPlus

A SA-MP plugin enhancing the capabilities of the Pawn programming language
MIT License
103 stars 17 forks source link

Run time error 10: "Native function failed" #41

Closed minhthien2563 closed 3 years ago

minhthien2563 commented 3 years ago

Hi!

I have a bit of a problem with the PawnPlus library, the error described in the console is "Run time error 10:" Native function failed "", looking forward to your help.

Capture

InsertPhoneMessage(phoneid, targetid, targetphoneid, const content[])
{
    new
        str[600],
        hour, minute, second,
        year, month, day;

    new message[E_MESSAGE_PHONE];
    message[messagePhoneOwner] = targetphoneid;
    gettime(hour, minute, second);
    format(str, sizeof(str), "%02d:%02d:%02d", hour, minute, second);
    format(message[messageTime], sizeof message[messageTime], str);
    getdate(year, month, day);
    message[messageDay] = day;
    message[messageMonth] = month;
    message[messageYear] = year;
    message[messageNumberSender] = InfoPhone[phoneid][phoneNumber];
    format(message[messageContent], sizeof message[messageContent], content);

    return list_add_arr(messages, message);
}
IS4Code commented 3 years ago

Hello, you haven't shown how you create messages. That code is probably at fault.

minhthien2563 commented 3 years ago

Oh sorry.

new List:messages;
IS4Code commented 3 years ago

You have to create an instance of the list in order to add elements to it, for example via list_new. Otherwise the variable will have the initial value of INVALID_LIST (List:0).

You can use the usual script initialization callback to create the list there, use an initializer or perform some sort of lazy loading (check if the list is INVALID_LIST and then create it).