Solved Percentage loop time

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

Aralwen

Active Member
May 26, 2017
164
14
18
25
Hello ! I'm looking for a system for computational fans ! I would like it to show a percentage before the end of the loop. For example, if it's the fourth loop, it will show 90%

Code:
code_language.skript:
command /try:
    trigger:
        loop 5 times:
            broadcast "%loop-value%"


Thank's in advance.
Aralwen
 
Im not 100% sure if this is what you are looking for, I'm only 90% sure it is <--- get it?!?!
anyways
code_language.skript:
command /try:
    trigger:
        loop 5 times:
            broadcast "%loop-value%"
            if loop-value = 4:
                broadcast "90%"
 
Im not 100% sure if this is what you are looking for, I'm only 90% sure it is <--- get it?!?!
anyways
code_language.skript:
command /try:
    trigger:
        loop 5 times:
            broadcast "%loop-value%"
            if loop-value = 4:
                broadcast "90%"
Thank you, but it's not really that. I would like a system that can convert to a percentage based on the number of loops that remain.

I improved my code to make it clearer :

code_language.skript:
command /try:
    trigger:
        set {_loopMax} to 5
        loop 5 times:
            wait 1 second
            broadcast "%loop-value% / %{_loopMax}%"  #Here display a percentage
 
Ahh.... duh, that makes more sense
code_language.skript:
command /try:
    trigger:
        loop 5 times:
            wait 1 second
            set {_perc} to (100 / 5) * loop-value
            broadcast "%{_perc}%%%"#!<-- the 3 % is there for a reason, dont worry its not a mistake
 
Ahh.... duh, that makes more sense
code_language.skript:
command /try:
    trigger:
        loop 5 times:
            wait 1 second
            set {_perc} to (100 / 5) * loop-value
            broadcast "%{_perc}%"
You're genius, really thank you. I just have one last problem,

uWyyaDT.png


the percentage sign can not be broadcast, I searched a little, and apparently we can't save. It is possible by doing :

code_language.skript:
broadcast "%{_perc}% %%"

But not one, have you an idea?

code_language.skript:
broadcast "%{_perc}% %"
 
Oh hehe, yeah i edited it i guess after you copied it
if you scroll back up to my post you will see it there...
like this
code_language.skript:
broadcast "%{_perc}%%%"
 
  • Like
Reactions: Aralwen
Oh hehe, yeah i edited it i guess after you copied it
if you scroll back up to my post you will see it there...
like this
code_language.skript:
broadcast "%{_perc}%%%"
Great job, thanks again for everything !
 
Excuse me for bothering you again, but I have a question : Is it possible to have this system display only 5%?

5%, 10%, 15%, 20%, 25% ...
and not others

Other question : By not taking into account my request above : Is it possible to get only whole numbers?
Example: 28,8 % => 28 %, 37,2% => 37 % etc ...
 
okay for question #1 This will work.... its just multiplying 5 by the loop value (which is the number of the loop)
code_language.skript:
command /try:
    trigger:
        loop 5 times:
            wait 1 second
            set {_perc} to 5 * loop-value
            broadcast "%{_perc}%%%"

For question #2 Skript has a built in rounding function
code_language.skript:
round(n: number)
This will round up and down accordingly
depending how you are planning in using that in script, you could do something like
**This is just an unnecessary example, since 5 * something is already rounded, but just to give you an idea of how it would work
code_language.skript:
set {_perc} to round(5 * loop-value)
[doublepost=1534584634,1534584482][/doublepost]Heres another example:
So take the original one I sent you... and lets pretend we change 100 to 99
code_language.skript:
command /try:
    trigger:
        loop 5 times:
            wait 1 second
            set {_perc} to (99 / 5) * loop-value
            broadcast "%{_perc}%%%"
the output would be as follows
code_language.skript:
[02:28:40 INFO]: 19.8%
[02:28:40 INFO]: 39.6%
[02:28:41 INFO]: 59.4%
[02:28:41 INFO]: 79.2%
[02:28:41 INFO]: 99%
but if we throw that function in there to round it
code_language.skript:
command /try:
    trigger:
        loop 5 times:
            wait 5 ticks
            set {_perc} to round((99 / 5) * loop-value)
            broadcast "%{_perc}%%%"
the outcome would be as follows
code_language.skript:
[02:28:51 INFO]: 20%
[02:28:52 INFO]: 40%
[02:28:52 INFO]: 59%
[02:28:52 INFO]: 79%
[02:28:52 INFO]: 99%
 
okay for question #1 This will work.... its just multiplying 5 by the loop value (which is the number of the loop)
code_language.skript:
command /try:
    trigger:
        loop 5 times:
            wait 1 second
            set {_perc} to 5 * loop-value
            broadcast "%{_perc}%%%"

