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.
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +1
  • V-SNES V-SNES:
    Happy Friday!
    +1

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top