Skript icon indicating copy to clipboard operation
Skript copied to clipboard

Add timespan expression

Open TUCAOEVER opened this issue 2 years ago • 8 comments

Skript/Server Version

Skript version 2.6.3
Customize Minecraft's mechanics with simple scripts written in plain English sentences.
Website: https://skriptlang.github.io/Skript
Authors: Njol, Mirreski, SkriptLang Team and Contributors

Server Version: 1.16.5

Bug Description

when i am using variables in timespan, it tells me "can't understand" while using wait 10 ticksis fine

set {_x} to 10 wait {_x} ticksdoesn't work

Expected Behavior

Using variable in timespan expression.

Steps to Reproduce

set {_x} to 10 wait {_x} ticks wrong

set {_x} to 10 wait "%{_x}% ticks" parsed as timespancorrect

wait 10 ticks correct

similar situation

send titile ... to player for {_x} ticks wrong

Errors or Screenshots

No response

Other

No response

Agreement

  • [X] I have read the guidelines above and affirm I am following them with this report.

TUCAOEVER avatar Sep 08 '22 02:09 TUCAOEVER

This isn't so much a bug but rather how skript works since you're using a variable that already has a type instead of raw data like an option you're basically doing (number) (string) instead of timespan if you want this to work you'd need to set the variable to a timespan so instead of 10 it should be 10 seconds and use wait {_var}

if you want to use wait x seconds you'd need to do an option like so while this removes your flexability in variables it at least fixes the issue wait x seonds x being a number

options:
  wait: 10
  
every {@wait} seconds:
  broadcast 10 seconds

Fusezion avatar Sep 08 '22 02:09 Fusezion

This isn't so much a bug but rather how skript works since you're using a variable that already has a type instead of raw data like an option you're basically doing (number) (string) instead of timespan if you want this to work you'd need to set the variable to a timespan so instead of 10 it should be 10 seconds and use wait {_var}

if you want to use wait x seconds you'd need to do an option like so while this removes your flexability in variables it at least fixes the issue wait x seonds x being a number

options:
  wait: 10
  
  every {@wait} seconds:
    broadcast 10 seconds

But in most cases, i would like to get value from files, or i need some calculation before getting required timespan in order to customize those effects like send title, option doen't work in these situation.

TUCAOEVER avatar Sep 08 '22 02:09 TUCAOEVER

But in most cases, i would like to get value from files, or i need some calculation before getting required timespan in order to customize those effects like send title, option doen't work in these situation.

That's where an on load event would be good as you can then parse, and customize within variables then call the variable in whatever events when needed could also incorporate with options to make editing easier for people outside of yourself who see the skript

I don't see skript really having any benefit from adding the ability to just enter a number as you want above it seems inefficient and doesn't fit well with skript for the most part

Fusezion avatar Sep 08 '22 02:09 Fusezion

I don’t think so, I talked about this “bug” early this morning in my discord channel, serval server owners encountered this issue from version 2.4 till now, and for them, currently, using string parse is the only way to avoid this issue. U say I could just parse during “on load” but in most cases calculations is based on player’s stats value or functions which may changed a lot, those situations it out of “on load”’s reach.

TUCAOEVER avatar Sep 08 '22 02:09 TUCAOEVER

For me, I usually find it frustrating to parse the timespan every time after some calculation, hence I do insist that adding a new expression that converts {_x} seconds/{_x} ticks etc. automatically into a timespan would be quite helpful.

theOldSheep avatar Sep 08 '22 03:09 theOldSheep

This is how it should work, litterals can't accept variables and using EffParse is the way to make it work so currently there is no issue here however, this can be marked as enhancement to add an expression for timespan to allow variables but for this I would like to get opinions from the team in case it can be done in a better way or it may cause conflicts

AyhamAl-Ali avatar Sep 08 '22 09:09 AyhamAl-Ali

This work well

set {_x} to "10 ticks" parsed as timespan
wait {_x}

Soufreur78 avatar Sep 09 '22 11:09 Soufreur78

You can set a timespan to a variable. I don't know what examples those are but you can't have wait in the middle of the syntax

set {_cooldown} to 5 seconds and 2 ticks
while {_cooldown} is greater than 0 seconds:
    wait a tick
    remove a tick from {_cooldown}
message "5 seconds and 2 ticks have past"

Note: Yes, Skript is smart enough to distinguish between a list and a single timespan in line 1 of this example.

If you want to do something like this, consider using timespan all together instead of the variable being an integer and parsing the ticks each time.

Adding an expression for this will either just simply override the classinfo parse of the Timespan, cause conflicts, or just be a fallback for when the classinfo parse fails. Sure it's a simple fix, but it may need some extensive testing as the delay is an important syntax.

You can also add expression parsing to the parse of the classinfo timespan, but that's a bad idea as it's called frequently.

TheLimeGlass avatar Sep 16 '22 01:09 TheLimeGlass