Starting jass

rexpim

Member
Reaction score
8
I'm moving from gui to jass this is my first spell, so i wanna know if i got mistakes in this code

JASS:
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
//              -Made By REX  
//
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

//===========================================================================

scope NatureStrike

globals
    private constant integer NATURESTRIKE = 'A01U'   // Nature Strike RAW CODE
    private constant integer TREE = 'BTtw'               // Tree RAW CODE
    private constant integer VAR = 2                     // Tree variation
    private constant real SCALE = 2.00                 // Tree scale size
    private constant real LIFE = 20.00                 // Tree life time
endglobals

//===========================================================================
//===========================================================================

private function Trig_NatureStrike_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == NATURESTRIKE       
endfunction

function Trig_NatureStrike_Actions takes nothing returns nothing
    local destructable FSTREE
    local location FORCETARGET = GetSpellTargetLoc()
    call CreateDestructableLoc( TREE, FORCETARGET, GetRandomDirectionDeg(), SCALE, VAR )
    set FSTREE = GetLastCreatedDestructable()
    call TriggerSleepAction( LIFE )
    call RemoveDestructable( FSTREE )
endfunction

//===========================================================================

function InitTrig_NatureStrike takes nothing returns nothing
    set gg_trg_NatureStrike = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_NatureStrike, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_NatureStrike, Condition( function Trig_NatureStrike_Conditions ) )
    call TriggerAddAction( gg_trg_NatureStrike, function Trig_NatureStrike_Actions )
endfunction

endscope

//===========================================================================

//===========================================================================


I'm using sleep action, can any1 tell me another action to get the life of the tree
 

luorax

Invasion in Duskwood
Reaction score
67
1, Don't use BJs. BJs use natives, so you can do everything, what they do calling the right natives directly. Also, "CreateDestructableLoc" returns a destructible, so you can use this:

JASS:
    local location FORCETARGET = GetSpellTargetLoc()
    local destructable FSTREE = CreateDestructableLoc( TREE, FORCETARGET, GetRandomDirectionDeg(), SCALE, VAR )


2, Try to avoid using locations. Using real coordinates is more powerful, and faster than using locations.

3, Remove leaks! Don't forget to null handle variables (like timers, units, destructables and so on)

4, It's just a suggestion: naming. I suggest you to use variable names like this:

GLOBAL_CONSTANT (Example: TICK_DMG)
Global_Dynamic (Example: Current_Target)
lOcal (Example: local real xPos)

Or use some "theme". It makes the things easier.

JASS:
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
//              -Made By REX  
//
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

//===========================================================================

scope NatureStrike

globals
    private constant integer NATURESTRIKE = 'A01U'       // Nature Strike RAW CODE
    private constant integer TREE = 'BTtw'              // Tree RAW CODE
    private constant integer VAR = 2                    // Tree variation
    private constant real SCALE = 2.                 // Tree scale size
    private constant real LIFE = 20.                 // Tree life time
endglobals

//===========================================================================
//===========================================================================

private function Trig_NatureStrike_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == NATURESTRIKE       
endfunction

function Trig_NatureStrike_Actions takes nothing returns nothing
    local destructable dTree = CreateDestructable(TREE, GetSpellTargetX(), GetSpellTargetY(), GetRandomReal(0, 360), SCALE, VAR) //We don't need BJ's, and Locations!

    call TriggerSleepAction( LIFE )
    call RemoveDestructable( dTree)

    //Cleaning leaks
    set dTree = null
endfunction

//===========================================================================

function InitTrig_NatureStrike takes nothing returns nothing
    set gg_trg_NatureStrike = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_NatureStrike, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_NatureStrike, Condition( function Trig_NatureStrike_Conditions ) )
    call TriggerAddAction( gg_trg_NatureStrike, function Trig_NatureStrike_Actions )
endfunction

endscope

//===========================================================================

//===========================================================================
 

luorax

