How can I save a entity for another code?

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

    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.

AwesomeGunGuy

New Member
Mar 5, 2018
5
0
0
Hello all,
I am trying to let the player execute a command after he interacted with an entity before something will happen to that entity. How can I do this?
Here is an simple example

code_language.skript:
on right click on pig:
    set {askquestion.%player%} to 1
    send "want to change the name?" to player
    send "/yes or /no" to player

command /yes:
    trigger:
        if {askquestion.%player%} is 1:
            set entity's display name to "example"
            set {askquestion.%player%} to 0
            send "name changed!" to player
command /no:
    trigger:
        if {askquestion.%player%} is 1:
            set {askquestion.%player%} to 0
            send "name unchanged" to player

This example wont work, but how can I make it work?
Thanks in advance!
 
You can store entities in variables, it just doesn't persist over server restarts. Set the player's variable to the entity itself then you should be able to see its name by referencing the variable.

Also, you should be deleting the askquestion variable instead of setting it to 0. It's better to remove variables once they're not being used instead of setting them to some sort of pseudo-empty value since they're just taking up unnecessary space in your variable storage, which affects load times (minorly, but it will add up if you do stuff like this often).
 
  • Like
Reactions: AwesomeGunGuy
Status
Not open for further replies.