Skript

Skript

788k Downloads

Setting method to allow default function to be literal

TheLimeGlass opened this issue ยท 6 comments

commented

Suggestion

Add a setting method to allow default function to be literal in the case the default function parameters only requires literals.

An example of a valid use cause would be

on block physics involving location(0, 0, 0):
    block is water
    cancel event
on firework explode colored rgb(255, 255, 255):

Why?

In the example, to add to the block physics event, to avoid being called so frequently.

Other

No response

Agreement

  • I have read the guidelines above and affirm I am following them with this suggestion.
commented

Relevant: #5471, #7841

Note that the location idea cannot be a literal as worlds can never be literals due to their ability to be loaded/unloaded at runtime, but rgb can be a literal.

commented

Worlds have a special literal parsing syntax within the classinfo to allow it to operate in events structures. Really old behavior.
So location(0, 0, 0, world "example") will work as a literal. at 7am in "world" is a syntax example in the docs.
Also a location can have the world nullable.

commented

Sure, but that's bad behavior. It's grandparented in but should not exist, since it doesn't actually meet the requirements for a literal.
Notably, it can't handle worlds that weren't loaded at the time the syntax was parsed.

There's plans for a literal-like type called Contextless Expressions which do not require an event to be evaluated, like literals, but can change their value in between calls. That would be what a world expression should be, but the implementation of contextless expressions in events is proving tricky without breaking changes to many events due to Literal being part of the init signature.

commented

Sure, but that's bad behavior. It's grandparented in but should not exist, since it doesn't actually meet the requirements for a literal. Notably, it can't handle worlds that weren't loaded at the time the syntax was parsed.

There's plans for a literal-like type called Contextless Expressions which do not require an event to be evaluated, like literals, but can change their value in between calls. That would be what a world expression should be, but the implementation of contextless expressions in events is proving tricky without breaking changes to many events due to Literal being part of the init signature.

That sounds like a horrible idea, having the parsing essentially just pass it no matter the value, for it to be changed later. That's what Skript has been trying to avoid for years with Variables.

In your example, you just wouldn't make a world a literal, and Strings haven't been a literal up until recently.

commented

Just to clarify, a "Contextless Expression" still has a specific return type that doesn't change. It's the same thing as any expressions parsed with ParserInstance#getCurrentEvents being empty (that is, the trigger depends on no specific event at runtime)

commented

parsing essentially just pass it no matter the value, for it to be changed later

yeah i'm not sure where you got this from. a contextless expression is the exact same as any other expression, it just can be evaluated without an event. get() instead of get(Event).