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

Fix respawning for racing #348

Merged
merged 2 commits into from
Aug 28, 2023
Merged

Fix respawning for racing #348

merged 2 commits into from
Aug 28, 2023

Conversation

enteryournamehere
Copy link
Member

The previous code

var playerInfo = Players.Find(info => info.Player.Id == player.Id);
playerInfo.Vehicle = car;

was broken because Players contains RacingPlayerInfo structs, which is a value type, not a reference type. This means that var playerInfo = ... results in a local copy of the data. The following line then only modifies this local copy, leaving Players unchanged.

This new code creates a local copy of the data, modifies it, and then updates the struct stored in the Players list.

Copy link
Member

@teccheck teccheck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In line 233 there's another one of those bugs. To me it seems like it's working anyways but it might be good to fix this as well.

playerInfo = Players.Find(info => info.Player.Id == player.Id);
playerInfo.Player = player;
playerInfo.PlayerLoaded = true;

Other than that it looks good to me.

I looked into ref structs but they don't seem to be the right choice

@enteryournamehere
Copy link
Member Author

Oh, good catch!

@teccheck
Copy link
Member

I made this code after all... The more I look at it, the more I want to redo the whole thing xD

@enteryournamehere enteryournamehere linked an issue Aug 28, 2023 that may be closed by this pull request
Copy link
Member

@teccheck teccheck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Thank you 👍

@enteryournamehere enteryournamehere merged commit de67faf into dev Aug 28, 2023
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Respawn in racing broken
2 participants