• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Parsing string, facing problem with string length limit

Status
Not open for further replies.
Level 3
Joined
Jan 29, 2021
Messages
34
Hello guys. Recently I've found out that strings in jass are limited to ~1k symbols in length and because of this I get some strange bugs

Here what I'm doing:
I have string (actually it is first array's element, doesnt really matter)

Code:
string commands = Commands_Stack[0]

It works like "stack" simulation, don't bother much if you dont understand
Then this "stack" is filled with commands, one by one, each command ends with some separator, for example "&", each command is concatenated to previous string.

Format of command is

Code:
"-add_DIRECTION_SLOT_TIME1_TIME2" (doesn't really matter)

The important thing is that it is guaranteed that command is added to "stack" only if it is in the right format

So, after adding few commands to our "stack" (which is just simple string) it looks like

Code:
"-add_right_5_1.23_3.45&-add_right_4_1.65_7.45&-add_down_5_1.23_3.45&-add_up_5_1.23_3.45&-add_right_5_1.23_3.45&" ... and so on

Now, I implemented function that allows me to remove last command from this "stack". Last means the rightest one in the string.

The algorithm is pretty simple:
I find the last entrance of symbol "-" (each command start exactly with "-add" and again you can consider it is strictly guaranteed)
and then reset string(our stack) to its Substring without symbols after last symbol "-" including it

Now, when our string is pretty short - it works fine.
When it becomes long - it doesnt work
Interesting thing is that as far as Im concerned Im able to add as many commands to the string as I want to, I can also see current string even if it is long and all is fine
But function that removes last command from the string stops working

What is the issue?
 
Level 3
Joined
Jan 29, 2021
Messages
34
The problem I see is that I'm trying to get high string index, like > 1000 and it is not supported(I'm not sure, can anyone help or bring documentation about it?) even considering that string is able to store more then 1000 symbols through concatenation.
 
Level 3
Joined
Jan 29, 2021
Messages
34
The problem was solved changing to dynamic "stack"

Now each adding command works like:
before each adding I check that current comands length + newCommand length < lets say 800(could be even lower)
If so - just simply concatenate new command to first index of our string array(Commands_Stack[0])
If not - concatenate new command to next index of our string array(Commands_Stack[1])
 
Level 3
Joined
Jan 29, 2021
Messages
34
But again, would be nice if someone explains how it works when you have string of lets say 2k symbols and then you somehow work with it calling its StringLength
 
Status
Not open for further replies.
Top