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.
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
Added optional wait variance #967
Added optional wait variance #967
Changes from 1 commit
9b9a659
59d91b6
7126912
cb38c90
74df211
80f6c38
5dd9295
1bec762
82361d8
d01fa92
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the reason for removing float as supported datatype? If this feature is released and someone used wait(10.5), then I believe their macro will suddenly crash.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was trying to make the
wait
macro accept a variable as input as it either didn't or I'd broken it somehow.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_resolve
makes rpc calls. Though I doubt it would be noticeable by a user, on paper it would most likely be a lot better for performance if_resolve
was called once forvary
andtime
, and then the result stored in a local variable withintask
to reference it later on, instead of resolvingtime
redundantly three times. It also reduces the risk of race conditions.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair. When I made the initial changes the
vary > time
comparison didn't work and my knowledge of python isn't spectacular.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you need to resolve them in
task
._resolve
looks up variables, and they can change during runtime. If you do it outside of_task
they are resolved when the macro is parsed, and then never again.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've moved the
_resolve
into_task
. I'm not sure how to set the default value formax_time
to beNone
as it throws an error comparing'NoneType' and 'int'
when the second argument isn't set. Again, my python is not amazing.A slightly off-topic aside: In testing I found a way to test if macro variable is set or not by
if_eq($var, None, then=unset_macro, else=set_macro)
. Would it be worth amending the examples documentation to illustrate it as a roundaboutif_unset()
function? Usingwait
with an unset variable can softlock keys if you have something likekey_down(a).wait($unsetvariable).key_up(a)
as thewait
dies sokey_up(a)
never fires and having the macro always setunsetvariable
first negates changing the value elsewhere.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, you would need to do something like
if max_time is not None and max_time > ...
this way, you are not comparing
'NoneType' and 'int'
, because it never reaches the comparison if max_time is None.Do you mean something like
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unittests are used in pipelines, like this one: https://github.com/sezanzeb/input-remapper/actions/runs/11427747182/job/31792217401 (Click on "Run tests" to see them)
They are used, so that we immediately see if something broke with our changes. In that case, github will display an error icon for us, like here:
Other than that, people rarely look at the test-output. And nobody is going to look at the output of a test each time they make a commit, to verify if things still work.
This is what I mean with "automated". Unittests should automatically check if the result is as expected (time within an acceptable margin of error), and if not, raise an exception (
self.assertLess
does that for us in the example below)Here is how a test can work. It passes if 5 iterations of wait sleep between 45ms and 55ms on average.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Automated tests are extremely important and every project should have them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll finish the pull request later if you don't have more time, that's fine. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've re-added the
float
inputs for the requiredtime
and as well as the optionalmax_time
and carried that through the entire function while also making sure it didn't get flattened by the variousint
s. Also added debug output to theadd_wait
macro but it's not reflected in testing.Using your unit testing it looks like they're all within desired +/-0.005s limits. All but a double variable retrieval are under 0.001 with
wait($a,$b)
breaking 0.002 even on my ancient work laptop.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you remove the time randomization from add_wait, your tests will still pass, therefore they are not able to verify if the randomization works.
I have made some changes and a pull request to your branch: shawarden#1. In shawarden@dc98ddb you can see how I ended up designing the tests.
Once you merge that one into your main branch, I'll merge this pull request.