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.
  • 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
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    New recipe is another summer dessert Berry and Peach Cheesecake - https://www.thehelper.net/threads/recipe-berry-and-peach-cheesecake.194169/

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top