| 07-26-2007, 05:02 PM | #1 |
JASS:
set result = ( result + SubString( udg_SL_CharSet, b, b ) )
call DisplayTextToForce( GetPlayersAll(), udg_SL_CharSet )
call DisplayTextToForce( GetPlayersAll(), "b " + I2S(b) )
call DisplayTextToForce( GetPlayersAll(), "result " + result )Ok, in-game these messages display. "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyz%$" "b 26" "result " This runs 3 times, and the script returns result, which is still null. The first message shows the string the substring comes from. The second shows which part its trying to get. From what I can see theres no error here but result is always null. Result is used nowhere else except for the return. |
| 07-26-2007, 05:06 PM | #2 |
substring(udg_SL_CharSet, b, b) returns null because if you call a substring(udg_SL_CharSet, 1, 1) the length of the substring equals 1-1 with is 0 meaning it returns a string with the length of 0 try substring(udg_SL_CharSet, b, b+1) |
| 07-26-2007, 06:12 PM | #3 |
Wouldn't that return 2 characters? Which character does it take, b, or b+1? |
| 07-26-2007, 06:12 PM | #4 |
Think of the substring min/max as going from and to the divisions between characters. That makes 0 before the first character, 1 between the first and second, etc. This helps to visualize why going from b to b gets you no characters. I think SubStringBJ behaves differently because people expect the behavior you do. Unfortunately, that's not the standard in the cs world. |
| 07-26-2007, 06:23 PM | #5 |
Think about it, if you have a string Hello you get this H E L L O 1 2 3 4 5 if you substring ( 4,4) it starts at 4 but ends at 4 before its selected, IE H E L L O -> Returns null 1 2 3|4 5 if you substring (4,5) it starts at 4 and ends at 5, IE H E L L O -> Returns L 1 2 3|4|5 |
| 07-26-2007, 06:29 PM | #6 |
Alright, thanks. So like you said, b, b+1 would just be the same thing as b, b in BJ. Is StringLength also different? Or to get the full string i'd have to use 1, StringLength+1? EDIT: JASS:set udg_SL_CharSet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyz%$" call DisplayTextToForce( GetPlayersAll(), SubString(udg_SL_CharSet, 1, StringLength(udg_SL_CharSet)) It displayed "BCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyz$" which is the string, except with 1 at the start (A) cut off, and the % is missing? Whats going on there? |
| 07-26-2007, 06:58 PM | #7 |
Try both string length +1 and string length. It depends on how string length works. And im guessing that strings actually start at 0 rather than 1 H E L L O 0|1 2 3 4| The missing % mightve just been wc3 doing something stupid as per usual... try adding a different character is exchange for % |
| 07-26-2007, 07:19 PM | #8 |
Alright so instead of b, b+1 ... b-1, b This is confusing. |
| 07-26-2007, 09:02 PM | #9 |
no, you keep b+1, and start at 0 rather than 1 for b |
| 07-26-2007, 09:57 PM | #10 | |
Quote:
Read my post again. The numbers are the indices of the divisions between the characters. Code:
___________________________________ STRING: | a | b | c | d | e | f | g | h | i | DIVIDERS: 0 1 2 3 4 5 6 7 8 9 SubString(a, b) copies characters between divider a and divider b |
