Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Item:GetItemLink case server crash #112

Closed
icaca opened this issue Apr 1, 2023 · 2 comments · Fixed by #114
Closed

Item:GetItemLink case server crash #112

icaca opened this issue Apr 1, 2023 · 2 comments · Fixed by #114

Comments

@icaca
Copy link

icaca commented Apr 1, 2023

RegisterPlayerEvent(PLAYER_EVENT_ON_STORE_NEW_ITEM) is fired when the player creates a character. Try to use Item:GetItemLink, the server will restart without any log.

function OnLoot(event, player, item, count)
    print(item:GetItemLink(4))
end

RegisterPlayerEvent(53, OnLoot)

@55Honey
Copy link
Member

55Honey commented Apr 1, 2023

Always Null-check variables that might not have a value before accessing them.
Example:

function OnLoot(event, player, item, count)
    if item
        print(item:GetItemLink(4))
    else
        print("item was null")
    end
end

RegisterPlayerEvent(53, OnLoot)

Object variables are prone to that behaviour and it is on the programmer to catch it.

@55Honey 55Honey closed this as completed Apr 1, 2023
@55Honey 55Honey reopened this Apr 1, 2023
@icaca
Copy link
Author

icaca commented Apr 2, 2023

This is just an example, the actual running code has judged nil.
even if it is nil, it should report an error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants