Skip to content

Functions behave inappropriately with Auto-Args #8187

@MinecraftNight4

Description

@MinecraftNight4

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugAn issue that needs to be fixed. Alternatively, a PR fixing an issue.completedThe issue has been fully resolved and the change will be in the next Skript update.

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions