How to make a function that checks the number of items in a container?

  • 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.

YK_DZ

Member
Jan 14, 2022
24
0
1
24
I have a function like this:
Code:
function invAmountMI(type: string,inv: inventory) :: number:

    set {_amount} to 0
  
    loop all items in {_inv}:
        if name of loop-item contains "{_type}":
            add 1 to {_amount}

    return {_amount}
      
on inventory click:
    set {_Aamount} to invAmountMI("Wood",event-inventory)
    send "%{_Aamount}%"
But when I click a inventory like chest inventory, the output is always 0
Then I change the Skript to this:
Code:
on inventory click:

    set {_amount} to 0
  
    loop all items in event-inventory:
        if name of loop-item contains "Wood":
            add 1 to {_amount}

    send "%{_amount}%"
And find that all things work well.
So how can I make a function to check the amount?
 
parameter {_type} is already a string, don't surround it with quotes
 
parameter {_type} is already a string, don't surround it with quotes
I remove that quotes, but the output is still 0

This is my Skript now:
Code:
function invAmountMI(id: string,inv: inventory) :: number:

    set {_amount} to 0
   
    loop all items in {_inv}:
        if name of loop-item contains {_id}:
            add 1 to {_amount}

    return {_amount}

on inventory click:
    set {_Aamount} to invAmountMI("Wood",event-inventory)
    send "%{_Aamount}%"
 
Last edited:
Code:
function invAmountMI(type: itemtype, inv: inventory) :: number:
 set {_amount} to 0
 loop all items in {_inv}:
  type of loop-item = {_type}:
   add 1 to {_amount}
 return {_amount}
    
on inventory click:
    set {_Aamount} to invAmountMI(type of clicked item, event-inventory)
    send "%{_Aamount}%"
 
Status
Not open for further replies.