effects defaults to empty array for all room objects#117
Open
Will-Crain wants to merge 2 commits intoscreeps:masterfrom
Will-Crain:master
Open
effects defaults to empty array for all room objects#117Will-Crain wants to merge 2 commits intoscreeps:masterfrom Will-Crain:master
Will-Crain wants to merge 2 commits intoscreeps:masterfrom
Will-Crain:master
Conversation
Right now, there is a discrepency in how the `.effects` property on RoomObjects is handled. If there are no effects on an object, an object that has never had an effect on it has an undefined `effects` property, whereas objects that have had an effect on them in the past have an `effects` property of `[]` This change sets `effects` to undefined if there are no effects on the object, making this property consistent for all room objects.
Contributor
|
Why not just default it to empty array instead? that way its always one consistent type |
Author
|
I wasn't sure if defining a new property for all game objects would have any impact on performance, so I opted for a defined-on-demand. I'm not well versed in the server/database side of things, so if you think that defining a new property for all room objects wouldn't be an issue, I'd gladly change the PR to reflect that. |
Contributor
|
I would say just add } else {
this.effects = []
}```
to the if statement |
Contributor
|
shouldn't be any performance difference, in fact, would be cheaper than checking if its an array |
After some delibaration and advice, code was changed so `effects` is never undefined, but defaults to an empty array instead. This way, the `effects` property never changes data type.
sparr
approved these changes
Jun 17, 2023
Contributor
sparr
left a comment
There was a problem hiding this comment.
+1 for consistent types to match the documented API.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Right now, there is a discrepency in how the
.effectsproperty on RoomObjects is handled.If there are no effects on an object, an object that has never had an effect on it has an undefined
effectsproperty, whereas objects that have had an effect on them in the past have aneffectsproperty of[]This change sets
effectsto undefined if there are no effects on the object, making this property consistent for all room objects.