• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Vjass hashtable glitches or folly?

Status
Not open for further replies.
Level 4
Joined
Apr 19, 2013
Messages
86
Hey again guys, you probably remember me from my never-ending, relentless-going-on-shameless queries about Anachron's vjass inventory system.

I'm back! This time what started as a simple tweak to pair special effects attached to the real unit to be created in tandem with the dummy inventory unit has ended in a fundamental breakdown of my understanding of vjass.

PurgeandFire111 got me off to a great start, but for some reason his code isn't working on my triggers. I'm fairly certain I entered the code in correctly. So, then I looked up some possible causes and saw maybe its because I need to update jasshelper or patch to the latest wc3 patch. And I didn't import any .j files which I learned can cause similar compile errors.

No matter how hard I try, I always get:

Error: undeclared function: LoadUnit
Error : undeclared function: SaveUnit

Here is some code snippets to clue everyone in on my hashtable format

JASS:
scope test initializer init
globals
    hashtable HeroHash = InitHashtable()
endglobals

Here it is the real unit is saved as it is created:
JASS:
call SaveUnit(HeroHash, GetHandleId(hero), 1337, fakeInv)

And here is when the unit should be loaded to check what special effects to destroy:

JASS:
call DestroyEffect(.dummyeffects[i])
                if theUnit != null then
                    set .dummyeffects[i] = AddSpecialEffectTarget(.sfx[i], LoadUnit(HeroHash, GetHandleId(theUnit), 1337), .attachments[i])

It seems simple enough right? I've spent five days trying this and that with nothing to show for it. Anybody have any thoughts? I hope its not something with my Newgen or something more fundamental. Any help at all is appreciated!
 
Level 4
Joined
Apr 19, 2013
Messages
86
Oh, that's something I didn't hear about yet. Thanks a bunch for bringing this to my attention! I'll try to place it somewhere else and edit this post w/ the outcome.
 
u cant initialize hashtables in the gloabls block but u can do something like this.
JASS:
library tester initializer init

globals
    private hashtable hash
endglobals

//===========================================================================
private function init takes nothing returns nothing
    local trigger t = CreateTrigger()
    set hash = InitHashtable()
    set t = null
endfunction

endlibrary

this does initialize them at map init
 
If you go for library, please show DiggetyBo, that he should go for onInit method since those are called before initializer functions. Modules are even faster.

Your problem lies in functions you call, since there arent any Save/Load Unit natives. You probably wanted:
JASS:
native  LoadUnitHandle	   takes hashtable table, integer parentKey, integer childKey returns unit
native  SaveUnitHandle    takes hashtable table, integer parentKey, integer childKey, unit whichUnit returns boolean
 
If you go for library, please show DiggetyBo, that he should go for onInit method since those are called before initializer functions. Modules are even faster.

Your problem lies in functions you call, since there arent any Save/Load Unit natives. You probably wanted:
JASS:
native  LoadUnitHandle	   takes hashtable table, integer parentKey, integer childKey returns unit
native  SaveUnitHandle    takes hashtable table, integer parentKey, integer childKey, unit whichUnit returns boolean

he had scope i was just showing an alternate method on how he could do it.
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
you actually can initalize hashtables in globals block without any problems, at least I never had any problems with that

and yes SaveUnit and LoadUnit are not valid functions

if you are trying to save to hashtbale data type other then native ones(string, real, integer, boolean), you have to put Handle keyword there(Save/LoadUnitHandle, Save/LoadItemHandle ...)

Modules are even faster.

Modules are not faster, they are ordinary Jass functions as everything else, they are just being executed before anything else while using Vexorians JassHelper
 
^dude, I know what module is and no, it's not a function. Modules are a mechanism to package libraries. Since veryJass is enabled basically only by JNPG, fact is that they are being executed before anything else; so.. it's the best method.

About initializing hashtables, if you go for struct members you can alternatively declare them via:
JASS:
struct MyStruct extends array
    static hashtable myHash = InitHashtable()
endstruct

//access:
MyStruct.myHash
yet globals still suits fine.
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
that is the same as initializing globals, so it is totally safe to initialize Hashtables in globals block

in Cohadars JH onInit methods that are declared in modules are ran just before InitTrig

btw:

JASS:
library lib

    private module m
        private /* safety */static method onInit takes nothing returns nothing
            //...
        endmethod
    endmodule
    
    private struct s_init extends array
        implement m
    endstruct

endlibrary
->
JASS:
//library lib:

    
//Implemented from module lib__m:
        function s__lib__s_init_lib__m___onInit takes nothing returns nothing
            //...
        endfunction

//library lib ends

it is just called in the main function:

JASS:
function main takes nothing returns nothing
     //some shit
call ExecuteFunc("jasshelper__initstructs9026420")

    call InitGlobals()
    call InitCustomTriggers()

endfunction

function jasshelper__initstructs9052472 takes nothing returns nothing

call ExecuteFunc("s__lib___s_init_lib___m__onInit")

endfunction

so no, it is just a function, the call is just injected to the main function of Jass, which runs when map loads
 
edo u're acting like a child. I suggested that globals can also be declared via struct member block, as an alternative option - not that global block is unsafe.

You do not have to show me compiled code from jasshelper since I knew the compilation process before you've even joined the hive. And no, don't talk shit. Interpretation of interior of the module has nothing to do with what module in programming truly is. "module is a function"...
 
Last edited:
Level 4
Joined
Apr 19, 2013
Messages
86
Wow, guys I finally made sense of it. Somewhere that rings a bell, I guess I forgot that some natives aren't handled. I still think it's weird, but I'm getting used to that notion. And I now know the right way to initialize a hashtable. (look out!!)

knowledge is powerful, now I got a sweet inventory system that shows gear on the inventory model as you equip it!!

I'm so stoked to have cracked the code on this thing. It started off as something trivial, but it kept eluding me for days upon days and now it feels like some type of nobel-prize winning accomplishment haha.

Anyway, can't thank all you guys enough for the effective solutions here. +mad rep
 
Status
Not open for further replies.
Top