Jump to content

Tutorial | Variables


UntitledGoose
 Share

Recommended Posts

Introduction

Variables are a form of data storage in Skript that allows you to store strings, integers, players, multiple players, etc. You will be learning how to use every type of variable in Skript, aswell as what each one is and does.

 

What you’ll learn about

  • Variable commonplace

  • How to set variables

  • Single value variables (‘Normal’ variables)

  • List variables

  • Local variables

  • Metadata tags

 

Variable commonplace

There are 2 key components to any variable: index and value

 

The index is like the name of your variable, if I had a variable named {epic}, the index would be ‘epic’.

The value is what your variable stores, if I had a variable that held the string “minehut.com”, the value would be “minehut.com”.

 

How to set variables

You can set variables with the effect Change: Set/Add/Remove/Delete/Reset. The syntax for this effect looks like:

(add|give) %objects% to %objects% _________

increase %objects% by %objects%____________

give %objects% %objects%___________________

set %objects% to %objects%_________________

remove (all|every) %objects% from %objects% 

(remove|subtract) %objects% from %objects%_

reduce %objects% by %objects% _____________

(delete|clear) %objects%___________________

reset %objects%____________________________

 

So if I were to set a variable with this, it’d look like:

set {woohoo} to “Join minehut.com for quality servers today!”

 

Single value variables

Because I’m lazy, I’ll be referring to single value variables as normal variables so it’s easier for me to type and explain.

 

Normal variables can be thought of as envelopes, they can hold anything, but only 1 one of that something. Normal variables usually look like this: {index}, {my.awesome.variable}, etc. These variables can be set or retrieved anywhere within your script.

 

set {my.variable} to “a”  # Success! {my.variable} is now set to “a”______________

set {my.variable} to “a” and “b” # {my.variable} can only be set to one object, not more 

 

38Wl2JHGEWN8U3Ypp-rGVvtJNsm2vO982xZEUsybNMdHq4nigwnZxbq0SbjiOIgfOKhHb9rbafX_dsH-_Qr5qLwe5AFQu6S0fbnTi1qL517Tc__Ta_JDWcFX4Z5Xl6lmnSFMUYtv

 

List variables

List variables are like cardboard boxes, they can hold multiple items, compared to normal variables, which can only hold one thing.

 

In order for a list variable to hold multiple values, the index MUST end in ::*, and have nothing else after it (except for the closing })

 

List variables look like this:

{my::variable::*}

{my.variable::*}

{hello_there::*}

 

set {my.variable::*} to “a” and “b”  # Success! {my.variable::*} is now set to “a” and “b”

set {my::variable} to “a” and “b” # {my::variable} can only be set to one object, not more_

 

Local variables

Local variables are temporary variables. They can be either list variables or normal variables, but they will be deleted at the end of a trigger (the end of a command or event), and cannot be accessed by external triggers.

 

You can initiate a local variable by slapping a _ right before the index.

This will look like:

{_variable}

{_my.list::*}

{_hey::*}

{_}

 

Metadata tags

Metadata tags are [also temporary] variables, but they’re attached to an entity or block, and are flushed when the server restarts. Note that metadata tags can only hold one value.

 

This is the syntax for metadata tags:

metadata [(value|tag)[s]] %strings% of %metadataholders% 

%metadataholders%'[s] metadata [(value|tag)[s]] %string%

 

Note: %metadataholders% = entity or block

 

Examples of metadata tags:

set metadata tag “super cool” of player to true

delete metadata tag “epic” of target block____.

 

Conclusion

There you go! Now you’re a pro on everything Skript variables. Hope this tutorial helped clear up some fog, and be sure to comment on this post if I missed everything. 🙂

  • Like 4

VIP since January 7th, 2020

Support since September 19th, 2020

Helper since November 3rd, 2020

Moderator since March 8th, 2021

unknown.png

5.png.e14b1bf83edf0ac2edc1bfb822177184.png

image.png.fe30b7b2c0be5a541ba4ed2187b23030.png

Link to comment
Share on other sites

Very good tutorial for beginners. Explains everything fully detailed, but not confusingly.

⁃ Owner of Shulked
Skript Developer ⁃

DEFAULT / 2018
[VIP] / 2019

DISCORD: Cosmos#2576 ⁃
IGN: Stuudium (soon to change) ⁃

- *former* ADMIN on Versa Realms -
-
MODERATOR on EddyEvents -


85ae165db1ccfa5faf3937bda91316da-png.jpg.2508c19c38e80ab6cd03fd909b03a9b4.jpg
signature.gif.ae17aaf0a0cfdc3515d822c66c2a0056.gif.65475d1df01fa6283bf9c3cdb19c7b97.gif

Link to comment
Share on other sites

  • 2 weeks later...
  • 8 months later...
12 minutes ago, Madlirex said:

How to make private variable like your money or balance?

Hi Madlirex!

I will now lock this post. Please do not reply to posts that have not been responded to in over a month.

You can always create your own post and be sure to post in under the right category.

Thanks!😊

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share



×
×
  • Create New...