• 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] Questions related to "instance".

Status
Not open for further replies.
Level 11
Joined
Oct 11, 2012
Messages
711
Hi all. What does "instance" mean in vJass? I have seen a lot of tutorials talking about it but I cannot get a clear meaning of it.
Also, under what circumstances do I need to destroy the instance (set it to 0 or something) or to use the destroy method in order to free the memory usage?
Does the following spell need to use the destroy thing?
JASS:
struct JRXFeng extends array
    private static method run takes nothing returns boolean
        local unit caster = GetTriggerUnit()
        local unit dummy
        local real x=GetSpellTargetX()
        local real y=GetSpellTargetY()
        local integer level=GetUnitAbilityLevel(caster,'A0LP')
        if GetSpellAbilityId()=='A0LP' then
            set dummy=CreateUnit(GetOwningPlayer(caster),'n024',x,y,bj_UNIT_FACING)
            call UnitAddAbility(dummy,'A0LQ')
            call SetUnitAbilityLevel(dummy,'A0LQ',level)
            call UnitApplyTimedLife(dummy,'BHwe',22.) 
            call IssuePointOrder(dummy,"stampede",x,y)
        endif
        set caster = null
        set dummy = null
        return false
    endmethod

    private static method onInit takes nothing returns nothing
        local trigger t = CreateTrigger()
        call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
        call TriggerAddCondition(t, Condition(function thistype.run))
        set t = null
    endmethod
endstruct

Edit:
One last question, how to use "extends array"? In vJass manual, it stats that if the struct has no method then use "extends array". But in Mag's struct example, he uses "extends array" while having methods in the struct. This really confuses me... Thanks guys.
 
Best way to describe instance is by example. Say we have a spell and it is casted by 20 units basically running 20 times. Each of those is an instance of the spell.

That spell is an instant spell so it is not needed to destroy anything as you don't create a struct in it.

There are a few tutorials on here that deal with extend array in vJass. Look at magtheridon's and nestharus's to learn how to use them. It is pretty easy.
To give a short example.
With the extend array your have to make your own allocator and deallocator methods.
You then use them just like you would normally. Take a look at some of my spells / systems i use extends array in all of them.

Here are the 2 specific guides i was talking about. You should look at the struct for dummies first then look at the other one.
http://www.hiveworkshop.com/forums/...ls-280/coding-efficient-vjass-structs-187477/
http://www.hiveworkshop.com/forums/jass-ai-scripts-tutorials-280/structs-dummies-197435/
 
Level 18
Joined
Sep 14, 2012
Messages
3,413
On your code I may tell this :
JASS:
private static method run takes nothing returns boolean
        local unit caster = GetTriggerUnit()
        local unit dummy
        local real x=GetSpellTargetX()
        local real y=GetSpellTargetY()
        local integer level=GetUnitAbilityLevel(caster,'A0LP')
        if GetSpellAbilityId()=='A0LP' then
            set dummy=CreateUnit(GetOwningPlayer(caster),'n024',x,y,bj_UNIT_FACING)
            call UnitAddAbility(dummy,'A0LQ')
            call SetUnitAbilityLevel(dummy,'A0LQ',level)
            call UnitApplyTimedLife(dummy,'BHwe',22.) 
            call IssuePointOrder(dummy,"stampede",x,y)
        endif
        set caster = null
        set dummy = null
        return false
    endmethod
->
JASS:
private static method run takes nothing returns boolean
        local unit caster
        local unit dummy
        local real x
        local real 
        local integer level
        if GetSpellAbilityId()=='A0LP' then
            set caster = GetTriggerUnit()
            set x = GetSpellTargetX()
            set y = GetSpellTargetY()
            set level=GetUnitAbilityLevel(caster,'A0LP')
            set dummy=CreateUnit(GetOwningPlayer(caster),'n024',x,y,bj_UNIT_FACING)
            call UnitAddAbility(dummy,'A0LQ')
            call SetUnitAbilityLevel(dummy,'A0LQ',level)
            call UnitApplyTimedLife(dummy,'BHwe',22.) 
            call IssuePointOrder(dummy,"stampede",x,y)
            set caster = null
            set dummy = null
        endif
        return false
    endmethod

Anyway struct extends array don't have allocate/create and deallocate/destroy method :)
 
Level 11
Joined
Oct 11, 2012
Messages
711
Best way to describe instance is by example. Say we have a spell and it is casted by 20 units basically running 20 times. Each of those is an instance of the spell.

That spell is an instant spell so it is not needed to destroy anything as you don't create a struct in it.

There are a few tutorials on here that deal with extend array in vJass. Look at magtheridon's and nestharus's to learn how to use them. It is pretty easy.
To give a short example.
With the extend array your have to make your own allocator and deallocator methods.
You then use them just like you would normally. Take a look at some of my spells / systems i use extends array in all of them.

Here are the 2 specific guides i was talking about. You should look at the struct for dummies first then look at the other one.
http://www.hiveworkshop.com/forums/...ls-280/coding-efficient-vjass-structs-187477/
http://www.hiveworkshop.com/forums/jass-ai-scripts-tutorials-280/structs-dummies-197435/

Thanks, DIMF. So do I need to allocate or deallocate in my example? I suppose not because it is an instant spell? I have read the tutorials but still kinda confused. Actually I am using Mag's struct example. :/

