HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

struct question

01-04-2009, 07:00 PM#1
dorreen
I need to know if there is some way to detect difference between Child1.findInstance() and Child2.findInstance() ( if there is any )

Im trying to do something like this:
Collapse JASS:
struct Parent

 static method findInstance takes unit h returns Parent
    local Parent this=0
    if GetWidgetLife(h) > 0.405 then
        if HaveStoredInteger(Cache, < child structs name >, I2S(H2I(h))) == true then
            set this=GetStoredInteger(Cache, < child structs name >, I2S(H2I(h)))
        endif
    endif
    return this
 endmethod
   // some stuff
endstruct

struct Child1 extends Parent
    // some stuff
endstruct

struct Child2 extends Parent
    // some stuff
endstruct

function test takes unit h returns nothing
    local Child1 a=Child1.findInstance(h)
    local Child2 b=Child2.findInstance(h)
endfunction

So, is there any way to do something like this?
01-04-2009, 07:13 PM#2
Zerzax
This is from the JassHelper manual, it might help:

Quote:
Originally Posted by Manual

It is possible to acquire the type id of an instance of an struct that extends an interface, this type id is an integer number that is unique per struct type that extends that interface.

Collapse JASS:
interface A
    integer x
endinterface

struct B extends A
    integer y
endstruct

struct C extends A
    integer y
    integer z
endstruct

function test takes A inst returns nothing
   if (inst.getType()==C.typeid) then
     // We know for sure inst is actually an instance of type C
       set C(inst).z=5 //notice the typecast operator
   endif
   if (inst.getType()==B.typeid) then
       call BJDebugMsg("It was of type B with value "+I2S( B(inst).y  ) )
   endif
endfunction
In short, .getType() is a method that you use on instances of an object whose type extends an interface. And .typeid is an static constant set for struct types that extend an interface.


You'd need an interface to use getType and the static struct type. Also, there might be something on this in another part of the manual more suited to what you want.
01-04-2009, 07:26 PM#3
dorreen
I am using .getType() and it works fine with normal methods, but it doesnt work with static methods.

I kinda need to know structs typeid before I Get it from gamecache.
01-04-2009, 08:14 PM#4
Zerzax
A static method behaves exactly like a function, which is what Vexorian used. If you want to do what Vexorian did, just call it a static method instead of a function... Perhaps use some kind of attachment system with the right typeId if the static method is a code callback of some sort? (you didn't specify whether you could pass arguments to the method or not)
01-04-2009, 08:39 PM#5
Anitarf
If it can't be done then that's likely because you're doing it wrong. Why do you even need a different missionkey for each child anyway?
01-05-2009, 10:05 AM#6
dorreen
I guess it doesnt matter. I can just use key string directly. Well, thanks for help.