-
Notifications
You must be signed in to change notification settings - Fork 44
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
MaxIndex() and MinIndex() method not converted properly. #178
Comments
Maybe something like this? x := [1, , 3]
MsgBox x.Length != 0 ? x.Length : ""
x := []
MsgBox x.Length != 0 ? x.Length : "" and for MinIndex x := [1, , 3]
MsgBox x.Length != 0 ? 1 : ""
x := []
MsgBox x.Length != 0 ? 1 : "" Afaik Max returns length and and Min return 1 unless array is blank? If so then this should work |
^ MaxIndex() is fine MsgBox % {-10: 0, -1: 0}.MinIndex() ; -10 |
^what does MaxIndex return in that last example? |
MsgBox % {-10: 0, -1: 0}.MaxIndex() ; -1
MsgBox % {-10: 0, -1: 0}.Length() ; 0 These are more complicated than I originally thought, and may not have a perfect match in v2 |
yeah for now best to prob do nothing |
Actually since map properties and array properties are converted separately, it's possible to use this solution just for arrays, then leave maps how they are for now |
Suggestion... How about if the converter adds these custom properties (once) to the script when it encounters references to MinIndex() or MaxIndex()... And a note that communicates that Min/MaxIndex() should not be used for future scripts because it is not directly supported by v2. This will ensure that it is supported by the converted script, but also informs the user that this will not always be the case for new scripts.
Should work for maps as well, with an extra check
Although, AFAIK, this object literal is not valid in v2 |
Yeah... it is stepping slightly out of bounds, but there is no direct conversion for Min/MaxIndex() between v1 and v2. This would allow the converted script to support these unsupported methods. Which helps ease the burden of manual edit for the user. I did add this solution to the script section of the forum in case anyone wants to add it manually. |
my initial reaction is that that is kinda out of scope for the converter. but i dont really know how it should handle it |
I read the comments for #100. I see that once an exception is made, it may lead to an expectation for other situations to be supported as well. I wonder if a secondary tool might be better to address some of these "exceptions" that can be run after the conversion with this tool? Just thinking out loud... |
It could be possible to add these inside the Quick convertor menu, we can make a PR to add these changes, as there's atleast two other issues that could benefit from this |
I misunderstood 'Returns the lowest or highest integer key, if present.' See below for the corrected versions... |
ok... here is the corrected custom properties that should return the same value as v1
I think a map is stored with keys in alphabetical order, so not sure how helpful Min/MaxIndex will be for maps. But it does work, if you decide to include Min/MaxIndex for maps. |
Update on this issue: |
Arrays only MinIndex fails on cases like [ , , 1, 2, 3] See #178
In v1,
MaxIndex()
is an object method, therefore supported by arrays. In v2, the Array class does not have aMaxIndex()
orMinIndex()
method, causing converted code to give errors.v1 code:
Generated v2 code:
Running the generated code as is will give the following error:
Note:
MaxIndex()
does exist in the v2 docs, as a method for the ComObjArray class.In my case, I manually converted
x.MaxIndex()
tox.Length
. While they are technically different conceptually, functionally they yield the same value. I'm not sure if that works as a full solution though.The text was updated successfully, but these errors were encountered: