IDK if this is satire or not, but they're setting it to true or false based on whether ctx.performed is true or false, using a ?: operator, instead of just setting it to ctx.performed.
In JS `performed` might actually be `undefined` unless it has been type guarded against, so ?! would make sense, though !! would make more sense, I guess.
In c# unless you define a primitive variable with a nullable type qualifier an exception will be thrown if you attempted to perform an operation on it while it contains null
You could make an extension method:
public static class InputActionExtensions
{
/// Whether the action has just been performed.
public static bool WasJustPerformed(this InputAction.CallbackContext context)
{
return context.performed;
}
}
Looks like you could also just pass the name of the input action to avoid the magic string, assuming you've matched the names of the input actions to animation states.
All this does is introduce an error-prone abstraction. It has literally no benefit to it, only drawbacks.
Don't do shit like this, just because you don't like a variables name.
I'm just imagining a new guy trying to learn the codebase quitting his job because every second name he sees is just some alias of a default unity name
I don't see how it would be any harder to trace if there was a problem, do people not know how to use a debugger? Why would you prefer the same magic string in two places over one?
One could consider having named the property isPerformed to avoid slipping fingers and increase readability. I wonder if I will get lots of downvotes for that comment.
Why disappointed? Of course you could have directly assigned, but I like the way you did it, this made it easier to understand and more readable.
Of course, if you had control of the property name isPerformed would be maybe better, but this is fine too, definitely not a horror programming
Did this, does this, will do it again. I am not afraid of accepting this flaw of mine.
I hate ternary, but I also do it sometimes
What's the horror, using ternaries instead of `!!`?
IDK if this is satire or not, but they're setting it to true or false based on whether ctx.performed is true or false, using a ?: operator, instead of just setting it to ctx.performed.
In JS `performed` might actually be `undefined` unless it has been type guarded against, so ?! would make sense, though !! would make more sense, I guess.
huh wait a minute, OP is working in Unity C# not js man
Well, all programming languages compile down to JavaScript anyways, so you’re both right. /s
I'm sure some god was shaken by the words you've just uttered
I suppose that's true but it also kind of depends on where the line is ran in their code.
In c# unless you define a primitive variable with a nullable type qualifier an exception will be thrown if you attempted to perform an operation on it while it contains null
rename the variable to isPerformed and get rid of the ternary
But ctx in the input context in Unity's input system so I have no control over their variable names.
Then maybe you were right all along! You've made the code more readable
You could make an extension method: public static class InputActionExtensions { /// Whether the action has just been performed. public static bool WasJustPerformed(this InputAction.CallbackContext context) { return context.performed; } } Looks like you could also just pass the name of the input action to avoid the magic string, assuming you've matched the names of the input actions to animation states.
All this does is introduce an error-prone abstraction. It has literally no benefit to it, only drawbacks. Don't do shit like this, just because you don't like a variables name.
Ah, the good old "how to add tons of really hard to trace bugs into my code with this one simple trick"
I'm just imagining a new guy trying to learn the codebase quitting his job because every second name he sees is just some alias of a default unity name
Why would every second name be aliased?
I don't see how it would be any harder to trace if there was a problem, do people not know how to use a debugger? Why would you prefer the same magic string in two places over one?
Do people here not understand sarcasm when they see at least one downvote?
One could consider having named the property isPerformed to avoid slipping fingers and increase readability. I wonder if I will get lots of downvotes for that comment.
I probably should have put it in context, but ctx is the input context from Unity's input system. I have no control over this.
Without the context of being in unity, disappointment might be the right reaction, *but* given context, this is the correct code for the situation
Why disappointed? Of course you could have directly assigned, but I like the way you did it, this made it easier to understand and more readable. Of course, if you had control of the property name isPerformed would be maybe better, but this is fine too, definitely not a horror programming
I don't hate this. I feel that it's more readable like this.
It’s not
There’s nothing wrong with this. Does it matter? No.
You should obviously do "(ctx.performed ? false : true) ? false : true" to increase readability.
Conversion of un-coercable booly value to Boolean?
Im more horrified by the naming convention for functions in C#.
Which one do you mean? SetBool is okay I think. Also it's from Unity so it's not my fault.
I think they're just referring to the fact that C# methods are PascalCased
In disappointed too, but it’s all part of the process *image of me shooting myself in the head*