How to store a certain value from a string? (WSE)

Users who are viewing this thread

Kosolov325

Recruit
So, i'm trying to loop through an instance and then store a slot on it. the slot will be a number which had been taked from a string, but i have no idea why isn't working.

Since that string will has random numbers and i can't know the exactly digits from it i did by Regex's research.

Python:
     # ("regex", "/(\d+)/"),
    # ("regex_string", "A"),
    # {s2} = will be like this A55A44A0A501A120A0A0A0A
(try_for_range, ":inventory_slot", slot_scene_prop_inventory_begin, ":inventory_end"),
      (str_clear, s3),
      (str_regex_get_matches, ":amount", s3, s2, "str_regex"), #search for the first digits on s2 and then store inside s3
      (server_add_message_to_log, s3),
      (str_to_num, ":item_id", s3),
      (scene_prop_set_slot, ":instance_id", ":inventory_slot", ":item_id"),
      (str_clear, s0),
      (str_store_regex_replace, s0, s2, "str_regex", "str_regex_string"), #search for the digit that had found peviously and then store the letter A on the place, so the next loop will take the next number from the string {s2}
      (str_clear, s2),
      (str_store_string, s2, s0),
      (server_add_message_to_log, s2),
      (val_sub, ":amount", ":amount"),
    (try_end),

hopefully someone can help me. my thanks.
 
Last edited:
Solution
It looks a little bit confusing :smile: I'll try to convert it to a readable format.

Loop through inventory slots. -> ok

find values by regex in s2 and store it to the registers starting from the s3. -> ok. You can use optional paramater [max] as 1.

log first value found -> ok

Convert the value to int and set some slot -> ok

Try to replace first value found with "A" -> This replaces not the first value, but all of the same values. "A1A2A1A2A1A2" becomes "AAA2AAA2AAA2".

log the new string -> ok

substract amount from amount -> ?
It looks a little bit confusing :smile: I'll try to convert it to a readable format.

Loop through inventory slots. -> ok

find values by regex in s2 and store it to the registers starting from the s3. -> ok. You can use optional paramater [max] as 1.

log first value found -> ok

Convert the value to int and set some slot -> ok

Try to replace first value found with "A" -> This replaces not the first value, but all of the same values. "A1A2A1A2A1A2" becomes "AAA2AAA2AAA2".

log the new string -> ok

substract amount from amount -> ?
 
Upvote 0
Solution
It looks a little bit confusing :smile: I'll try to convert it to a readable format.

Loop through inventory slots. -> ok

find values by regex in s2 and store it to the registers starting from the s3. -> ok. You can use optional paramater [max] as 1.

log first value found -> ok

Convert the value to int and set some slot -> ok

Try to replace first value found with "A" -> This replaces not the first value, but all of the same values. "A1A2A1A2A1A2" becomes "AAA2AAA2AAA2".

log the new string -> ok

substract amount from amount -> ?
But.. the regex will only take the first capture group not all of them.. (i guess), because there isn't /g flag on it, isn't it?
Ps: The amount - amount is just to prevent warnings while compiling
 
Last edited:
Upvote 0
But.. the regex will only take the first capture group not all of them.. (i guess), because there isn't /g flag on it, isn't it?
I tried "/(\d+)/" it returns no match and "(\d+)" returns every matches. I think regex has some issues. What does the '/' characters do exactly?
 
Upvote 0
Sadly, i think this operator has /g by default on It, so, i can't be able to store only one capture group, but i'll work with this
str_regex_get_matches = 4242 #(str_regex_get_matches, <destination>, <string_register>, <string_1>, <string_regex>, [<max>]), #Stores all matches of <string_regex> that occur in <string_1> into a range of string registers, starting from <string_register>, storing [[<max>]] substrings at most (default = unlimited). Stores the amount of matches into <destination>
str_store_regex_replace = 4243 #(str_store_regex_replace, <string_register>, <string_1>, <string_regex>, <string_2>), #Stores <string_1> into <string_register>, replacing occurrences of <string_regex> with <string_2>
It's stated on the documentation.
You can read the string char by char. There are lots operations for that kind of stuff.
 
Upvote 0
Back
Top Bottom