wurstscript / WurstScript

Programming language and toolkit to create Warcraft III Maps
https://wurstlang.org
Apache License 2.0
226 stars 28 forks source link

how to really create a string autohash?? #1054

Closed fbicirno closed 2 years ago

fbicirno commented 2 years ago

@compiletime public function string.autoHash() returns int return this.getHash() i really need a string autohash method to save game speed

but its look like not work.. such as in wurst "test".autohash() in game " stringhash("test") "

Frotty commented 2 years ago

I don't understand what you are trying to do here. Hash to save game speed? Putting @compiletime means the func will be executed once at compiletime.

fbicirno commented 2 years ago

I want to convert some strings to hashes at compile time, not in game.

fbicirno commented 2 years ago

I want the compiler to automatically turn "text".gethash() into a hash value like 97675546

cloudfox2 commented 2 years ago

You should use compiletime("text".getHash())

fbicirno commented 2 years ago

You should use compiletime("text".getHash())

The code is too long,not good to read

fbicirno commented 2 years ago

image why not work

Frotty commented 2 years ago

@cloudfox2 is correct. compiletime() expression are evaluated once at compiletime and then are replaced with the result. Because this is not defined when running the expression in the function body your function evaluates to:

function string.autohash2() returns int
    return null

If you want to hash your strings for protection of some sort I would suggest using specialized software for that like W3Protect and not do it in source code.