Solved Counting Variables

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

ezmann!44

Member
Jul 2, 2017
35
1
0
26
Hello, I'd like to count my variables. How could I do it?

{Variable2} is Name, Name, Name

You can see there is 3 words there.
How can i count it? Then broadcast it as "3"
 
A bit confused as to what you mean, but this may help. When you set a variable like {Variable2} you can only set it to 1 thing.
You can, however, add the words to a list variable like this {Variable2::*}.
So then {Variable2::*} is the list containing Name1, name2 and name3.
To broadcast a count of the number of contents in that list you'd need to set a separate variable that represents the current number on the list. It'd look potentially like this:
code_language.skript:
command /add <text>:
    trigger:
#This adds your name to the list
        add arg 2 to {Variable2::*}
#Here if the list count hasnt been set it will start at 0
        if {name_count} is not set:
            set {name_count} to 0
#once a note is added it adds 1 to the total note amount.
        set {name_count} to {name_count} + 1
You'd do the same when you remove a name only you'd take away from the total list count instead like this:
code_language.skript:
set {name_count} to {name_count} - 1
Then when you want to broadcast the total amount the list contains you only need to do something like:
code_language.skript:
broadcast "%{name.count}%"
 
  • Like
Reactions: ezmann!44
A bit confused as to what you mean, but this may help. When you set a variable like {Variable2} you can only set it to 1 thing.
You can, however, add the words to a list variable like this {Variable2::*}.
So then {Variable2::*} is the list containing Name1, name2 and name3.
To broadcast a count of the number of contents in that list you'd need to set a separate variable that represents the current number on the list. It'd look potentially like this:
code_language.skript:
command /add <text>:
    trigger:
#This adds your name to the list
        add arg 2 to {Variable2::*}
#Here if the list count hasnt been set it will start at 0
        if {name_count} is not set:
            set {name_count} to 0
#once a note is added it adds 1 to the total note amount.
        set {name_count} to {name_count} + 1
You'd do the same when you remove a name only you'd take away from the total list count instead like this:
code_language.skript:
set {name_count} to {name_count} - 1
Then when you want to broadcast the total amount the list contains you only need to do something like:
code_language.skript:
broadcast "%{name.count}%"
Although that would work you could simply
code_language.skript:
broadcast "%size of {Variable2::*}%"
 
  • Like
Reactions: ezmann!44
Won't work :'(

code_language.skript:
    set {_slot} to "%size of {_result1::*}%"
    broadcast "&b%{_slot}%" #works - broadcasts 3
    set slot {_slot} of {_executer}'s current inventory to book and quill named "wont work?" with lore ""

{_executer} is %player%, this is in a function

using Skript Dev 25.

How do i fix this?
[doublepost=1499977729,1499976695][/doublepost]@Wynnevir
 
Won't work :'(

code_language.skript:
    set {_slot} to "%size of {_result1::*}%"
    broadcast "&b%{_slot}%" #works - broadcasts 3
    set slot {_slot} of {_executer}'s current inventory to book and quill named "wont work?" with lore ""

{_executer} is %player%, this is in a function

using Skript Dev 25.

How do i fix this?
[doublepost=1499977729,1499976695][/doublepost]@Wynnevir

Parse the variable set to the size as a number.
code_language.skript:
set {_slot} to "%size of {test::*}%" parsed as number
 
  • Like
Reactions: ezmann!44
Status
Not open for further replies.