Solved Compare question

  • Welcome to skUnity!

    Welcome to skUnity! This is a forum where members of the Skript community can communicate and interact. Skript Resource Creators can post their Resources for all to see and use.

    If you haven't done so already, feel free to join our official Discord server to expand your level of interaction with the comminuty!

    Now, what are you waiting for? Join the community now!

  • LOOKING FOR A VERSION OF SKRIPT?

    You can always check out skUnity Downloads for downloads and any other information about Skript!

Status
Not open for further replies.

_PAPER_PLANE_

Member
Jan 21, 2022
41
0
6
I want to confirm on the second line that the player has the item and I have enough items on me, but it still judges it as not having it

I have confirmed that the contents of {_item} and the items in my backpack are "cobblestone block"


Code:
function money(p: player, n: number, item: item, price: number):
    {_p} has {_n} of {_item}:  ←here
        remove {_n} of {_item} from {_p}
        add {_price} to money of {_p}
    else:
        send "you don't have enough items" to {_p}
        play sound "block.note_block.pling" with volume 2 and pitch 0.5 to {_p}
on inventory click:
    name of event-inventory is "menu":
        cancel event
        set {_item1} to type of event-item
        index of event-slot = 0:
            money(player, 1, {_item1}, 0.5)
 
Last edited:
I want to confirm on the second line that the player has the item and I have enough items on me, but it still judges it as not having it

I have confirmed that the contents of {_item} and the items in my backpack are "cobblestone block"


Code:
function money(p: player, n: number, item: item, price: number):
    {_p} has {_n} of {_item}:  ←here
        remove {_n} of {_item} from {_p}
        add {_price} to money of {_p}
    else:
        send "you don't have enough items" to {_p}
        play sound "block.note_block.pling" with volume 2 and pitch 0.5 to {_p}
on inventory click:
    name of event-inventory is "menu":
        cancel event
        set {_item1} to type of event-item
        index of event-slot = 0:
            moneyoptionclick(player, 1, {_item1}, 0.5)
you're calling a different function when the player clicks the item?
 
I want to confirm on the second line that the player has the item and I have enough items on me, but it still judges it as not having it

I have confirmed that the contents of {_item} and the items in my backpack are "cobblestone block"


Code:
function money(p: player, n: number, item: item, price: number):
    {_p} has {_n} of {_item}:  ←here
        remove {_n} of {_item} from {_p}
        add {_price} to money of {_p}
    else:
        send "you don't have enough items" to {_p}
        play sound "block.note_block.pling" with volume 2 and pitch 0.5 to {_p}
on inventory click:
    name of event-inventory is "menu":
        cancel event
        set {_item1} to type of event-item
        index of event-slot = 0:
            money(player, 1, {_item1}, 0.5)
I tested out this code, and it works, so your issue might be with detecting the inventory itself, you might want to switch to metadata instead of name of the inventory here is a tutorial about metadata.
However if you still choose to use the name, send the code of the inventory as well, because skript also recognizes and compares colors
 
  • Like
Reactions: _PAPER_PLANE_
adding on to what @xdh said, you can also fix color checking in names by making skript read the gui name as uncolored. I dont recommend this though, because if you have multiple menus with the same name but different colors it will trigger both.
Code:
if uncolored name of event-inventory is "name":
 
I tested out this code, and it works, so your issue might be with detecting the inventory itself, you might want to switch to metadata instead of name of the inventory here is a tutorial about metadata.
However if you still choose to use the name, send the code of the inventory as well, because skript also recognizes and compares colors
Oh, it turns out that there are three ways, I read this to know, I have been using variables + inventory name, let me change my code to try
[doublepost=1673690991,1673687602][/doublepost]I replaced the GUI with metadata, but it still doesn't work.
Still output "you don't have enough items"
Or do you need the full .sk file?
 

Attachments

  • moneyshop.sk
    5.9 KB · Views: 76
Oh, it turns out that there are three ways, I read this to know, I have been using variables + inventory name, let me change my code to try
[doublepost=1673690991,1673687602][/doublepost]I replaced the GUI with metadata, but it still doesn't work.
Still output "you don't have enough items"
Or do you need the full .sk file?
I'll test it out tomorrow and I will let you know.
 
I also changed a little to make it easier for you to read, thank you very much!
I apologize for the late reply, I completely forgot! I have great news! I have found your issue

Code:
function moneyoptionclick(p: player, n: number, item: text, price: number):
Your issue is in the item variable, because you're trying to compare an itemtype with text, now if you were to change it to an itemtype like this:
Code:
function moneyoptionclick(p: player, n: number, item: itemtype, price: number):

it should work.
 
  • Like
Reactions: Merrical
I apologize for the late reply, I completely forgot! I have great news! I have found your issue

Code:
function moneyoptionclick(p: player, n: number, item: text, price: number):
Your issue is in the item variable, because you're trying to compare an itemtype with text, now if you were to change it to an itemtype like this:
Code:
function moneyoptionclick(p: player, n: number, item: itemtype, price: number):

it should work.
That's okay, but you solved this problem that has been bothering me for a long time, thank you very much for your help! (* >ω<)
 
Status
Not open for further replies.