Aye, but using strings is just as good as int arrays. It's slower but it wouldn't change the end result, would it? And strings were convenient because the thing was made with banks in mind. You'd immediately have a usable string output. I thought that was pretty neat :P
I would've made things differently if I had all the neat things of vJass at my disposal.
I made this a year ago when I was still young and wild ~ and I don't think I'll rewrite it completely, as the need for it is much smaller by now.
Still, I appreciate the criticism and the links. I haven't looked at the Wc3 scene for a long time now and I love it that there's still so much stuff being made after so many years.
Hi, I'm currently using Starcode to save integer variables in NOTD. What if I want to store string variables? I'm using that to store the player's SC2 ID (via Get Player Handle). Does Starcode support saving string variables? Otherwise, what can I do. Thanks.
Hi, I'm currently using Starcode to save integer variables in NOTD. What if I want to store string variables? I'm using that to store the player's SC2 ID (via Get Player Handle). Does Starcode support saving string variables? Otherwise, what can I do. Thanks.
You can store strings normally without starcode. If you want to "hide" the sc2 id in some way so that it's more difficult to edit, you can use the id as part of the encryption key or as a hash for data verification purposes.
For everyone who is using this library and getting errors with 1.5, here is a quick fix for you:
- The error is caused by a change Blizzard did to the "StringToInt" function
- If the String is empty or cant be converted to an int, it will still return 0 but display a trigger error
- Starcode still works, but spams errors under certain circumstances
To fix this issue, insert this two functions into the source file of starcode:
After doing this, make sure to replace all the "StringToInt" that cause errors in your map by "SaveStringToInt". In my case it was just one line:
Note: This function will make StringToInt alot slower, so make sure just to use it if its really needed.
Edit: Great, with the fix I get "execution too long" error in SCU now. >_>
If anyone has ideas how to optimize this function or a totally different approach, that would be very appreceated. :)
Did they ninja-fix the StringToInt problem? I was trying to find a better algorithm for your post, but I can't seem to replicate the problem. I faced it too before, but now it's not spitting errors (I'm not complaining).
Note: cout is just a debugger function which prints to screen. i2s is a shortcut for IntToString.
The output I got when I run this was: 0, 0, 1, 1, 0
Edit:
The StringToInt function appears to behave in a manner that it will check for the first non-whitespace character in the string. If it's an integer, it will still cast, else it will return 0. Here's what I came up with to check this condition. Although it won't really matter if they fixed it
I did a quite similar test to yours before, and got the same output, but with errors.
StringToInt still seems to work like in 1.4.4 (meaning it defaults to 0), however it now displays an error message if the string is empty or contains non-decimal characters. (Thats at least how it behaved in my tests)
This isnt really a problem, however the errors really annoy me while testing the map, since they get spammed at me constantly and I cant see the important errors. Thats why I wanted to fix the problem somehow.
EDIT:
Here are my test results:
Quote:
00:00:00.00 Scri: Trigger Error in 'gt_MeleeInitialization_Func': Could not get 'int' from parameter in '' (value: ) Near line 49 in gt_MeleeInitialization_Func() in MapScript.galaxy
00:00:00.00 converting "123" to int...
00:00:00.00 result: 123
00:00:00.00 converting "-1" to int...
00:00:00.00 result: -1
00:00:00.00 converting "" to int...
00:00:00.00 Scri: Trigger Error in 'gt_MeleeInitialization_Func': Could not get 'int' from parameter in '' (value: ) Near line 53 in gt_MeleeInitialization_Func() in MapScript.galaxy
00:00:00.00 Scri: Trigger Error in 'gt_MeleeInitialization_Func': Could not get 'int' from parameter in '' (value: ) Near line 57 in gt_MeleeInitialization_Func() in MapScript.galaxy
00:00:00.00 Scri: Trigger Error in 'gt_MeleeInitialization_Func': Could not get 'int' from parameter in '' (value: ) Near line 61 in gt_MeleeInitialization_Func() in MapScript.galaxy
00:00:00.00 Scri: Trigger Error in 'gt_MeleeInitialization_Func': Could not get 'int' from parameter in '' (value: ) Near line 65 in gt_MeleeInitialization_Func() in MapScript.galaxy
00:00:00.00 result: 0
00:00:00.00 converting "abc" to int...
00:00:00.00 result: 0
00:00:00.00 converting "4a2" to int...
00:00:00.00 result: 4
00:00:00.00 converting "-a45" to int...
00:00:00.00 result: 0
00:00:00.00 converting "-55af" to int...
00:00:00.00 result: -55
As you can see, 5 errors total for 4 Strings containing non-decimal characters and one empty string.
It seems there can also be errors even though it doesnt default to 0.
That said, it seems like your much shorter function cant replace my slow algorythm, since there is still an error even though the first character is a decimal number.
Could I take a look at your test map please? I don't understand why I'm not getting the error, although you still get it. I'd like to do a comparison between our methods
Could I take a look at your test map please? I don't understand why I'm not getting the error, although you still get it. I'd like to do a comparison between our methods
Well, there isnt much to show off.
Its just a string variable getting converted into an int variable.
I dont even have the map anymore, but it was like this (pseudocode):
strings;inti;s="45";debug("converting "+s+" into int");i=StringToInt(s);debug("Result: "+IntToString(i));...
Really nothing special going on.
The only difference i see towards your method is, that I use a String variable instead of entering the String directly. However, theoretically that shouldnt make any difference and in reality you always use variables anyways.
No error, but When I tried another script I was working on, it spammed my debugger with the (value: ) could not be assigned nonsense. Trying to figure out here what exactly the condition is for the error to appear.
Edit:
I found the condition. The debugger will only spam if the StringToInt function is called from a trigger thread. Doesn't matter how many stacks deep. If you're running from the main thread (InitMain), nothing will happen.
Edit #2:
Here's the solution I've come up with, partially inspired by your solution above :)
conststringnum="0123456789";//Checks if the the first non-space character is a numberboolStrIsNum(strings,boolisFixed){stringx=s;intlen=StringLength(num);inti=1;while(i<=len){x=StringReplaceWord(x,StringSub(num,i,i),"",c_stringReplaceAll,false);i+=1;}//Check if floating pointif(isFixed){x=StringReplaceWord(x,".","",1,false);}//If string length 0 after replacing all numbers, it's a numberreturnStringLength(x)==0;}intStr2Int(strings){if(StrIsNum(s,false)){returnStringToInt(s);}return0;}fixedStr2Fix(strings){if(StrIsNum(s,true)){returnStringToFixed(s);}return0;}
I'm not sure how it'll perform with super long strings though.
The performance of your algorythm depends on the speed of the replace word function. Im assuming its pretty slow since it might have to loop through the entire string to replace all characters, and also needs to build a new string to return.
In addition, I think your function has problems with negative numbers.
For floating point numbers you should avoid replacing all "." since this would allow stuff like "12.34.25", instead id suggest just to replace the first .
However its an interresting idea, since replace word is a native function and therefore might beform better. I dont know how exactly the native functions are implemented.
For floating point numbers you should avoid replacing all "." since this would allow stuff like "12.34.25", instead id suggest just to replace the first .
I noticed this last night when I was trying to sleep lol. Fixed it above. As for negative numbers (which I forgot), with some modifications, I believe it can be built to handle negative numbers (Check if the first character is a '-') Will give it a try when I'm able.
Just a quick question about the algorithm... I am using the Starcode to encrypt Games played and Wins in my map. At most, each of these values can increase by 1 each game. The way I have it set up is that I take the unhash (security level 2), decrypt, and then decompress both values (individual values, each with a set max value of 2000) and then I convert the string to an int. I then use that int as a variable and when saving the bank I do the reverse... My problem is this: The games played and wins seem to jump much more than they should. For example, I had 4 wins, won a game and then the next game I played I had 15 wins. It worked for the first 4 and then broke, and for some players this isn't happening at all. I don't think I have a problem with the triggers themselves, but before I spend hours staring at them I was just curious if it could be a problem with the encryption.
Lol, thanks for the feedback. I'll weed those out when I'm free :) (Probably on the weekend)
However, I believe ".123" is a valid float number. The majority of programming languages recognize it as so (Not sure about Galaxy though). Does it throw errors with StringToFixed?
Note to self "-.", ".-", " -1" may cause complications as well. Have to be very careful with the replacement of blank spaces as "1 0" actually throws an error. Much further testing required. @_@
Im not 100% sure on this, but i think its important in which order you do the operations.
Try this:
1. Store your integer
2. Compress
3. Encrypt
4. Hash
I'm pretty sure this is what I'm doing, and it should be the proper code because my problem isn't happening for everyone, at least I don't think.
I have attached the code of what my "Games Won" section looks like. Is this right? It is repeating this exact code for each player that gets a win, is this a problem?
Here's the updated function :) It should now handle all negative numbers and other anomalies correctly
conststringnum="0123456789";//Strips the blank space paddings from either end of a stringstringStrip(strings){intbegin=1;intend=StringLength(s);//Return if no blank spacesif(StringFind(s," ",false)==-1){returns;}//Find startwhile(StringSub(s,begin,begin)==" "){begin+=1;}//Find endwhile(StringSub(s,end,end)==" "){end-=1;}returnStringSub(s,begin,end);}//Checks if the the first non-space character is a numberboolStrIsNum(strings,boolisFixed){inti=1;intlen=StringLength(num);intpos;stringx=Strip(s);stringsub;//Check if isNaNif(x==""||x=="."||x=="-."||x==".-"){returnfalse;}//Check if negativepos=StringFind(x,"-",false);if(pos==1){x=StringReplaceWord(x,"-","",1,false);}elseif(pos!=-1){returnfalse;}//Check if intwhile(i<=len){x=StringReplaceWord(x,StringSub(num,i,i),"",c_stringReplaceAll,false);i+=1;}//Check if floating pointif(isFixed){x=StringReplaceWord(x,".","",1,false);}//If string length 0 after replacing all numbers, it's a numberreturnStringLength(x)==0;}intStr2Int(strings){if(StrIsNum(s,false)){returnStringToInt(s);}return0;}fixedStr2Fix(strings){if(StrIsNum(s,true)){returnStringToFixed(s);}return0;}
Attached my test file as well. Feel free to critique if you feel the function could be further optimized (Esp the strip)
@nestharus: Go
Aye, but using strings is just as good as int arrays. It's slower but it wouldn't change the end result, would it? And strings were convenient because the thing was made with banks in mind. You'd immediately have a usable string output. I thought that was pretty neat :P
I would've made things differently if I had all the neat things of vJass at my disposal.
I made this a year ago when I was still young and wild ~ and I don't think I'll rewrite it completely, as the need for it is much smaller by now.
Still, I appreciate the criticism and the links. I haven't looked at the Wc3 scene for a long time now and I love it that there's still so much stuff being made after so many years.
Hi, I'm currently using Starcode to save integer variables in NOTD. What if I want to store string variables? I'm using that to store the player's SC2 ID (via Get Player Handle). Does Starcode support saving string variables? Otherwise, what can I do. Thanks.
You can store strings normally without starcode. If you want to "hide" the sc2 id in some way so that it's more difficult to edit, you can use the id as part of the encryption key or as a hash for data verification purposes.
Thank you for spending your time making this.
For everyone who is using this library and getting errors with 1.5, here is a quick fix for you:
- The error is caused by a change Blizzard did to the "StringToInt" function
- If the String is empty or cant be converted to an int, it will still return 0 but display a trigger error
- Starcode still works, but spams errors under certain circumstances
To fix this issue, insert this two functions into the source file of starcode:
After doing this, make sure to replace all the "StringToInt" that cause errors in your map by "SaveStringToInt". In my case it was just one line:
Note: This function will make StringToInt alot slower, so make sure just to use it if its really needed.
Edit: Great, with the fix I get "execution too long" error in SCU now. >_>
If anyone has ideas how to optimize this function or a totally different approach, that would be very appreceated. :)
Did they ninja-fix the StringToInt problem? I was trying to find a better algorithm for your post, but I can't seem to replicate the problem. I faced it too before, but now it's not spitting errors (I'm not complaining).
Here's my script:
Note: cout is just a debugger function which prints to screen. i2s is a shortcut for IntToString.
The output I got when I run this was: 0, 0, 1, 1, 0
Edit:
The StringToInt function appears to behave in a manner that it will check for the first non-whitespace character in the string. If it's an integer, it will still cast, else it will return 0. Here's what I came up with to check this condition. Although it won't really matter if they fixed it
I did a quite similar test to yours before, and got the same output, but with errors.
StringToInt still seems to work like in 1.4.4 (meaning it defaults to 0), however it now displays an error message if the string is empty or contains non-decimal characters. (Thats at least how it behaved in my tests)
This isnt really a problem, however the errors really annoy me while testing the map, since they get spammed at me constantly and I cant see the important errors. Thats why I wanted to fix the problem somehow.
EDIT:
Here are my test results:
As you can see, 5 errors total for 4 Strings containing non-decimal characters and one empty string.
It seems there can also be errors even though it doesnt default to 0.
That said, it seems like your much shorter function cant replace my slow algorythm, since there is still an error even though the first character is a decimal number.
Could I take a look at your test map please? I don't understand why I'm not getting the error, although you still get it. I'd like to do a comparison between our methods
Well, there isnt much to show off.
Its just a string variable getting converted into an int variable.
I dont even have the map anymore, but it was like this (pseudocode):
Really nothing special going on.
The only difference i see towards your method is, that I use a String variable instead of entering the String directly. However, theoretically that shouldnt make any difference and in reality you always use variables anyways.
@Mille25: Go
Hm.. I tried your script, and here's my output
No error, but When I tried another script I was working on, it spammed my debugger with the (value: ) could not be assigned nonsense. Trying to figure out here what exactly the condition is for the error to appear.
Edit: I found the condition. The debugger will only spam if the StringToInt function is called from a trigger thread. Doesn't matter how many stacks deep. If you're running from the main thread (InitMain), nothing will happen.
Edit #2:
Here's the solution I've come up with, partially inspired by your solution above :)
I'm not sure how it'll perform with super long strings though.
Thanks for your help so far!
The performance of your algorythm depends on the speed of the replace word function. Im assuming its pretty slow since it might have to loop through the entire string to replace all characters, and also needs to build a new string to return.
In addition, I think your function has problems with negative numbers.
For floating point numbers you should avoid replacing all "." since this would allow stuff like "12.34.25", instead id suggest just to replace the first .
However its an interresting idea, since replace word is a native function and therefore might beform better. I dont know how exactly the native functions are implemented.
You're welcome
I suppose I could run some time tests for this one to evaluate it's performance. Do you think a 1000 char string would suffice?
I noticed this last night when I was trying to sleep lol. Fixed it above. As for negative numbers (which I forgot), with some modifications, I believe it can be built to handle negative numbers (Check if the first character is a '-') Will give it a try when I'm able.
Just a quick question about the algorithm... I am using the Starcode to encrypt Games played and Wins in my map. At most, each of these values can increase by 1 each game. The way I have it set up is that I take the unhash (security level 2), decrypt, and then decompress both values (individual values, each with a set max value of 2000) and then I convert the string to an int. I then use that int as a variable and when saving the bank I do the reverse... My problem is this: The games played and wins seem to jump much more than they should. For example, I had 4 wins, won a game and then the next game I played I had 15 wins. It worked for the first 4 and then broke, and for some players this isn't happening at all. I don't think I have a problem with the triggers themselves, but before I spend hours staring at them I was just curious if it could be a problem with the encryption.
@FuzzYD: Go
It still accepts ".123" or "." :D
It also accepts "".
@DaBernMon: Go
Im not 100% sure on this, but i think its important in which order you do the operations.
Try this:
1. Store your integer
2. Compress
3. Encrypt
4. Hash
And on load do this in reverse. If this doesnt work, try to swap compress and encrypt. If it still doesnt work its your code.
@Mille25: Go
Lol, thanks for the feedback. I'll weed those out when I'm free :) (Probably on the weekend)
However, I believe ".123" is a valid float number. The majority of programming languages recognize it as so (Not sure about Galaxy though). Does it throw errors with StringToFixed?
Note to self "-.", ".-", " -1" may cause complications as well. Have to be very careful with the replacement of blank spaces as "1 0" actually throws an error. Much further testing required. @_@
I'm pretty sure this is what I'm doing, and it should be the proper code because my problem isn't happening for everyone, at least I don't think. I have attached the code of what my "Games Won" section looks like. Is this right? It is repeating this exact code for each player that gets a win, is this a problem?
@Mille25: Go
Here's the updated function :) It should now handle all negative numbers and other anomalies correctly
Attached my test file as well. Feel free to critique if you feel the function could be further optimized (Esp the strip)
Is there an update to this? I get errors when I try to use -save or -load from the front page download link. -example still works, though
Heya,
I've gotten years of use out of this library and I love it.
Still, 2.1 introduced an error when trying to publish. It looks small, but I don't want to break anything by attempting to fix it myself.
http://i.imgur.com/fJIfnoo.png
Any suggestions?
Better screenshots;
This is the problematic trigger;
And this is the error report;