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
413
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.
  • Varine Varine:
    How can you tell the difference between real traffic and indexing or AI generation bots?
  • The Helper The Helper:
    The bots will show up as users online in the forum software but they do not show up in my stats tracking. I am sure there are bots in the stats but the way alot of the bots treat the site do not show up on the stats
  • Varine Varine:
    I want to build a filtration system for my 3d printer, and that shit is so much more complicated than I thought it would be
  • Varine Varine:
    Apparently ABS emits styrene particulates which can be like .2 micrometers, which idk if the VOC detectors I have can even catch that
  • Varine Varine:
    Anyway I need to get some of those sensors and two air pressure sensors installed before an after the filters, which I need to figure out how to calculate the necessary pressure for and I have yet to find anything that tells me how to actually do that, just the cfm ratings
  • Varine Varine:
    And then I have to set up an arduino board to read those sensors, which I also don't know very much about but I have a whole bunch of crash course things for that
  • Varine Varine:
    These sensors are also a lot more than I thought they would be. Like 5 to 10 each, idk why but I assumed they would be like 2 dollars
  • Varine Varine:
    Another issue I'm learning is that a lot of the air quality sensors don't work at very high ambient temperatures. I'm planning on heating this enclosure to like 60C or so, and that's the upper limit of their functionality
  • Varine Varine:
    Although I don't know if I need to actually actively heat it or just let the plate and hotend bring the ambient temp to whatever it will, but even then I need to figure out an exfiltration for hot air. I think I kind of know what to do but it's still fucking confusing
  • The Helper The Helper:
    Maybe you could find some of that information from AC tech - like how they detect freon and such
  • Varine Varine:
    That's mostly what I've been looking at
  • Varine Varine:
    I don't think I'm dealing with quite the same pressures though, at the very least its a significantly smaller system. For the time being I'm just going to put together a quick scrubby box though and hope it works good enough to not make my house toxic
  • Varine Varine:
    I mean I don't use this enough to pose any significant danger I don't think, but I would still rather not be throwing styrene all over the air
  • The Helper The Helper:
    New dessert added to recipes Southern Pecan Praline Cake https://www.thehelper.net/threads/recipe-southern-pecan-praline-cake.193555/
  • The Helper The Helper:
    Another bot invasion 493 members online most of them bots that do not show up on stats
  • Varine Varine:
    I'm looking at a solid 378 guests, but 3 members. Of which two are me and VSNES. The third is unlisted, which makes me think its a ghost.
    +1
  • The Helper The Helper:
    Some members choose invisibility mode
    +1
  • The Helper The Helper:
    I bitch about Xenforo sometimes but it really is full featured you just have to really know what you are doing to get the most out of it.
  • The Helper The Helper:
    It is just not easy to fix styles and customize but it definitely can be done
  • The Helper The Helper:
    I do know this - xenforo dropped the ball by not keeping the vbulletin reputation comments as a feature. The loss of the Reputation comments data when we switched to Xenforo really was the death knell for the site when it came to all the users that left. I know I missed it so much and I got way less interested in the site when that feature was gone and I run the site.
  • Blackveiled Blackveiled:
    People love rep, lol
    +1
  • The Helper The Helper:
    The recipe today is Sloppy Joe Casserole - one of my faves LOL https://www.thehelper.net/threads/sloppy-joe-casserole-with-manwich.193585/
  • The Helper The Helper:
    Decided to put up a healthier type recipe to mix it up - Honey Garlic Shrimp Stir-Fry https://www.thehelper.net/threads/recipe-honey-garlic-shrimp-stir-fry.193595/

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top