Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with Returning Items from a Function #1747

Closed
Whimsyturtle opened this issue Dec 12, 2018 · 3 comments · Fixed by #4261
Closed

Issue with Returning Items from a Function #1747

Whimsyturtle opened this issue Dec 12, 2018 · 3 comments · Fixed by #4261
Labels
bug An issue that needs to be fixed. Alternatively, a PR fixing an issue. completed The issue has been fully resolved and the change will be in the next Skript update. priority: low Issues that are not harmful to the experience but are related to useful changes or additions.

Comments

@Whimsyturtle
Copy link
Member

Whimsyturtle commented Dec 12, 2018

Description

Functions that return multiple items (e.g. 2 diamonds) in reality return <none>

Steps to Reproduce

function test(c: number) :: item:
    set {_gem} to diamond
    return {_c} of {_gem}
    
function test2(c: number) :: item:
    return {_c} of diamond

command /testfunction:
    trigger:
        give player test(1) #Should give the command sender 1 diamond
        send "test(): Attempting to give %player% %test(1)%"
        give player test(2) #Should give the command sender 2 diamonds
        send "test(): Attempting to give %player% %test(2)%"
        give player test2(1) #Should give the command sender 1 diamond
        send "test2(): Attempting to give %player% %test2(1)%"
        give player test2(2) #Should give the command sender 2 diamonds
        send "test2(): Attempting to give %player% %test2(2)%"
        #In total, the command sender should recieve 6 diamonds, 3 from test() and 3 from test2()

Expected Behavior

The player should receive 6 diamonds

Errors / Screenshots

image

Note: After executing /testfunction, the player only recieves 3 diamonds (from test2())

Server Information

  • Server version/platform: 1.12.2 (Paper)
  • Skript version: 2.3-beta4

Additional Context

This issue didn't occur in Skript 2.2-dev37c, and only occurred when I updated the version of Skript (2.3-beta4)

@Blueyescat
Copy link
Contributor

Blueyescat commented Dec 14, 2018

Your description was wrong, it is not related to multiple items, but can confirm the same with 1.13.2


# {x} = 2
# {y} = diamond

function test() :: item:
	broadcast "&62 diamonds"
	broadcast "&6%class of 2 diamond%" # skript-mirror addon
	return 2 of diamond

function test1() :: item:
	broadcast "&a%{x} of {y}%"
	broadcast "&a%class of {x} of {y}%"
	return {x} of {y}

function test2() :: item:
	broadcast "&c%2 of {y}%"
	broadcast "&c%class of 2 of {y}%"
	return 2 of {y}

function test3() :: item:
	broadcast "&b%{x} of diamond%"
	broadcast "&b%class of {x} of diamond%"
	return {x} of diamond

image

First of all, shouldn't the X Of expression return item type instead of item stack? I see that it takes return type of the input expression, but it uses %itemstacks% so it always takes and returns an item stack even if we enter an item type. It may fix the issue when it takes %itemtypes%.

And these functions will work when you make the return type multiple (items) because item refers to item stack and items refers to item type, this is also a bad thing. So they will also work when you make the return type item type.

Not sure about why {x} of diamond works and others don't... Why it doesn't work when the return type is item stack and the return value is also an item stack, except {x} of diamond...

@TheBentoBox TheBentoBox added bug An issue that needs to be fixed. Alternatively, a PR fixing an issue. priority: low Issues that are not harmful to the experience but are related to useful changes or additions. labels Dec 14, 2018
@TheBentoBox
Copy link
Member

Really good investigation @Blueyescat , weird bug for sure

@bensku bensku added the completed The issue has been fully resolved and the change will be in the next Skript update. label Dec 19, 2018
bensku added a commit that referenced this issue Dec 19, 2018
@bensku
Copy link
Member

bensku commented Dec 19, 2018

Huh, this one was hard to track down. In the end, it turned out this was caused by two completely different bugs.

@bensku bensku closed this as completed Dec 22, 2018
APickledWalrus added a commit to APickledWalrus/Skript that referenced this issue Jan 21, 2023
This override was added many years ago to fix an issue (SkriptLang#1747) with the expression that occurred when using variables. This was because Skript could not properly convert variables during parse time. The proper fixes have been made with this branch and so this method is no longer needed. I've updated the test to include code from the original issue.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An issue that needs to be fixed. Alternatively, a PR fixing an issue. completed The issue has been fully resolved and the change will be in the next Skript update. priority: low Issues that are not harmful to the experience but are related to useful changes or additions.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants