HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Math questions

08-14-2008, 01:06 PM#1
Vestras
1 - Pow? What does it do? Is it like 2 timed with 2 2 times? Or..? I mean, the first one is a real, and the second one is power? I don't get it...

2 - Hashes? What can they be used for? What can you use them for? How do you create them?

More will surely pop up...
08-14-2008, 01:19 PM#2
Tukki
1: Pow(a, b) = a^b, it raises the a value by b times.
2: Hashing algorithms is used to squeeze numbers. It can be useful if you are storing stuff in arrays.
08-14-2008, 01:24 PM#3
Themerion
1)
Code:
Pow(x,7) = x^7 = x*x*x*x*x*x*x

2)You don't create a hash. Use gamecache, or look at Strilanc's or Cohadar's systems.

Collapse Sweet usage of a hash:
call HashStoreValueByKey(17,'h000')

call BJDebugMsg( I2S( HashGetValueByKey('h000') ) )
// Will display 17
08-14-2008, 01:33 PM#4
Vestras
Pow - Okay, I guessed so too.
Hashes - That function doesn't exist.
08-14-2008, 04:02 PM#5
Ammorth
http://en.wikipedia.org/wiki/Hash_function

for all your hashing needs.
08-14-2008, 05:35 PM#6
Themerion
Quote:
Hashes - That function doesn't exist.

Nope, I just wanted to show you the idea behind it. With game cache, it would look something like...

Collapse JASS:
// Provided you have an initialized Game Cache

local integer value

call StoreInteger(myGameCacheVariable, "myOwnCustomUnitDataOrWhatever", I2S('h000'), 17)

set value = GetStoredInteger(myGameCacheVariable, "myOwnCustomUnitDataOrWhatever", I2S('h000'))
call BJDebugMsg( I2S( value ))
08-14-2008, 06:05 PM#7
Vestras
Okay, but what are they useful for? Passwords? Maybe for debuging?
08-14-2008, 06:16 PM#8
Themerion
Haven't you ever used an attachment system? ;)

Collapse JASS:
// This spell will show the effect's death-animation
// after 2 seconds.
// The effect will appear in the spell target location.

// H2I is our way of typecasting any object (such as a timer) into a unique integer.
// It is possible to use because we trick the syntax checker.

function H2I takes handle h returns integer
    return h
    return 0
endfunction

function MySpell_End takes nothing returns nothing

// Timers cannot be used with game-caches.
// So, first we make the timer into an integer, then turn the integer into a string.

    local string ts = I2S(H2I(GetExpiredTimer()))

// Get the real values from the game cache udg_cache
// The values are in the category of the timer, and are associated to with "x" and "y"

    local real x = GetStoredReal( udg_cache, ts, "x" )
    local real y = GetStoredReal( udg_cache, ts, "y" )

    call DestroyEffect( AddSpecialEffect( "war3mapimported\\WAAAAAAGH.mdx", x, y ) )

// FlushStoredMission will clean up the attachments in the game cache (since we won't use them anymore)
// Notice how we only clean up the values associated with our timer.

    call FlushStoredMission( udg_cache, ts )

    call DestroyTimer(GetExpiredTimer())
endfunction

function MySpell_Actions takes nothing returns nothing
    local location loc = GetSpellTargetLoc()
    local timer t=CreateTimer()

// Timers cannot be used with game-caches.
// So, first we make the timer into an integer, then turn the integer into a string.

    local string ts=I2S(H2I(t))

// Set the real values to the game cache udg_cache
// The values will be stored in the category of the timer, and are associated to with "x" and "y"

    call StoreReal( udg_cache, ts , "x", GetLocationX(loc) )
    call StoreReal( udg_cache, ts , "y", GetLocationY(loc) )

    call TimerStart(t,2.0,false,function MySpell_End)

    call RemoveLocation(loc)
    set loc=null
    set t=null
endfunction