For question #2 Skript has a built in rounding function
code_language.skript:
round(n: number)
This will round up and down accordingly
depending how you are planning in using that in script, you could do something like
**This is just an unnecessary example, since 5 * something is already rounded, but just to give you an idea of how it would work
code_language.skript:
set {_perc} to round(5 * loop-value)
[doublepost=1534584634,1534584482][/doublepost]Heres another example:
So take the original one I sent you... and lets pretend we change 100 to 99
code_language.skript:
command /try:
    trigger:
        loop 5 times:
            wait 1 second
            set {_perc} to (99 / 5) * loop-value
            broadcast "%{_perc}%%%"
the output would be as follows
code_language.skript:
[02:28:40 INFO]: 19.8%
[02:28:40 INFO]: 39.6%
[02:28:41 INFO]: 59.4%
[02:28:41 INFO]: 79.2%
[02:28:41 INFO]: 99%
but if we throw that function in there to round it
code_language.skript:
command /try:
    trigger:
        loop 5 times:
            wait 5 ticks
            set {_perc} to round((99 / 5) * loop-value)
            broadcast "%{_perc}%%%"
the outcome would be as follows
code_language.skript:
[02:28:51 INFO]: 20%
[02:28:52 INFO]: 40%
[02:28:52 INFO]: 59%
[02:28:52 INFO]: 79%
[02:28:52 INFO]: 99%

Sincerely thanks for the explanations, I understood everything. I just have a problem with my request 1, it does not work :

code_language.skript:
set {_perc} to (100 / 5) * loop-value + 5 * loop-value
 
im a bit confused as what you are hoping the outcome of this "set {_perc} to (100 / 2) * loop-value + 5 * loop-value" would be?
Lets say the loop value is 1... what are you hoping the answer would be? This way I can sort out the math for you

EDIT: I ran it in console and i get
code_language.skript:
[02:39:35 INFO]: 55%
[02:39:35 INFO]: 110%
[02:39:35 INFO]: 165%
[02:39:36 INFO]: 220%
[02:39:36 INFO]: 275%
im just not sure what you are hoping for
 
im a bit confused as what you are hoping the outcome of this "set {_perc} to (100 / 2) * loop-value + 5 * loop-value" would be?
Lets say the loop value is 1... what are you hoping the answer would be? This way I can sort out the math for you

EDIT: I ran it in console and i get
code_language.skript:
[02:39:35 INFO]: 55%
[02:39:35 INFO]: 110%
[02:39:35 INFO]: 165%
[02:39:36 INFO]: 220%
[02:39:36 INFO]: 275%
im just not sure what you are hoping for

No, I want to get the percentages:

5%
10%
15%
20%
25%
30%
35%
40%
45%
50%
-> 100%
 
ohhhh gotcha... sorry i didn't realize you were wanting to add more loops
code_language.skript:
command /try:
    trigger:
        loop 20 times:
            wait 5 ticks
            set {_perc} to 5 * loop-value
            broadcast "%{_perc}%%%"
 
ohhhh gotcha... sorry i didn't realize you were wanting to add more loops
code_language.skript:
command /try:
    trigger:
        loop 20 times:
            wait 5 ticks
            set {_perc} to 5 * loop-value
            broadcast "%{_perc}%%%"
Do not worry, my explanations were confusing xD
Thank you again, you are awesome
 
You are welcome :emoji_slight_smile:
Ah I still have a problem xD
If there are 60 loops, it exceeds 100% (105, 110 ...). Is not there a way to fix that? So that it always adapts according to the loops.
Otherwise it does not matter, you did so much xD
 
Funny you should ask, Im working on doing that right now.... i'll send it when im finished :emoji_slight_smile:
[doublepost=1534586387,1534586170][/doublepost]okay here you go... i added a number into the command, so do /try <number here> then it will loop that many times and do the percent for the correct amount
code_language.skript:
command /try <integer>:
    trigger:
        set {_loop} to arg-1
        loop arg-1 times:
            wait 1 tick
            set {_perc} to round((100 / {_loop}) * loop-value)
            broadcast "%{_perc}%%%"
 
Funny you should ask, Im working on doing that right now.... i'll send it when im finished :emoji_slight_smile:
[doublepost=1534586387,1534586170][/doublepost]okay here you go... i added a number into the command, so do /try <number here> then it will loop that many times and do the percent for the correct amount
code_language.skript:
command /try <integer>:
    trigger:
        set {_loop} to arg-1
        loop arg-1 times:
            wait 1 tick
            set {_perc} to round((100 / {_loop}) * loop-value)
            broadcast "%{_perc}%%%"
Frankly a huge thank you for taking so much time for me. I let you rest and help others! :emoji_grin:
 
Status
Not open for further replies.