problems with gui and variable

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

number52091

Member
Feb 24, 2024
14
0
1
29
So, I was making a skript and my goal was when a player right clicks on a gold block, an (existing) gui would open, in this case,

on right click on gold block:
if block below event-block is red wool:
open {_gui} to player


but then I looked for help and a friend told me, "if the premade gui is already stored in a variable, then you do"
So, how can I store my gui in variable to open existing gui when right clicked on gold block?
 
{_gui} will never be set to anything if you don't set it within the right click event, but I don't recommend saving the GUI to a global variable because it will never be deleted. Will you need to re-use this GUI in more than one place or just this one?
 
{_gui} will never be set to anything if you don't set it within the right click event, but I don't recommend saving the GUI to a global variable because it will never be deleted. Will you need to re-use this GUI in more than one place or just this one?
in more than one place, i guess.
 
In that case, I recommend you make the GUI in a function.
Python:
local function gui(p: player): #remove the "local" if you want to use this faction in other files
    set {_gui} to chest inventory with 3 rows #set the variable to a chest with the amount of rows
    #do set slots here
    open {_gui} to {_p} #{_p} refers to the player argument you plug in, as defined when we declared the function

on right click on gold block:
    if block below event-block is red wool:
        gui(player) #call the function and plug in the player as the {_p} argument
 
In that case, I recommend you make the GUI in a function.
Python:
local function gui(p: player): #remove the "local" if you want to use this faction in other files
    set {_gui} to chest inventory with 3 rows #set the variable to a chest with the amount of rows
    #do set slots here
    open {_gui} to {_p} #{_p} refers to the player argument you plug in, as defined when we declared the function

on right click on gold block:
    if block below event-block is red wool:
        gui(player) #call the function and plug in the player as the {_p} argument
I removed the "local" and it worked, Thanks bro!