1. 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!

Dismiss Notice
This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Use a Skript variable in a java plugin.

Discussion in 'Java' started by sandor_1234, Aug 26, 2017.

  1. sandor_1234

    sandor_1234 Active Member

    Joined:
    Jan 26, 2017
    Messages:
    165
    Likes Received:
    5
    So i am trying to grab a variable in my java code and i wanna check if it is set.
    I just found this thread:
    https://forums.skunity.com/threads/how-get-skript-variable.459/
    Which was really helpfull but i never really worked with java before so how would i use / call this function?
    This is what i am trying to achieve:
    Code (Java):
    1. public void onInteract(PlayerInteractEvent event) {
    2. #if {test::lol::%player%} is set{
    3. #Do stuff
    4. }
    5.  
    6. }
     
    #1 sandor_1234, Aug 26, 2017
    Last edited: Aug 26, 2017
  2. Best Answer:
    Post #2 by ShaneBee, Aug 26, 2017
  3. ShaneBee

    Moderator Resource Staff Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,179
    Likes Received:
    218
    • Like Like x 1
    • Useful Useful x 1
  4. ShaneBee

    Moderator Resource Staff Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,179
    Likes Received:
    218
    So i would have do do something like:
    Code (Java):
    1. public void onInteract(PlayerInteractEvent event) {
    2. Player p = event.getPlayer();
    3. Object variable = Variables.getVariable("{test::lol::" + p + "}", null, false);
    4. if variable != null{
    5. #My code here
    6. }
    7. }
    The {test::lol::" + p + "} part is probably wrong so how would i have to do that?
     
  5. ShaneBee

    Moderator Resource Staff Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,179
    Likes Received:
    218
    Without the braces, and you might be looking for the player name and not the player object in the string, a player object in a string returns more than its name. Use the Player#getName method for it.
     
    • Useful Useful x 1
  6. ShaneBee

    Moderator Resource Staff Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,179
    Likes Received:
    218
    Thanks allot for all the usefull information so far!
    Currently i have this code:
    Code (Java):
    1. public void onInteract(PlayerInteractEvent event) {
    2. Player p = event.getPlayer();
    3. String playerName = p.getName();
    4. Object variable = Variables.getVariable("k::lip::" + playerName, null, false);
    5. if( variable = null){
    6. #do stuff
    7. }
    But its not working, do i have to do anything else?
     
  7. ShaneBee

    Moderator Resource Staff Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,179
    Likes Received:
    218
    = is for assignation, you're setting the variable "variable" to null there, not comparing it with null. Use two equals (==) for comparison.

    Also, Java doesn't use # for comments, it uses // for single line comments or /* comment here */ for multi-line comments.
     
    • Useful Useful x 1
  8. ShaneBee

    Moderator Resource Staff Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,179
    Likes Received:
    218
    Hmm i used this skript:
    Code (Skript):
    1. set {k::lip::%player%} to "test"
    But if i use this:
    Code (Java):
    1. Object variable = Variables.getVariable("k::lip::" + playerName, null, false);
    2. Bukkit.broadcastMessage(variable);
    it just returns "null"
     
  9. ShaneBee

    Moderator Resource Staff Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,179
    Likes Received:
    218
    try making the player name lower case.
     
    • Useful Useful x 1
  10. ShaneBee

    Moderator Resource Staff Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,179
    Likes Received:
    218
    That worked thanks allot <3 .
     

Share This Page

Loading...