| 04-22-2007, 05:20 PM | #1 |
If this has already been covered, ignore this post. JASS:function String2Int takes string s returns integer return s return 0 endfunction alternatively: JASS:function Int2String takes integer i returns string return i return "" endfunction will return the string at the certain "string slot". These include the map name which can be compared to detect unofficial mods. These can also be used to attach integers to strings by using arrays. ie: JASS:globals integer array somearray endglobals function String2Int takes string s returns integer return s return 0 endfunction function storeStringInt takes string s, integer i returns nothing set somearray[String2Int(s)]=i endfunction function getStringInt takes string s, returns integer return somearray[String2Int(s)] endfunction of course you would have to worry about string leaks from outside sources (player messages included) but if the strings are stored at map init, chances are it shouldn't be a problem. It could be a faster alternative to Game-Cache, except it would require many integer arrays in case of string over-flow and that Structs are more efficient (but don't offer the spontaneous values that game-cache provided; which sometimes is a bad thing but it all depends on the map). |
| 04-22-2007, 05:55 PM | #2 |
There's also the fact that we don't know if the string table is constant (or to the best of my knowledge we don't know that) and that is gets 'compressed' if it uses too much memory. Which means this wouldn't be stable. But yeah this has already been mentioned. |
| 04-22-2007, 06:06 PM | #3 |
I thought the same thing about compression since I did a test that generated strings and the RAM usage started to decrease after a period of time (not as fast as it was increasing, but noticeable compared to its normal increase). I also did another test and got to ~ 40,000 strings at which point my fps was < 1 but it seemed the strings were all still intact. Reason I brought this up is that I was looking for an alternative method to my name search for the PAS to make it linear without the game-cache, but I don't think I'll use this. |
| 04-22-2007, 06:12 PM | #4 |
You could try hashing. Don't know how efficient it would be in JASS, but hey. |
| 04-22-2007, 08:50 PM | #5 |
string hashing would be terribly bad in Jass. Seriously people, gamecache is very efficient at what it does, being a 2 ways hash table that takes 2 strings, if you want to relate stuff to strings it is the best way. |
| 04-23-2007, 07:43 AM | #6 |
Ammorth - this is a old story... |
| 05-02-2007, 05:05 AM | #7 |
I'd like to revive this thread because I'm thinking this will be a viable method for a new system (or mini-system) of mine. It's a multi-board sparser that will sparse a line of text (including color codes and the like) onto a multiboard so it will fit. I need to store the width of each character to the letter, which I have currently been using game-cache for, but as I've stated earlier, I would like to get away from it. Now, I did another test and got to 60,000 strings, where my memory usage was over 100Mbs and still had the strings intact. I am now seriously considering to change my system over to the string return and I was wondering if I did do that, would it have any chance of being approved? It doesn't seem to pose any problems yet, and I think it's rather feasible to store static values with. Opinions please. @Vexorian, I know Game-cache is great for everything, I just don't think it's the answer for everything. Since the following systems I am making are for a single-player RPG, I would like to keep it game-cache free so I can use it to save data between maps without being forced to save dynamic information. It's a personal opinions and I don't think I will be swayed easily. |
| 05-02-2007, 06:57 AM | #8 | |
Quote:
Gamecache isn't great for everything, but gamecache is perfect for this kind of string stuff. |
| 05-02-2007, 03:36 PM | #9 |
String tables are, I believe, reset on saving/loading. |
| 05-02-2007, 05:41 PM | #10 | |
Quote:
|
| 05-02-2007, 11:28 PM | #11 | |
Quote:
Btw, the function I use to test is as follows: JASS:globals integer i = 0 integer test integer increment = 2 endglobals function StoI takes string s returns integer return s return 0 endfunction function ItoS takes integer i returns string return i return "" endfunction function test_loop takes nothing returns nothing local integer end = i+increment loop exitwhen i > end call BJDebugMsg(I2S(i)) set i = i+1 endloop call BJDebugMsg(ItoS(test)) endfunction function Test takes nothing returns nothing local timer t = CreateTimer() set test = StoI("test") call BJDebugMsg(I2S(i)) call TriggerSleepAction(5.0) call TimerStart(t, 0.01, true, function test_loop) endfunction |
| 05-03-2007, 08:28 AM | #12 | |
Quote:
OR in 1.21 Blizz are also saving string tables.... will test it. btw your test is not random ! to test correctly you must simple run some RandomInts convert it to strings after call BJDebugMsg(I2S(StoI("Toadcop"))) (// ;D ) and if the id before loading and after loading will be the same of BJDebugMsg(I2S(StoI("Toadcop"))) (after loading you must call this separate witho out any other string inits !!!) but i am 100% sure what string tables are not saving. |
| 05-03-2007, 09:13 PM | #13 | |||
Quote:
Quote:
Quote:
I have included this into my system and so far have not experienced any glitches or errors. |
| 05-04-2007, 11:26 AM | #14 |
sorry your tests sucking ! well as i have allready sad string tables are not saving than saving and loading the game =) (and it was known long ago) |
| 05-04-2007, 02:18 PM | #15 | ||
Quote:
Quote:
Anyone else have an opinion or input about this method? PS: Please keep this on-topic. |
