#Refresh GUI while player is in GUI
1 messages · Page 1 of 1 (latest)
May I ask, why wouldn't you want to use a function for this? It's much more efficient.
thx, but im actully not good bcz im a newer here
i donot know how to use fuctions and what is fuction
i will sreach
functions are easy, ill give an example.
Definition of a function from google: In computer programming, a function or subroutine is a sequence of program instructions that performs a specific task, packaged as a unit. This unit can then be used in programs wherever that particular task should be performed. Basically a way of reusing bits of code without typing it all again.
Example of a functioning GUI using the skript-gui addon:
function openGUI(p: player):
create a gui with chest inventory with 3 rows named "Test":
make gui 0 with dirt
open last gui to {_p}
command /gui:
trigger:
openGUI(player)
As seen on the last line, I am passing a player argument in the function, passing the player themselves, so the function can use the player argument to open the gui to the player.
In the function, {_p} is the letter or whatever is in place of p: player, so if it is doo: player then the variable will be {_doo} for that argument of the function.
Then if I want to reload the GUI while the player is already in the GUI
(example code below)
on inventory click:
name of event-inventory is "Test"
if event-item is dirt:
openGUI(player)
By running that function again whilst the player is in the GUI, clicking the dirt runs that code and runs the function to open the gui to the player again. This "refreshes" the GUI.
I hope that helps
Note that the code for the GUI in these examples require the skript-gui addon, which can be found here
tysm man for all, but can the gui reload without any click event ? like reloading the lore ? so if i player put the mouse cursor on the item and there i lore "amount players in room: {var}" thats the var reloading ?
No worries, my hand really hurts now xD
Uh, you could create a loop to loop all the players viewing/in the gui and refresh it for the loop-player which would refresh it for everyone viewing the GUI.
In simple terms, loop-player stores the players in a loop, so if you do loop all players: you'd have to use loop-player to call that group of everyone that has been looped
like:
I'll see if I can make another example
every 10 seconds:
loop all players:
if name of loop-player's inventory is "Test":
openGUI(loop-player)
NOTE: It is not recommended to run frequent loops on a server with not that many resources, as it could lag and potentially crash your server. You could give it a go though.
This code has not been tested, it may not work.
should work
with my other pieces of exampe code it should anyway
how can i replace "openGUI" by smth thats is'nt function
so i can test my code
I suggest using function for your GUIs so you can refresh it easily
go based on what I have done in my example, try to understand what I've done
I've tried to write enough documentation in that message as much as I can
hopefully it will help
No problem, glad I could be of assistance
its , thanks alot , best one
functions are exactly the same as other code. only thing is u have to pass things in as paramters.
other than that its identical to normal code.
then you just call the function and its like copy/pasting the lines in there