Static Method Data Retrieval

AoW_Hun7312

I'm a magic man, I've got magic hands.
Reaction score
76
I'm trying to use a static method as a trigger inside a struct. For some reason I can't use the struct's values inside of it.

Is there anyway to bypass this?
 

AoW_Hun7312

I'm a magic man, I've got magic hands.
Reaction score
76
Static methods do not reference a specific instance of your struct - you would need to store the struct instance in a global variable whose type corresponds to your struct, then recall that variable in your static method

Is there anyway to make it so the struct has a trigger when you create it? I was trying to do this to avoid that.
 

Ashlebede

New Member
Reaction score
43
JASS:
struct A
    trigger t

    //replaces the default A.create()
    static method create takes nothing returns thistype
        local thistype instance = thistype.allocate()//since we can't use create
        instance.t=CreateTrigger()
        return instance
    endmethod
endstruct


Hope this helps. Though that's most likely not your problem. >_>

If you want a static method to act like it's not static, you can, as Jesus said, set a global, or make the method take a [ljass]thistype[/ljass] parameter.
 

AoW_Hun7312

I'm a magic man, I've got magic hands.
Reaction score
76
That's what I already had. I want it so that each instance of the buff can just run this method whenever the event is fired. Is there a way to do that along with its values without specifying a type?
 

Ashlebede

New Member
Reaction score
43
Make the method non-static. The point of static methods is not to call them from an object. To call them from an object, use non-static methods.
 

Ashlebede

New Member
Reaction score
43
For some reason, I can't show as many chars as I want in a
JASS:
 tag. I'll just post it in 2 different tags.

<div class="bbCodeBlock bbCodeBlock--screenLimited bbCodeBlock--code"><div class="bbCodeBlock-title">JASS:</div><div class="bbCodeBlock-content"><pre class="bbCodeCode"><code class="jass"><span class="keyword">globals</span>
    <a href="http://wiki.thehelper.net/wc3/jass/common.j/hashtable" class="type">hashtable</a> <span>h</span> <span class="symbol">=</span> <a href="http://wiki.thehelper.net/wc3/jass/common.j/InitHashtable" class="native">InitHashtable</a><span class="symbol">(</span><span class="symbol">)</span>
<span class="keyword">endglobals</span>

<span class="keyword">struct</span> <span>A</span>
    <a href="http://wiki.thehelper.net/wc3/jass/common.j/trigger" class="type">trigger</a> <span>t</span>

    <span class="keyword">static</span> <span class="keyword">method</span> <span>Actions</span> <span class="keyword">takes</span> <a href="http://wiki.thehelper.net/wc3/jass/common.j/nothing" class="type">nothing</a> <span class="keyword">returns</span> <a href="http://wiki.thehelper.net/wc3/jass/common.j/nothing" class="type">nothing</a>
        <span class="keyword">local</span> <a href="http://wiki.thehelper.net/wc3/jass/common.j/thistype" class="type">thistype</a> <span>this</span> <span class="symbol">=</span> <a href="http://wiki.thehelper.net/wc3/jass/common.j/LoadInteger" class="native">LoadInteger</a><span class="symbol">(</span><span>h</span><span class="symbol">,</span><a href="http://wiki.thehelper.net/wc3/jass/common.j/GetHandleId" class="native">GetHandleId</a><span class="symbol">(</span><a href="http://wiki.thehelper.net/wc3/jass/common.j/GetTriggeringTrigger" class="native">GetTriggeringTrigger</a><span class="symbol">(</span><span class="symbol">)</span><span class="symbol">)</span><span class="symbol">,</span><span class="number">0</span><span class="symbol">)</span>
        <span class="comment">//actions...</span>
    <span class="keyword">endmethod</span>

    <span class="keyword">static</span> <span class="keyword">method</span> <span>create</span> <span class="keyword">takes</span> <a href="http://wiki.thehelper.net/wc3/jass/common.j/nothing" class="type">nothing</a> <span class="keyword">returns</span> <a href="http://wiki.thehelper.net/wc3/jass/common.j/thistype" class="type">thistype</a>
        <span class="keyword">local</span> <a href="http://wiki.thehelper.net/wc3/jass/common.j/thistype" class="type">thistype</a> <span>instance</span> <span class="symbol">=</span> <a href="http://wiki.thehelper.net/wc3/jass/common.j/thistype" class="type">thistype</a>.<span>allocate</span><span class="symbol">(</span><span class="symbol">)</span></code></pre></div></div><div class="bbCodeBlock bbCodeBlock--screenLimited bbCodeBlock--code"><div class="bbCodeBlock-title">JASS:</div><div class="bbCodeBlock-content"><pre class="bbCodeCode"><code class="jass"><span class="comment">// indent</span>
        <span class="keyword">set</span> <span>instance</span>.<span>t</span><span class="symbol">=</span><a href="http://wiki.thehelper.net/wc3/jass/common.j/CreateTrigger" class="native">CreateTrigger</a><span class="symbol">(</span><span class="symbol">)</span>
        <span class="comment">//TriggerAddAction() and such...</span>
        <span class="keyword">call</span> <a href="http://wiki.thehelper.net/wc3/jass/common.j/SaveInteger" class="native">SaveInteger</a><span class="symbol">(</span><span>h</span><span class="symbol">,</span><a href="http://wiki.thehelper.net/wc3/jass/common.j/GetHandleId" class="native">GetHandleId</a><span class="symbol">(</span><span>instance</span>.<span>t</span><span class="symbol">)</span><span class="symbol">,</span><span class="number">0</span><span class="symbol">,</span><span>instance</span><span class="symbol">)</span>

        <span class="keyword">return</span> <span>instance</span>
    <span class="keyword">endmethod</span>
<span class="keyword">endstruct</span></code></pre></div></div>

Edit : Just realized your trigger wasn&#039;t inside the struct&#039;s data in your example. It doesn&#039;t matter, though. You can make it local.
 

Ashlebede

New Member
Reaction score
43
Can you show the whole struct? Otherwise, it's kind of hard to know where there may be a mistake.
 

Ashlebede

New Member
Reaction score
43
Try replacing all the [ljass]this.BuffID[/ljass]'s to rawcodes for debugging purposes. Maybe [ljass]this.BuffID[/ljass] and such just ain't set right... maybe not. The only way to know is to try. Or check. Both work.
 

AoW_Hun7312

I'm a magic man, I've got magic hands.
Reaction score
76
Ah, I forgot to add a line to set the damage source. It works now, but for some reason it crashes if I have more than 3 instances running. :\
 

Ashlebede

New Member
Reaction score
43
You'd have to show us the whole struct. No, the whole scope. Otherwise, we can only guess what could be wrong.
 

Ashlebede

New Member
Reaction score
43
JASS:
//! indent
    globals
        private cannon array Ability
        private hashtable h = InitHashtable()
    endglobals

//...

    struct skill// !!!


Shouldn't it be [ljass]private skill array Ability[/ljass]? Can't find anything wrong, though...

Edit : Um... why is [ljass]skill[/ljass] displayed as a string?... *investigates*
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top