Invasion in Duskwood
Reaction score
67
Too much wait can cause lag, but if you don't spamm the ability, it won't cause too much problem. Also, using a timer to destroy the destructible should be a better way. Using Vexorian's TimerUtils you can easily pass the required data to a timer, using a struct.
Or another useful way is a periodic timer, what reduces every "Tree"'s life by a previously defined ammount every x.y seconds.
 

Zeth

Member
Reaction score
3
I'm using sleep action, can any1 tell me another action to get the life of the tree

JASS:
scope NatureStrike

globals
    private constant integer NATURESTRIKE = 'A01U'   // Nature Strike RAW CODE
    private constant integer TREE = 'BTtw'               // Tree RAW CODE
    private constant integer VAR = 2                     // Tree variation
    private constant real SCALE = 2.00                 // Tree scale size
    private constant real LIFE = 20.00                 // Tree life time
endglobals

//===========================================================================
//===========================================================================

private function Trig_NatureStrike_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == NATURESTRIKE       
endfunction

private struct data

    private timer t
    private destructable FSTREE

static method kill takes nothing returns nothing
    local thistype this=GetTimerData(GetExpiredTimer())
    call RemoveDestructable(.FSTREE)
    call ReleaseTimer(GetExpiredTimer())
    set .FSTREE=null
    set .t=null
endmethod

static method create takes nothing returns thistype
    local thistype this=.allocate()
    set .t=NewTimer()
    set .FSTREE = CreateDestructable(TREE,GetSpellTargetX(),GetSpellTargetY(),GetRandomReal(1.,360.),SCALE,VAR) // use of coordinates instead of locations
    call SetTimerData(.t,this)
    call TimerStart(t,LIFE,false,function thistype.kill)
    return this
endmethod

endstruct

private function Trig_NatureStrike_Actions takes nothing returns nothing
    local data t=data.create()
endfunction

//===========================================================================

private function InitTrig_NatureStrike takes nothing returns nothing
    set gg_trg_NatureStrike = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_NatureStrike, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_NatureStrike, Condition( function Trig_NatureStrike_Conditions ) )
    call TriggerAddAction( gg_trg_NatureStrike, function Trig_NatureStrike_Actions )
endfunction

endscope


Note the use of the Vexorian's TimerUtils. SetTimerData, GetTimerData, and ReleaseTimer.

If you do not understand something, just ask.
 

rexpim

Member
Reaction score
8
JASS:
scope NatureStrike

globals
    private constant integer NATURESTRIKE = 'A01U'   // Nature Strike RAW CODE
    private constant integer TREE = 'BTtw'               // Tree RAW CODE
    private constant integer VAR = 2                     // Tree variation
    private constant real SCALE = 2.00                 // Tree scale size
    private constant real LIFE = 20.00                 // Tree life time
endglobals

//===========================================================================
//===========================================================================

private function Trig_NatureStrike_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == NATURESTRIKE       
endfunction

private struct data

    private timer t
    private destructable FSTREE

static method kill takes nothing returns nothing
    local thistype this=GetTimerData(GetExpiredTimer())
    call RemoveDestructable(.FSTREE)
    call ReleaseTimer(GetExpiredTimer())
    set .FSTREE=null
    set .t=null
endmethod

static method create takes nothing returns thistype
    local thistype this=.allocate()
    set .t=NewTimer()
    set .FSTREE = CreateDestructable(TREE,GetSpellTargetX(),GetSpellTargetY(),GetRandomReal(1.,360.),SCALE,VAR) // use of coordinates instead of locations
    call SetTimerData(.t,this)
    call TimerStart(t,LIFE,false,function thistype.kill)
    return this
endmethod

endstruct

private function Trig_NatureStrike_Actions takes nothing returns nothing
    local data t=data.create()
endfunction

//===========================================================================

private function InitTrig_NatureStrike takes nothing returns nothing
    set gg_trg_NatureStrike = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_NatureStrike, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_NatureStrike, Condition( function Trig_NatureStrike_Conditions ) )
    call TriggerAddAction( gg_trg_NatureStrike, function Trig_NatureStrike_Actions )
endfunction

endscope