On your code I may tell this :
JASS:
private static method run takes nothing returns boolean
        local unit caster = GetTriggerUnit()
        local unit dummy
        local real x=GetSpellTargetX()
        local real y=GetSpellTargetY()
        local integer level=GetUnitAbilityLevel(caster,'A0LP')
        if GetSpellAbilityId()=='A0LP' then
            set dummy=CreateUnit(GetOwningPlayer(caster),'n024',x,y,bj_UNIT_FACING)
            call UnitAddAbility(dummy,'A0LQ')
            call SetUnitAbilityLevel(dummy,'A0LQ',level)
            call UnitApplyTimedLife(dummy,'BHwe',22.) 
            call IssuePointOrder(dummy,"stampede",x,y)
        endif
        set caster = null
        set dummy = null
        return false
    endmethod
->
JASS:
private static method run takes nothing returns boolean
        local unit caster
        local unit dummy
        local real x
        local real 
        local integer level
        if GetSpellAbilityId()=='A0LP' then
            set caster = GetTriggerUnit()
            set x = GetSpellTargetX()
            set y = GetSpellTargetY()
            set level=GetUnitAbilityLevel(caster,'A0LP')
            set dummy=CreateUnit(GetOwningPlayer(caster),'n024',x,y,bj_UNIT_FACING)
            call UnitAddAbility(dummy,'A0LQ')
            call SetUnitAbilityLevel(dummy,'A0LQ',level)
            call UnitApplyTimedLife(dummy,'BHwe',22.) 
            call IssuePointOrder(dummy,"stampede",x,y)
            set caster = null
            set dummy = null
        endif
        return false
    endmethod

Anyway struct extends array don't have allocate/create and deallocate/destroy method :)

Thanks, :) Haven't seen you for a while.
So do I need to write a allocate or deallocate method?

Edit: Why declaring the value of the locals in the "if" statement? Is it more efficient? :)
 
Level 19
Joined
Mar 18, 2012
Messages
1,716
This is your best friend: Alloc Alternative.
Note somewhere with Alloc you find that static if DEBUG_MODE then everything below is just compiled in debug mode with the use to eradicate bugs or errors whatsoever. So just take a look at the allocate, deallocate and onInit method.

Your exmaple is something like an instant spell and requires no allocate, deallocate.
And btw it could look like this
JASS:
    private static method run takes unit u, real x0, real y0 nothing returns nothing
            local unit caster = u
            local real x = x0
            local real y = y0
            local unit dummy = CreateUnit(GetTriggerPlayer(),'n024',x,y,bj_UNIT_FACING)
            local integer leve = GetUnitAbilityLevel(caster,'A0LP')
            call UnitAddAbility(dummy,'A0LQ')
            call SetUnitAbilityLevel(dummy,'A0LQ',level)
            call UnitApplyTimedLife(dummy,'BHwe',22.)
            call IssuePointOrder(dummy,"stampede",x,y)
            set caster = null
            set dummy = null
    endmethod

    private static method onEffect takes nothing returns boolean//Or just use SpellEffectEvent it's awesome.
        if (GetSpellAbilityId()=='A0LP') then//Don't forget the brackets, some 	comparisons won't work without for instance (t > 0)
            call thistype.run(GetTriggerUnit(),GetSpellTargetX(), GetSpellTargetY())
        endif
        return false
    endmethod

    private static method onInit takes nothing returns nothing
        local trigger t = CreateTrigger()
        call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
        call TriggerAddCondition(t, Condition(function thistype.onEffect))
        set t = null
    endmethod
 
No, your best friend is struct no extends array (normal structs).
Alloc alternative is for speed freaks. Really that doesn't matter at all and less stuff is available "natively" such as array members ...

Using struct extends array is a lot better. Look at nestharus's documentation in the tutorial i posted above.

Frankly don't use struct extends array if you need not custom allocators. You don't have to reinvent the wheel.

You are not reinventing the wheel when using struct extends array. You are simply improving the quality of the wheel.

@TO
Instant spells do not need to be allocated / de-allocated.
I always use extends array as it provides better allocation and de-allocation.
 
It is only a matter when it comes to extending struct to another one....

If you are referring to using extends array then no it is not only for that.

When using extends array you have to make your own allocator and deallocator methods. The methods that are used in the original ( struct that does not extend array ) are inefficient. Look at the tutorial nestharus made in my above post.
 
Level 18
Joined
Sep 14, 2012
Messages
3,413
For the non-extending array they aren't that inefficient....

I don't say it is bad to use extends array since I extend every struct but the point is that when you don't really know how struct works don't tell him to use extends array.
In the non-extending example there is no check meaning that if the user make bad things it can break the coding, ect...

So I think he should stick to the normal structs until he is enough familiar with this.
 
I don't say it is bad to use extends array since I extend every struct but the point is that when you don't really know how struct works don't tell him to use extends array.

I find this quite ignorant. I never said i don't know how to use them.
I do know how it works as i have always used this.
The allocate and deallocate are more efficient this way.

If you really think that "normal" struct allocators are inefficient you should learn about efficiency.

Yes i do as they have double free protection which is not required and makes them less efficient.
 
Level 22
Joined
Sep 24, 2005
Messages
4,821
If there is a more efficient way to do something then the other way is inefficient.
The default struct allocator checks for double frees, so I don't think it's inefficient. I wouldn't say it is inefficient, but I'd agree with it being faster.
 
Status
Not open for further replies.
Top