Skript icon indicating copy to clipboard operation
Skript copied to clipboard

Add SecFilter, refactor Variable and Variables slightly to accomodate.

Open sovdeeth opened this issue 1 year ago • 6 comments

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

sovdeeth avatar Jul 16 '24 22:07 sovdeeth

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.

Mwexim avatar Jul 21 '24 20:07 Mwexim

Sections have access to a return api iirc in 2.9+ so this should be possible

Fusezion avatar Jul 21 '24 20:07 Fusezion

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.

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%}

sovdeeth avatar Jul 21 '24 20:07 sovdeeth

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 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

Absolutionism avatar Aug 20 '24 03:08 Absolutionism

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 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

You can already use input index! I'm not sure if using value would cause any issues but it seems reasonable.

sovdeeth avatar Aug 20 '24 03:08 sovdeeth

You can already use input index! I'm not sure if using value would cause any issues but it seems reasonable.

Ahhh ok, I was unaware of the input index, my apologies

Absolutionism avatar Aug 20 '24 03:08 Absolutionism