structs

jackall

You can change this now in User CP.
Reaction score
37
is there any way i can change the .create() method of a struct?
if no, can i call it in another method and then not use something like
Code:
local blah b = blah.create()
 

chobibo

Level 1 Crypt Lord
Reaction score
48
JASS:

static method create takes <optional parameters> returns <the struct type>
local thistype this=thistype.allocate() //<--- you need this to instanciate a struct
// add your stuff here
return this
endmethod
 

tooltiperror

Super Moderator
Reaction score
231
Should return thistype, instead.

JASS:
struct Anything

    integer x

    static method create takes integer value returns thistype
        local thistype this=thistype.allocate()
        set this.x=value
        return this
    endmethod

endstruct


You can do the same for the method onDestroy with no arguments and no return type, to run right before recycling the struct.
 

Bribe

vJass errors are legion
Reaction score
67
>> You can do the same for the method onDestroy with no arguments and no return type, to run right before recycling the struct.


This is terrible advice. Never use the onDestroy method.
 

tooltiperror

Super Moderator
Reaction score
231
Why not? Is speed so important that a function call is too slow?
 
Reaction score
456
Which doesn't matter at all. You're not going to destroy them 10 times per second anyway. I bet it wouldn't matter even then.
 

Bribe

vJass errors are legion
Reaction score
67
> Which doesn't matter at all.

It's privy information to know, especially for projectile systems which burn through instances.
 

Sgqvur

FullOfUltimateTruthsAndEt ernalPrinciples, i.e shi
Reaction score
62
JASS:

struct blah
    integer x
    
    static method new takes integer x returns blah
        local blah b = blah.allocate()
        set b.x = x
        return b
    endmethod

endstruct

function Blah takes integer x returns blah
    local blah b = blah.create()
    set b.x = x
    return b
endfunction

function BlahDemo takes nothing returns nothing
    local blah b = blah.new(4)
    local blah b2 = Blah(5) // I like this more
    local blah b3 = new Blah(6) // this is perhaps even better but unfortunately won't compile :/
    
    // use blahies
endfunction
 

Romek

Super Moderator
Reaction score
963
> You can do the same for the method onDestroy with no arguments and no return type, to run right before recycling the struct.
Using onDestroy isn't quite the same as overriding the create method.

You can actually override the destroy method too:
JASS:
struct Something

    method destroy takes nothing returns nothing
        call this.deallocate()
        // And friends
    endmethod

endstruct
 

Bribe

vJass errors are legion
Reaction score
67
> You're not going to destroy them 10 times per second anyway. I bet it wouldn't matter even then.

I see you added that on to your post, just like JassHelper adds two bogus "generated" methods for onDestroy:

// Generated method caller for s__struct_onDestroy
...

// Generated method executor for s__struct_onDestroy
...

To top off the already-existing function. A waste of performance and map file size, and big maps with a lot of systems importing onDestroy have a huge wasted performance and filesize overhead.

For the record, parent/child structs do the same wasteful thing, so does this:

method b takes nothing returns nothing
call this.a()
endmethod
method a takes nothing returns nothing
// This is going to generate two function proxies even though it effectively does nothing o_O
endmethod
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top