Note the use of the Vexorian's TimerUtils. SetTimerData, GetTimerData, and ReleaseTimer.

If you do not understand something, just ask.

You are talking about this Vexorian's TimerUtils
didn't get this part "local thistype"

[ljass]GetWidgetLife(<destructable>)[/ljass]

should work
This works for units to?

Too much wait can cause lag, but if you don't spamm the ability, it won't cause too much problem. Also, using a timer to destroy the destructible should be a better way. Using Vexorian's TimerUtils you can easily pass the required data to a timer, using a struct.
Or another useful way is a periodic timer, what reduces every "Tree"'s life by a previously defined ammount every x.y seconds.
i know that's why i asked for another way to do it, i will try Vexorian's TimerUtils
 

Laiev

Hey Listen!!
Reaction score
188
>> You are talking about this Vexorian's TimerUtils
Yes

>> didn't get this part "local thistype"
local = you know what is, variable local and thistype refer to the the struct type/name
for example:

JASS:
struct A
    private static method create takes nothing returns thistype //thistype because will return this struct
       return A //return A because A is the same as thistype, but you should use thistype instead of the direct name
    endmethod
endstruct


>> This works for units to?
This work for Widgets, I'm not sure what is all Widgets but I'm sure that Units and Items works.

PS: GetWidgetLive is fastest then GetUnitState
 

Sevion

The DIY Ninja
Reaction score
424
Methods and [ljass]thistype[/ljass] are all part of structs (data structures).

Basically, imagine that it's a new variable type with members and methods (functions pertaining to that specific type).

JASS:
struct myStruct
    integer myData
    public method getData takes nothing returns integer
        return this.myData // this implies &quot;this instance&quot;
    endmethod
    public method setData takes integer newData returns nothing
        set this.myData = newData
    endmethod
    public static method create takes integer data returns thistype
        // static method create always returns thistype and is public (public need not be explicitly set
        local thistype data = thistype.allocate() // allocates an address for variable &quot;data&quot; of type &quot;thistype&quot; or myStruct
        // It&#039;s the same as typing local myStruct data = myStruct.allocate()
        // Imagine the create method as a two-step process like UnitCreate broken into two. Create -&gt; Allocate
        set data.myData = data
        return data
    endmethod
endstruct
 

Bribe

vJass errors are legion
Reaction score
67
Just avoid structs whenever you can, because you'll really screw yourself in efficiency 99% of the time. Structs don't work in vJass like they do in truly-integrated programming languages, so stick to plain JASS and keep things simple.
 

Sgqvur

FullOfUltimateTruthsAndEt ernalPrinciples, i.e shi
Reaction score
62
Just avoid structs whenever you can, because you'll really screw yourself in efficiency 99% of the time. Structs don't work in vJass like they do in truly-integrated programming languages, so stick to plain JASS and keep things simple.

Structs are parallel arrays. Arrays are the fastest(as in most efficient) thing in Jass2.
Structs also reduce the complexity of a jass script immensely.

What is a "truly-integrated programming language" anyway?
 

Bribe

vJass errors are legion
Reaction score
67
Nothing wrong with using them if you know what you're doing, but most people reference the same "struct member" over and over and over, not realising the efficiency hit because of all the excessive array references instead of storing them temporarily to local variables.
 

rexpim

Member
Reaction score
8
Ty for the answers

I think he talks about the lifetime of the destructable (constant real LIFE = 20.00), not life itself.
i want to create the tree and then remove it from the game

I got a big problem I implemented TimerUtils to my map to test it and i got this error "Function redeclared: New Timer" what I'm doing wrong?
Solved
But now i got error "Syntax error" in this line " static if(TimerUtils___USE_HASH_TABLE) then"
 

Zeth

Member
Reaction score
3
i want to create the tree and then remove it from the game

Ok, then you don't need the life of the tree. Destructables are handles, then you can use a system like TimedHandles too (i don't know if that system is updated.)
 

Laiev

Hey Listen!!
Reaction score
188
ya, you create trigger and register events, conditions and actions to that trigger, then that trigger can run ingame
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top