Skript Help - Stripping a Variable

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

    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.

GToTheG

Member
Jan 26, 2017
35
0
8
Hello all.

How do i strip a text variable like this,, from everyelse than the numbers after chance?
code_language.skript:
{_1} = "blalfdk dsjds||Chance: 13||wsj1ldsjk"


So i only have the 13 in a variable.

Thanks in advance.
 
code_language.skript:
set {_list::*} to split "blalfdk dsjds||Chance: 13||wsj1ldsjk" by "||"
loop {_list::*}:
    if "%loop-value% " contains "Chance":
        set {_1} to loop-value
        replace all "Chance: " in {_1}
 
code_language.skript:
set {_l::*} to split "blalfdk dsjds||Chance: 13||wsj1ldsjk" at "||"
set {_c::*} to {_l::2} parsed as "Chance: %number%"
# {_c::1} will contain 13
 
Last edited:
@TPGamesNL not at all because he may have more lines and more "||"s so it wouldnt work properly..
True, if he expects to have more things than the 3 he used in the example he can use this:
code_language.skript:
set {_l::*} to split "blalfdk dsjds||Chance: 13||wsj1ldsjk" at "||"
loop {_l::*}:
    set {_c::*} to loop-value parsed as "Chance: %number%"
    {_c::1} is set
    exit loop
# {_c::1} will contain 13
 
Last edited:
Yes, but he can use this too:
code_language.skript:
set {_list::*} to split "blalfdk dsjds||Chance: 13||wsj1ldsjk" by "||"
loop {_list::*}:
    if "%loop-value% " contains "Chance":
        set {_1} to loop-value
        replace all "Chance: " in {_1}
:emoji_wink::emoji_joy:
 
Last edited:
Yes, but he can use this too:
code_language.skript:
set {_list::*} to split "blalfdk dsjds||Chance: 13||wsj1ldsjk" by "||"
loop {_list::*}:
    if "%loop-value% " contains "Chance":
        set {_1} to loop-value
        replace all "Chance: " in {_1}
:emoji_wink::emoji_joy:
But then it isn't parsed as a number :emoji_grinning:
 
Yes.. I know.. He wanted to parse it as number, isnt he?

EDIT:
Your code will cause that variable be "Chance: 13"
And he said: "So i only have the 13 in a variable."
 
Last edited:
Mostly, when people want only the value 13 in a variable, they want that in number form, not in text, so they will probably want mine
 
But you cant parse string "Chance: 13" as int..
So..
1. Your code is reporting error for me ({_c} can only be set to one object, not more)
2. By my logic "set {_c} to loop-value parsed as "Chance: %number%"" will set variable to "Chance: 13"
3. And if you have variable which is string ("Chance: 13"), you cannot parse it as integer...
4. You said that people usually want variable which contains only number parsed as number.. but your code will parse it as text.. (probably, i cant test it bcs i getting error..)

code_language.skript:
set {_list::*} to split "blalfdk dsjds||Chance: 13||wsj1ldsjk" by "||"
    loop {_list::*}:
        if "%loop-value% " contains "Chance":
            set {_l} to loop-value                        # {_l} = "Chance 13";
            replace all "Chance: " in {_l} with ""        # {_l} = "13";
            set {_l} to {_l} parsed as number             # {_l} = 13;
EDIT:
Oh.. my bad "But then it isn't parsed as a number" but its still not all...
 
But you cant parse string "Chance: 13" as int..
So..
1. Your code is reporting error for me ({_c} can only be set to one object, not more)
2. By my logic "set {_c} to loop-value parsed as "Chance: %number%"" will set variable to "Chance: 13"
3. And if you have variable which is string ("Chance: 13"), you cannot parse it as integer...
4. You said that people usually want variable which contains only number parsed as number.. but your code will parse it as text.. (probably, i cant test it bcs i getting error..)

code_language.skript:
set {_list::*} to split "blalfdk dsjds||Chance: 13||wsj1ldsjk" by "||"
    loop {_list::*}:
        if "%loop-value% " contains "Chance":
            set {_l} to loop-value                        # {_l} = "Chance 13";
            replace all "Chance: " in {_l} with ""        # {_l} = "13";
            set {_l} to {_l} parsed as number             # {_l} = 13;
1. edited, try again
2.
1dxet4.jpg

3. see 2.
4. see 3.
EDIT: the expression %text% parsed as (%*type%|"<.*>") will:
1. parse the first input (%text%) as the given type (%*type%)
2. parse the first input (%text%) as the given syntax (given as "<.*>" on http://skriptlang.github.io/Skript/expressions.html#ExprParse), there is also an example for this on the skript docs: set {var::*} to message parsed as "buying %items% for %money%"
 
1. OK its working now.
2. "(probably, i cant test it bcs i getting error..)"
3. No, you are wrong
code_language.skript:
set {_l} to "test123" parsed as number
    broadcast "%{_l}%"
Code:
[17:23:33 INFO]: <none>
4. see 2.
 
1. OK its working now.
2. "(probably, i cant test it bcs i getting error..)"
3. No, you are wrong
code_language.skript:
set {_l} to "test123" parsed as number
    broadcast "%{_l}%"
Code:
[17:23:33 INFO]: <none>
4. see 2.
So at your first point you are saying you don't get any errors, but in your second point you did get errors? Did you change your skript version in the meanwhile or what have you done?
And ofcourse
code_language.skript:
set {_l} to "test123" parsed as number
    broadcast "%{_l}%"
won't work, but this will:
code_language.skript:
set {_l::*} to "test123" parsed as "test%number%"
    broadcast "%{_l::1}%"
 
No, I didnt try it.. I thought its work and i thought that it returns "Chance: 13"..
sorry.. This I have never seen before..
And if I have to be like that... ohh.. nothing.. i dont want to quarrel..
My and your code are working.
 
I know, your code is fine, but if the OP will always just have only those 3 things in there, mine is shorter and doesn't need any loops, so I thought, why not add it to the thread.
code_language.skript:
command /test <text>:
    trigger:
        set {_l::*} to arg-1 parsed as "test%number%"
        broadcast "%{_l::1}%"
        broadcast "%{_l::1}% * 2 = %{_l::1} * 2%"
Result:
3eUsje3.png
 
Yes I know too.. But as I said, I have never before seen something like that, parsing as "test%number%"... By my logic its absolutly stupid and "wtf", but it works :emoji_joy::emoji_joy:.. Peace :emoji_relieved:
 
Status
Not open for further replies.