-
-
Notifications
You must be signed in to change notification settings - Fork 102
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
Behavior of foreach with empty elements in list #519
Comments
This is the doing of some internal dList code, not foreach specifically. |
So are you saying that you think a sign should always return a 4-item list? That probably makes sense, since you could use line 1 and line 3, and denizen might not maintain that the second item in the list was on line 3. Maybe empty lines could return 'null'? |
@aufdemrand - but then how would you know if the player just literally typed 'null' onto the sign? ++ |
Well first if all, || will be interpreted as an 'alternative'. Null is
|
@aufdemrand - I wish we could use a stronger typing system, and have It's not too hard to use... you can set -- actually, |
Hi guys, I think there's too much focus on this being a sign. I unfortunately can't test this right now, but from what I saw with the sign list I made the assumption that null values in an dList are simply being ignored/not looped through by the foreach command. For a sign, you're right, it's certainly no big deal to check each index and get the four values individually--that's how I'm working around this now--but I logged the call because i thought it might have more far reaching effects. In the case where you have an unknown number of elements in your dList, it seems illogical to me to "skip" some. What if you want to have an if statement in your loop to conditionally handle nulls? If the foreach statement doesn't even loop through the entries because they are null and appear at the end of the list, you can't do this. As far as checking the size of the list, that would work if you could do a while loop or a for... until and increment a counter to get each element, but I don't think Denizen can do either of those currently, can it? I haven't done professional development in many years (and even then I would never claim to have been particularly good at it! :D), but there's something logically wrong with a foreach loop that functions more like "forsome depending on the values" :) If I'm completely wrong and this is specific only to a sign-generated 4-element dList, then please ignore me! |
@winterfrost1 it's 'for each element in the list'. All of them. The issue here is empty elements are removed from the end (only the end) of the lists themselves. Also:
Outputs
So basically... if you want to handle empty elements are the end of a list, all you currently need to do is maintain a separate variable containing the total theoretical size of the list, and use that rather than ... but I still support lists being allowed to retain empty elements at the end. -- ALSO, an empty element is not the same thing as a null element. Empty = ... actually, I'm not entirely sure when/where it's getting removed. It might be from the argument parser... which means it's only being dropped when you directly input it into |
... and with that pull request I made, if it's accepted, there is 0% risk of |
This was never really an issue when it was made, and all possible side-issues have been fixed... |
I don't know if this is the desired behavior for foreach and empty elements, but it struck me as odd.
Example:
I create a sign at l@signlocation that says:
Test
[BLANK]
[BLANK]
[BLANK]
And I create a script (excerpt):
And I get:
Shouldn't foreach loop through all elements in the list, even if they're empty/blank?
Thanks!
The text was updated successfully, but these errors were encountered: