HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

S2I - Return Bug

04-22-2007, 05:20 PM#1
Ammorth
If this has already been covered, ignore this post.

Collapse JASS:
function String2Int takes string s returns integer
    return s
    return 0
endfunction
Can be used to find the "string slot" of the given string. If the string doesn't exist it will be created and the slot will be returned.

alternatively:

Collapse 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:

Collapse 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
blu_da_noob
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
Ammorth
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
blu_da_noob
You could try hashing. Don't know how efficient it would be in JASS, but hey.
04-22-2007, 08:50 PM#5
Vexorian
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
Toadcop
Ammorth - this is a old story...
05-02-2007, 05:05 AM#7
Ammorth
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
blu_da_noob
Quote:
Originally Posted by Ammorth
@Vexorian, I know Game-cache is great for everything, I just don't think it's the answer for everything.

Gamecache isn't great for everything, but gamecache is perfect for this kind of string stuff.
05-02-2007, 03:36 PM#9
Captain Griffen
String tables are, I believe, reset on saving/loading.
05-02-2007, 05:41 PM#10
Toadcop
Quote:
String tables are, I believe, reset on saving/loading
yes ! but it can be used i mean set somearray[s2i("string")]=data... if you know what you are doing ;)
05-02-2007, 11:28 PM#11
Ammorth
Quote:
Originally Posted by Captain Griffen
String tables are, I believe, reset on saving/loading.
I don't think so. I tried a test and the strings were still intact (both on save, load, and restart war3 and load).

Btw, the function I use to test is as follows:
Collapse 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
Toadcop
Quote:
I don't think so. I tried a test and the strings were still intact
O_O yes and we all idiots !?

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
Ammorth
Quote:
Originally Posted by Toadcop
O_O yes and we all idiots !?
Never said anything like that, I only said that it seems the strings stay intact even after loading the map.

Quote:
Originally Posted by Toadcop
OR in 1.21 Blizz are also saving string tables.... will test it.
btw your test is not random !
That was the standard function, I have been modifying it slightly for different tests, which all yield the same results: The string table stays intact.

Quote:
Originally Posted by Toadcop
but i am 100% sure what string tables are not saving.
Well they are.

I have included this into my system and so far have not experienced any glitches or errors.
05-04-2007, 11:26 AM#14
Toadcop
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
Ammorth
Quote:
Originally Posted by Toadcop
sorry your tests sucking ! well as i have allready sad string tables are not saving than saving and loading the game =)
Care to post a test map proving this? In life, it is required to prove something with fact, instead of just saying "you suck cause I am right."

Quote:
Originally Posted by Toadcop
(and it was known long ago)
But thats what so lovely about patches. Orbs used to work fine, "It was knowns long ago" but when they released a patch, the orbs broke.

Anyone else have an opinion or input about this method?

PS: Please keep this on-topic.