Skript

Skript

788k Downloads

Functions behave inappropriately with Auto-Args

MinecraftNight4 opened this issue · 2 comments

commented

Skript/Server Version

[23:30:52 INFO]: [Skript] Skript's aliases can be found here: https://github.com/SkriptLang/skript-aliases
[23:30:52 INFO]: [Skript] Skript's documentation can be found here: https://docs.skriptlang.org/
[23:30:52 INFO]: [Skript] Skript's tutorials can be found here: https://docs.skriptlang.org/tutorials
[23:30:52 INFO]: [Skript] Server Version: 1.21.7-2472-4d5a8e6 (MC: 1.21.7)
[23:30:52 INFO]: [Skript] Skript Version: 2.12.2 (skriptlang-github)
[23:30:52 INFO]: [Skript] Installed Skript Addons: 
[23:30:52 INFO]: [Skript]  - SkJson v5.4.1 (https://skjson.coffeerequired.info)
[23:30:52 INFO]: [Skript]  - Skitch v1.5.0
[23:30:52 INFO]: [Skript]  - DiSky v4.24.0-beta3
[23:30:52 INFO]: [Skript]  - skript-reflect v2.6 (https://github.com/SkriptLang/skript-reflect)
[23:30:52 INFO]: [Skript] Installed dependencies: None

Bug Description

Functions that require optional arguments are behaving differently than expected.
Here is an example of a function that should return the Unix timestamp for the next day at the specified time:

local function test(h: number = 0, m: number = 0, s: number = 0) returns number:
	set {_set} to date((now formatted as "yyyy") parsed as number, (now formatted as "MM") parsed as number, (now formatted as "dd") parsed as number, {_h}, {_m}, {_s})
	set {_set} to unix timestamp of ({_set} + a day)
	if (unix timestamp of now) >= ({_set} - 86400):
		return (rounded {_set})
	return (rounded {_set} - 86400)

Expected Behavior

Using the mentioned function, if this is executed with a broadcast, both in the console and in the chat, the Unix value of the argued time should appear.

If the function is executed WITHOUT arguments, the server will have to calculate the Unix value of 0:00:00 hours by default.
broadcast test() This works!

If the function is executed with TWO or MORE arguments, the server will have to calculate the Unix value of the specified hour, minute, and second.
broadcast test(16,59,59) This works!

PROBLEM:
If the function is executed with ONLY ONE argument, the server will have to calculate the Unix value of the argued hour and set the minute and second to 00:00:

broadcast test(16)

  • EXPECTED BROADCAST: 1757876400 (Just an example)
  • CURRENT RESPONSE: Functions cannot be used here (or there is a problem with your arguments).

Steps to Reproduce

Load this función on a SK file and this will throw an error on the second broadcast:

local function test(h: number = 0, m: number = 0, s: number = 0) returns number:
	set {_set} to date((now formatted as "yyyy") parsed as number, (now formatted as "MM") parsed as number, (now formatted as "dd") parsed as number, {_h}, {_m}, {_s})
	set {_set} to unix timestamp of ({_set} + a day)
	if (unix timestamp of now) >= ({_set} - 86400):
		return (rounded {_set})
	return (rounded {_set} - 86400)

on load:
	broadcast test() #Works 
	broadcast test(16) #Fails 
	broadcast test(16:00) #Works

Errors or Screenshots

Image

Other

No response

Agreement

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

Confirmed on dev/feature, @Efnilite is this related to overloading?

commented

Thanks for the report! I have found the cause of the issue and opened a pull request for it to be fixed in our next release. If you would like, you can download the nightly build from the pull request (it is based on 2.12.2) and ensure that the fix works for you. Link is here (you must be signed into GitHub): https://github.com/SkriptLang/Skript/actions/runs/17698793714?pr=8189