| 07-30-2007, 04:31 AM | #1 |
Out of nowhere, a problem with the code started to happen where "StringLength(xs) < 5" seemed to be returning false when its length was 2. I added a display message action above it, to display the string length of it, and now i'm getting 2 errors that don't seem to make any sense for that line. ( see // PROBLEM LINE BELOW in the code) The errors... Code:
Bad types for binary operator Cannot convert real to string The line JASS:
call DisplayTimedTextToForce(GetPlayersAll() , 900.00 , "string " + StringLength(xs) )So it seems like the variable xs is just dying mid-script. I don't know if thats possible. The only change I made before this problem started happening was with the global variables udg_SL_Powers and udg_SL_Max. Full code... (NOTE: the stuff commented with //q is an additional feature which I temporary removed to fix the code.) JASS:function SaveCode takes integer c returns string local integer xi = 0 local integer xi2 = 0 local integer xi3 = 0 local integer a = 1 local integer a2 = udg_Code_Saves[c] local integer b = 0 local integer b2 = 0 local string result = null local string xs = null local string xs2 = null if ( a2 <= 0 ) then // No values saved for this code. Duh? set result = "nosaves" return result endif loop // Lets make it multi-demensional. set xi3 = ( a + ( udg_SL_MaxSaves * (c - 1))) set xi = udg_Save_Val[xi3] set xi2 = udg_Save_Max[xi3] // Start BooStuffer //qif ( xi2 <= ( udg_SL_Powers[b] - xi2 ) ) then //q if ( xs != null ) then //q if ( SubString( xs, 0, 1 ) == "1" ) then //q set xi = ( xi + xi2 ) //q endif //q set xs = SubString( xs, 1, StringLength(xs) ) //q else //q // Create opt error. xs = null. //q endif //qendif // End BooStuffer set b = udg_Save_Space[xi3] loop if ( xi >= udg_SL_Powers[b] ) then set xi = ( xi - udg_SL_Powers[b] ) set xs = ( "1" + xs ) else set xs = ( "0" + xs ) endif set b = ( b - 1 ) exitwhen ( b == 0 ) endloop exitwhen a == a2 set a = ( a + 1 ) endloop set a = 1 set b = 1 set xi3 = 0 loop // THE PROBLEM LINE IS BELOW call DisplayTimedTextToForce( GetPlayersAll(), 900.00, "string " + StringLength(xs)) // THE PROBLEM LINE IS ABOVE if ( StringLength(xs) < 5 ) then set xs2 = xs set xs = null loop if ( StringLength(xs2) != 5 ) then set xs2 = ( xs2 + "0" ) set xi3 = xi3 + 1 else exitwhen true endif endloop else set xs2 = SubString( xs, a-1, (a+4)) set xs = SubString( xs, a+4, StringLength(xs) ) endif loop if ( xs2 == SubString( udg_SL_BinSet, b-1, (b+4)) ) then // Start BooStuffer //q If a value can be above 64, and is above 64, then extra is 1, else 0. Same goes for 32. //q Yes it makes sense, stop forgetting that. //qif (b <= (udg_SL_Chars - udg_SL_Base)) then //q if ( xs != null ) then //q if SubString( xs, 0, 1) == "1" then //q set b = (b + udg_SL_Base) //q endif //q set xs = SubString( xs, 1, StringLength(xs)) //q if (b <= (udg_SL_Chars - udg_SL_Base2)) then //q if ( xs != null ) then //q if SubString( xs, 0, 1) == "1" then //q set b = (b + udg_SL_Base2) //q endif //q set xs = SubString( xs, 1, StringLength(xs)) //q else //q // Create Opt Error. xs was = null. //q endif //q endif //q else //q // Create Opt Error. xs was = null. //q endif //qendif // End BooStuffer set result = ( result + SubString( udg_SL_CharSet, b-1, b ) ) exitwhen true endif set b = ( b + 1 ) endloop exitwhen ( xs == null ) set a = ( a + 5 ) set b = 1 endloop if ( xi3 > 0 ) then // Create Opt. Error. Extra space went unused. endif return result endfunction |
| 07-30-2007, 04:45 AM | #2 |
It's because StringLength() returns in integer, not a string. Thus, it should be I2S(StringLength(xs))
Additionally, I don't think you should initialize your strings as null. Try replacing all nulls relating to your strings with "" instead. |
| 07-30-2007, 04:55 AM | #3 |
Wow thats a stupid mistake... I must be more tired then I thought I was. Thanks. As for the null part, should it be done like that only at init? And will it still return null when I check it? |
| 07-30-2007, 05:45 AM | #4 |
It will return "", I believe, which is the GUI equivalent of "Empty String" if I'm correct. At any rate, don't use null strings. |
| 07-30-2007, 06:02 AM | #5 |
null strings return from cache, empty ("") return from all other functions. |
| 07-30-2007, 10:00 PM | #6 |
According to the errors I just got from making that change, global variable arrays are null by default. |
| 07-31-2007, 12:48 AM | #7 |
Yes, they are unless you initialize them as something in the Variable Editor. |
