#Getting the value of a function / variable from text

1 messages · Page 1 of 1 (latest)

hearty wyvern
#

So I made some code to get the value of a variable from text, and it worked great, but now I am trying to do the same with functions, but I for some reason am failing at this, if someone knows what I can do to fix this please let me know
code:

while index of "%%notationType(" in {_lineMessage} is not -1:
  wait 1 tick
  set {_start} to index of "%%notationType(" in {_lineMessage}
  send "1. start %{_start}%"
  set {_remainingMessage} to substring of {_lineMessage} from ({_start} + 14) to (length of {_lineMessage})
  send "2. remaining - %{_remainingMessage}%"
  set {_end} to index of ")%%" in {_remainingMessage}
  send "3. relative end - %{_end}%"
  if {_end} is greater than -1:
    set {_end} to {_end} + ({_start} + 13)
    send "4. end - %{_end}%"
    set {_functionArgs} to substring of {_lineMessage} from {_start} to {_end}
    set {_argStart} to index of "(" in {_functionArgs}
    set {_argEnd} to index of ")" in {_functionArgs}
    set {_args} to substring of {_functionArgs} from ({_argStart} + 1) to ({_argEnd} - 1)
    send "5. arguments - %{_args}%"
    set {_argList::*} to split {_args} at ", "
    set {_arg2} to {_argList::2}
    send "6. second argument - %{_arg2}%"
    set {_arg2NakedStart} to index of "{" in {_arg2}
    set {_arg2NakedEnd} to index of "}" in {_arg2}
    set {_arg2Naked} to substring of {_arg2} from ({_arg2NakedStart} + 1) to ({_arg2NakedEnd} - 1)
    send "7. second argument without {} - %{_arg2Naked}%"
    set {_variableValue} to ConvertVariableToValue("%%{%{_arg2Naked}%}%%")
    send "8. variable value - %{_variableValue}%"
    send "9. how it looks - %{_arg2Naked}% + {} + %%%% = %%{%{_arg2Naked}%}%%"
    set {_finalValue} to notationType({notationType::%player's uuid%::2}, {_variableValue})
    send "10. final value - %{_finalValue}%"
    replace first "%%notationType({notationType::%player's uuid%::2}, %{_arg2}%)%%" in {_lineMessage} with "%{_finalValue}%"
#

And this is the function ConvertVariableToValue:

function ConvertVariableToValue(lineMessage: text) :: string:
    if {stopVariable} isn't true:
        while index of "%%{" in {_lineMessage} is not -1:
            set {_start} to index of "%%{" in {_lineMessage}
            set {_remainingMessage} to substring of {_lineMessage} from ({_start} + 2) to (length of {_lineMessage})
            set {_end} to index of "}%%" in {_remainingMessage}
            if {_end} is greater than -1:
                set {_end} to {_end} + ({_start} + 1)
                set {_variable} to substring of {_lineMessage} from ({_start} + 2) to ({_end} - 1)
                replace first "%%{%{_variable}%}%%" in {_lineMessage} with "%{%{_variable}%}%"
            else if {_end} isn't greater than -1:
                stop loop
    return "%{_lineMessage}%"
#

And this is the debug:

#

So as you see problem occurs with trying to put the discovered variable inside the ConvertVariableToValue function, but the variable is exacly how it should be as shown in debug number 9

neon quail
#

Could you exactly tell me more about it? like what are you checking for? or smth

#

cause im not sure, but if you are trying to find numbers/integers in a text why not replace all letters, special characters and spaces to nothing?

#

or parse the variable as number/integer

#

and if you want to show the variable just do %{Variable}%

hearty wyvern
neon quail
#

cause variables can be already a integer and are saved inside of them

hearty wyvern
#

No, for example if a player says in chat that, I replace his message with that

#

Or for what I'm using this, setting the lines of a text display

neon quail
#

Welll i cant really understand what are you trying to do

hearty wyvern
#

What I'm trying to do is replace variables said in a text display i created with their values, since by just saying %{var}% it would display %{var}%, and what I want is it to display the value of {var}

#

which i managed to do, and now I am trying to do so with functions

neon quail
#

yeahh i wont be able to help you with that sry

hearty wyvern
#

ok I think I figured out why this is happening but I still have no idea why this is happening, so look at this:

#

As you can see, {variableValue} is equal to 10000000 and so is {money::%player's uuid%}, then when I try to run them through an existing function, {money::%player's uuid%} works just fine, but for some reason, {variableValue} gives <none>, Only after setting {variableValue} to {money::%player's uuid%}, it works, even though they both were equal to 10000000??? why is this happening and how can I fix this?

tardy solar
#

Could you send the notationType function

hearty wyvern
#
    else if {_type} = "Mixed_Scientific":
        set {_savedN} to {_n}
        set {_position} to floor(log(max(abs({_n}), 1), 1000))
        while {_n} >= 10:
            set {_n} to ({_n} / 10)
            add 1 to {_totalE}
        if {_totalE} >= 6:
            return "%{_n}%e%{_totalE} ? 0%"
        else if {_totalE} < 6:
            return "%{_savedN} / (1000 ^ {_position})%%{-number_suffixes::%{_position}%} ? ""%"```
this is the part I am currently using in it
hearty wyvern