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!

  2. LOOKING FOR A VERSION OF SKRIPT?

    You can always check out our Wiki for downloads and any other information about Skript!

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

add 1 to variable not working

Discussion in 'Skript' started by Deacon, Aug 11, 2019.

Thread Status:
Not open for further replies.
  1. Deacon

    Deacon Member

    Joined:
    Apr 17, 2017
    Messages:
    12
    Likes Received:
    0
    Hi there,

    I have a duels skript set up on my server, and the effect "add 1 to {variable}" won't work.

    Here's my code:

    Code (Text):
    1. on damage:
    2.     if attacker is a player:
    3.         set {lastAttacked.%victim%} to "%attacker%"
    4.         stop
    5.  
    6. on damage:
    7.     damage cause is fall:
    8.         if {induel.%victim%} is true:
    9.             if {induel.%{lastAttacked.%victim%}%} is true:
    10.                 execute console command "/warp Lobby %victim%"
    11.                 execute console command "/warp Lobby %{lastAttacked.%victim%}%"
    12.                 heal victim
    13.                 heal {lastAttacked.%victim%}
    14.                 execute console command "/minecraft:scoreboard players add %{lastAttacked.%victim%}% Wins 1"
    15.                 add 1 to {sumoWins.%{lastAttacked.%victim%}%}
    16.                 broadcast "{@prefix} &e%{lastAttacked.%victim%}% &7beat &e%victim% &7in a duel."
    17.                 set {bd.active.%victim%} to false
    18.                 set {bd.active.%{lastAttacked.%victim%}%} to false
    19.                 delete {arena.1}
    The part that isn't working is "add 1 to {sumoWins.%{lastAttacked.%victim%}%}"

    Everything else in the trigger is working, for exampel warping both players to spawn, and broadcasting the death message.

    Any ideas why it isn't working?
     
  2. ShaneBee

    Moderator Resource Staff Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,172
    Likes Received:
    215
    its most likely because of this line
    Code (Skript):
    1. set {lastAttacked.%victim%} to "%attacker%"
    you are setting a variable to a string, then treating it like an entity/player
     
    • Like Like x 1
  3. malia

    malia Well-Known Member

    Joined:
    Jul 24, 2019
    Messages:
    314
    Likes Received:
    21
    Code (Text):
    1. set {lastAttacked.%victim%} to attacker
    2.  
     
  4. Deacon

    Deacon Member

    Joined:
    Apr 17, 2017
    Messages:
    12
    Likes Received:
    0
    Thanks for your reply, but I don’t think that is the problem. I have a command, /setwins, which does this:

    set (sumoWins.%{lastAttacked.%victim%}%} to arg-2

    which works completely fine in changing their wins. It’s just the “add 1 to” that won’t work in this situation.
     
  5. malia

    malia Well-Known Member

    Joined:
    Jul 24, 2019
    Messages:
    314
    Likes Received:
    21
    "add 1 to {sumoWins.%{lastAttacked.%victim%}%}" I am not so sure if this is right...

    set (sumoWins.%{lastAttacked.%victim%}%} to arg-2 != set {lastAttacked.%victim%} to "%attacker%"
     
  6. Deacon

    Deacon Member

    Joined:
    Apr 17, 2017
    Messages:
    12
    Likes Received:
    0
    I don’t exactly understand what you’re saying, can you elaborate please?
     
  7. Mich7272

    Mich7272 Member

    Joined:
    Apr 12, 2019
    Messages:
    49
    Likes Received:
    0
    I don't know why this does not work but to add or subtract to a variable I usually do it like this
    Code (Text):
    1. #is faster this way
    2. Set {example.var} to {example.var} + 1
    3. Set {example.var} to {example.var} - 1
    4. Set {example.var} to {example.var} + {other.example.var}
    5. Set {example.var} to {example.var} - {other.example.var}
     
  8. Deacon

    Deacon Member

    Joined:
    Apr 17, 2017
    Messages:
    12
    Likes Received:
    0
    It worked! When a player dies it adds a {sumoWin} to the winner! BUT, I have a command called /setwins, which essentially does this:

    /setwins <player> <text>

    then the trigger,

    set {sumoWins.%arg-1%} to arg-2

    it works and sets the player's wins to that, but if you set a player's wins to something then the player gets another win in a duel match, it just sets their wins back to 1. I'm not sure why. Is there a reason for this?
     
  9. Mich7272

    Mich7272 Member

    Joined:
    Apr 12, 2019
    Messages:
    49
    Likes Received:
    0
    because you have to do set {sumowins.%arg-1%} to {sumowins.%arg-1%} + arg-2
    or this one
    set {sumowins.%arg-1%} to {sumowins.%arg-1%} + arg-2 parsed as a number

    you have to set the variable to the variable then add with "+" or subtract wuth "-"

    for example
    var = 1

    set {var} to {var} + 1 #now var equals 2
    set {var} to {var} - 1 #now var equals 0
    also you can use like multiplication
    set {var} to {var} * 3 #now var equals 3

    now if you do set {var} to 4 #var will equal 4 or the number you place

    like I set to have to set the variable to the variable and then add or subtract
     
    #9 Mich7272, Aug 13, 2019
    Last edited: Aug 13, 2019
Thread Status:
Not open for further replies.

Share This Page

Loading...