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.
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.
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.
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. :)
exactly, and its not only encrypting well but also it makes it very easy to work with banks because it automatically combines all the integers to a string and so on :D
first, i dont spend any time on ecryption because starcode does it for me :)
second, i dont believe that anyone will be able to hack the codes since they would have to hack hash + password whats nearly impossible for normal people. the much bigger problem is that it would be possible to create backups of your characters AND exchange your character with other players since there is no possibility to compare player names or anything to ensure the bank is only loadable for a specific player
third, banks are perfectly usable for rpgs because they removed the size limit (hopefully), and in a few weeks ull see whats possible with banks (if there dont appear new strange errors in development process xD)
but why it works with one 100*200 array but not with 4 100*50 arrays? and why the problem only occures if the variables are in the record?
i have really no idea... oO
PS: just tested abit further... one 100*1000 variable in the record doesnt make any problems. and about 20 100*50 arrays out of the record dont cause the bug, either.
at first, thanks for this great library. im developing my rpg and it works really well and its easy to use.
but i encoutered a very strange bug and had to search 2 hours until i had found the "reason" for it (which makes no real sense).
if you have a record on your map and in this record some variables (2d arrays), then at some point starcode will stop working. it will say "devide by zero" when it should compress/encrypt/... code.
i have created a new map, imported the starcode library, created some test trigger and implemented a record to show you the bug.
this are the characteristics of the bug:
- if you deactivate or remove the record, starcode will work again
- if you remove one of the 4 array variables in the record, starcode will work again
- if you move all 4 variables out of the record, starcode will work again
- if you replace the 4 100*50 arrays with one 100*250 array (which should be equal), starcode will work again
- it does not have any effect to rename the variables or the record
- when you start a new code with starcode and show a text message with the current code in it, it will not show "0" like its expected after "start new code", it will just show nothing
- additionally, the code output after storing the intergers is totally different when the record is in the map, even if you save exactly the same values
- compress code, encrypt code and hash code will throw a trigger error with message "devide by zero". havent tested the other functions yet, but getcode, startnewcode and store integer still works
try it out yourself and you will see it. i dont know if it helps you to find the mistake or if its some strange engine bug, but its very bad for my rpg because for my item/quest/spell systems i need a lot of multidimensional arrays in records and i always have to reduce the array size to avoid the "devide by zero" bug of starcode.
its very important for me that you look over my testmap and tell me what causes this problem.
do i get it right that tis is in fact nearly the same as the old systems used in wc3 to generate savecodes? (e.g. with 64 chars)
its very useful and i used smth similar for my rpg, the problem is however, that most of the space needed in my savecodes were the quest states, witch are saved by an integer with values from 0 to 3. so to compress the quest info you whould have to add 5 quests or so together to one integer value and then convert it to the new system.
so my suggestion: maybe you could implement a function that allows you to combine 5 or 6 boolean values or integer values with only one digit (0-9) to one big number witch is then converted to the XX char sys. cause booleans and integers with only one digit might be used very often, too.
for example 6 quests with different states would be:
023001 and this integer would be converted later.
correct me if i get smth wrong^^
i think this would make sense because the system is only useful for big numbers, as less digits as less effective is the "compression".
@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.
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.
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.
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.
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. :)
maybe you should update to 1.4? :)
i think he fixed some bugs since 1.0 and you havent used it much till now, so its a quite good idea to replace it with the newer library
@s3rius: Go
exactly, and its not only encrypting well but also it makes it very easy to work with banks because it automatically combines all the integers to a string and so on :D
are you guys serious?
first, i dont spend any time on ecryption because starcode does it for me :)
second, i dont believe that anyone will be able to hack the codes since they would have to hack hash + password whats nearly impossible for normal people. the much bigger problem is that it would be possible to create backups of your characters AND exchange your character with other players since there is no possibility to compare player names or anything to ensure the bank is only loadable for a specific player
third, banks are perfectly usable for rpgs because they removed the size limit (hopefully), and in a few weeks ull see whats possible with banks (if there dont appear new strange errors in development process xD)
greetings
mille25
so it really seems to be a blizzard bug... shit.
hm ok... then i have to move my arrays out of the records... thats very bad because how should i keep overview then? -.-
@s3rius: Go
but why it works with one 100*200 array but not with 4 100*50 arrays? and why the problem only occures if the variables are in the record?
i have really no idea... oO
PS: just tested abit further... one 100*1000 variable in the record doesnt make any problems. and about 20 100*50 arrays out of the record dont cause the bug, either.
hello s3rius
at first, thanks for this great library. im developing my rpg and it works really well and its easy to use.
but i encoutered a very strange bug and had to search 2 hours until i had found the "reason" for it (which makes no real sense).
if you have a record on your map and in this record some variables (2d arrays), then at some point starcode will stop working. it will say "devide by zero" when it should compress/encrypt/... code.
i have created a new map, imported the starcode library, created some test trigger and implemented a record to show you the bug.
this are the characteristics of the bug:
- if you deactivate or remove the record, starcode will work again
- if you remove one of the 4 array variables in the record, starcode will work again
- if you move all 4 variables out of the record, starcode will work again
- if you replace the 4 100*50 arrays with one 100*250 array (which should be equal), starcode will work again
- it does not have any effect to rename the variables or the record
- when you start a new code with starcode and show a text message with the current code in it, it will not show "0" like its expected after "start new code", it will just show nothing
- additionally, the code output after storing the intergers is totally different when the record is in the map, even if you save exactly the same values
- compress code, encrypt code and hash code will throw a trigger error with message "devide by zero". havent tested the other functions yet, but getcode, startnewcode and store integer still works
try it out yourself and you will see it. i dont know if it helps you to find the mistake or if its some strange engine bug, but its very bad for my rpg because for my item/quest/spell systems i need a lot of multidimensional arrays in records and i always have to reduce the array size to avoid the "devide by zero" bug of starcode.
its very important for me that you look over my testmap and tell me what causes this problem.
greez
mille25
@s3rius: Go
ah ok so your system generates the raw code first and then it splits it up into blogs whitch get converted?
do i get it right that tis is in fact nearly the same as the old systems used in wc3 to generate savecodes? (e.g. with 64 chars)
its very useful and i used smth similar for my rpg, the problem is however, that most of the space needed in my savecodes were the quest states, witch are saved by an integer with values from 0 to 3. so to compress the quest info you whould have to add 5 quests or so together to one integer value and then convert it to the new system.
so my suggestion: maybe you could implement a function that allows you to combine 5 or 6 boolean values or integer values with only one digit (0-9) to one big number witch is then converted to the XX char sys. cause booleans and integers with only one digit might be used very often, too.
for example 6 quests with different states would be:
023001 and this integer would be converted later.
correct me if i get smth wrong^^
i think this would make sense because the system is only useful for big numbers, as less digits as less effective is the "compression".