Function

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

AndreasLK

Member
Mar 12, 2020
16
0
1
19
Hi. I'm only now starting on functions, could anyone help me with why this doesn't work? Thank you!

Code:
function gui(title: text):
    wait 1 tick
    open chest with 5 rows named "%{_title}%" to player
    wait 2 tick
    set {_slot} to 0
    loop 24 times:
        if {_slot} is 10:
            set {_slot} to 17
        else if {_slot} is 19:
            set {_slot} to 26
        else if {_slot} is 28:
            set {_slot} to 35
        else if {_slot} is 45:
            stop
        if inventory name of player's current inventory is "%{_title}%":
            if {_slot} is 0 or 2 or 4 or 6 or 8 or 10 or 18 or 26 or 36 or 38 or 40 or 42 or 44:
                format slot {_slot} of player with {b} to be unstealable
            else:
                format slot {_slot} of player with {r} to be unstealable
        add 1 to {_slot}

command /function:
    trigger:
        gui(test)
 
Your function doesn’t have a player variable in it. E.g function example(Player p):

Then to use the player you would do example(player/attacker/victim/etc)

In the function to use the player variable, you would use {_p}

sorry if it seems complicated, I’m on my phone. I recommend reading the docs on how to use functions before creating such a complicated function.

All my bests,
Raymond
 
I think you have to do the function like that:
function gui(p: player, title: text):
wait 1 tick
open chest with 5 rows named "%{_title}%" to {_p}
wait 2 tick
set {_slot} to 0
loop 24 times:
if {_slot} is 10:
set {_slot} to 17
else if {_slot} is 19:
set {_slot} to 26
else if {_slot} is 28:
set {_slot} to 35
else if {_slot} is 45:
stop
if inventory name of {_p}'s current inventory is "%{_title}%":
if {_slot} is 0 or 2 or 4 or 6 or 8 or 10 or 18 or 26 or 36 or 38 or 40 or 42 or 44:
format slot {_slot} of {_p} with {b} to be unstealable
else:
format slot {_slot} of {_p} with {r} to be unstealable
add 1 to {_slot}
command /function:
trigger:
gui(player, test)
 
Your function doesn’t have a player variable in it. E.g function example(Player p):

Then to use the player you would do example(player/attacker/victim/etc)

In the function to use the player variable, you would use {_p}

sorry if it seems complicated, I’m on my phone. I recommend reading the docs on how to use functions before creating such a complicated function.

All my bests,
Raymond
Seems a bit complicated but together with the other response I got it seems like I may understand it now. Thank you very much!
[doublepost=1601041780,1601041696][/doublepost]
I think you have to do the function like that:
function gui(p: player, title: text):
wait 1 tick
open chest with 5 rows named "%{_title}%" to {_p}
wait 2 tick
set {_slot} to 0
loop 24 times:
if {_slot} is 10:
set {_slot} to 17
else if {_slot} is 19:
set {_slot} to 26
else if {_slot} is 28:
set {_slot} to 35
else if {_slot} is 45:
stop
if inventory name of {_p}'s current inventory is "%{_title}%":
if {_slot} is 0 or 2 or 4 or 6 or 8 or 10 or 18 or 26 or 36 or 38 or 40 or 42 or 44:
format slot {_slot} of {_p} with {b} to be unstealable
else:
format slot {_slot} of {_p} with {r} to be unstealable
add 1 to {_slot}
command /function:
trigger:
gui(player, test)
I'll see if it works. Thank you!
 
Status
Not open for further replies.