Add SecFilter, refactor Variable and Variables slightly to accomodate.
Description
Adds a filter section to allow filtering on many conditions at once, while maintaining indices and adding significant performance optimization when only removing a few elements of a large list.
Also support any and all, like multiline ifs.
set {_a::*} to integers between -10 and 10
filter {_a::*} to match:
input is a number
mod(input, 2) = 0
input > 0
I would like feedback on the abuses of the Variable api I have committed, as I don't really think the code is that great. I couldn't think of any better approaches, however.
Target Minecraft Versions: any Requirements: none Related Issues: #6866
Wouldn't it be smart to also allow a lambda-like structure where one can return a boolean?
filter {_players::*}:
if health of player > 10:
return true
return false
Not sure if Skript's current section API facilitates this feature, but it allows for more flexibility and is more intuitive in my opinion.
Either way, I like both options actually since your proposition is a really clean way to filter expressions without the cluttering '[]' syntax that is used currently.
Sections have access to a return api iirc in 2.9+ so this should be possible
Wouldn't it be smart to also allow a lambda-like structure where one can return a boolean?
filter {_players::*}: if health of player > 10: return true return falseNot sure if Skript's current section API facilitates this feature, but it allows for more flexibility and is more intuitive in my opinion.
Either way, I like both options actually since your proposition is a really clean way to filter expressions without the cluttering '[]' syntax that is used currently.
I considered this, but I thought it could get messy, and at that point there's no benefit to having a filter section over just doing
loop {list::*}:
if loop-value is x:
delete {list::%loop-index%}
I have a suggestion question for this,
- What about an "alias" for
inputcalledvalue - Matching the
valueif the list that is being looped, is a list variable, to also be able to useindexof sorts. That way you can filter out the values and indices within one section, if a user wanted to
Example
filter {_a::*}:
value is an integer
index parsed as number is set
I know for 2 you could just simply do two filters, one that processes the values, then once that is done, to do the indices.
Was just curious though
I have a suggestion question for this,
1. What about an "alias" for `input` called `value` 2. Matching the `value` if the list that is being looped, is a list variable, to also be able to use `index` of sorts. That way you can filter out the values and indices within one section, if a user wanted toExample
filter {_a::*}: value is an integer index parsed as number is setI know for
2you could just simply do two filters, one that processes the values, then once that is done, to do the indices. Was just curious though
You can already use input index! I'm not sure if using value would cause any issues but it seems reasonable.
You can already use
input index! I'm not sure if usingvaluewould cause any issues but it seems reasonable.
Ahhh ok, I was unaware of the input index, my apologies