add 1 to variable not working

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

  • 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.

Deacon

Member
Apr 17, 2017
12
0
1
33
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:
on damage:
    if attacker is a player:
        set {lastAttacked.%victim%} to "%attacker%"
        stop

on damage:
    damage cause is fall:
        if {induel.%victim%} is true:
            if {induel.%{lastAttacked.%victim%}%} is true:
                execute console command "/warp Lobby %victim%"
                execute console command "/warp Lobby %{lastAttacked.%victim%}%"
                heal victim
                heal {lastAttacked.%victim%}
                execute console command "/minecraft:scoreboard players add %{lastAttacked.%victim%}% Wins 1"
                add 1 to {sumoWins.%{lastAttacked.%victim%}%}
                broadcast "{@prefix} &e%{lastAttacked.%victim%}% &7beat &e%victim% &7in a duel."
                set {bd.active.%victim%} to false
                set {bd.active.%{lastAttacked.%victim%}%} to false
                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?
 
its most likely because of this line
code_language.skript:
set {lastAttacked.%victim%} to "%attacker%"
you are setting a variable to a string, then treating it like an entity/player
 
  • Like
Reactions: Hypenexy
its most likely because of this line
code_language.skript:
set {lastAttacked.%victim%} to "%attacker%"
you are setting a variable to a string, then treating it like an entity/player
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.
 
"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%"
I don’t exactly understand what you’re saying, can you elaborate please?
 
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:
on damage:
    if attacker is a player:
        set {lastAttacked.%victim%} to "%attacker%"
        stop

on damage:
    damage cause is fall:
        if {induel.%victim%} is true:
            if {induel.%{lastAttacked.%victim%}%} is true:
                execute console command "/warp Lobby %victim%"
                execute console command "/warp Lobby %{lastAttacked.%victim%}%"
                heal victim
                heal {lastAttacked.%victim%}
                execute console command "/minecraft:scoreboard players add %{lastAttacked.%victim%}% Wins 1"
                add 1 to {sumoWins.%{lastAttacked.%victim%}%}
                broadcast "{@prefix} &e%{lastAttacked.%victim%}% &7beat &e%victim% &7in a duel."
                set {bd.active.%victim%} to false
                set {bd.active.%{lastAttacked.%victim%}%} to false
                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?
I don't know why this does not work but to add or subtract to a variable I usually do it like this
Code:
#is faster this way
Set {example.var} to {example.var} + 1
Set {example.var} to {example.var} - 1
Set {example.var} to {example.var} + {other.example.var}
Set {example.var} to {example.var} - {other.example.var}
 
I don't know why this does not work but to add or subtract to a variable I usually do it like this
Code:
#is faster this way
Set {example.var} to {example.var} + 1
Set {example.var} to {example.var} - 1
Set {example.var} to {example.var} + {other.example.var}
Set {example.var} to {example.var} - {other.example.var}
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?
 
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?
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
 
Last edited:
Status
Not open for further replies.