Vjass Code Problems (Simple)

Squll2

je'ne sais pas
Reaction score
76
Hey everyone. Begginner Vjasser here, with a very simple code that is playing up on me.

Would anyone care to explain to me why those code does not work at all :( and tell me how I can improve it, and make it faster... cleaner as such?

Thanks in advance!! :)

The simple aim of the spell, currently, is to create lightning from enemy units around the target point to the caster.

Also, with my GroupEnumUnitsInRange, how do I filter it through a condition? :nuts:

JASS:
scope CounterEnergy initializer Init

//Changeable / Alterable functions

private function ID takes nothing returns integer
  return 'A000'
endfunction

private function Unit_ID takes nothing returns integer
  return 'h000'
endfunction

private function Boo takes nothing returns boolexpr
   return null
endfunction

private function Radius takes nothing returns real
   return 350.00
endfunction

//Changeable / Alterable functions End.

private function Cons takes nothing returns boolean
   return GetSpellAbilityId() == ID
endfunction

private function Actions takes nothing returns nothing
//Local Setting
 local unit u     = GetTriggerUnit()
 local unit e
 local unit d
 local group g               = CreateGroup()
 local group g2              = CreateGroup()
 local player p              = GetOwningPlayer(u)
 local integer a             = 0
 local integer b             = 0
 local location l            = GetSpellTargetLoc()
 local lightning array Light
 local real x                = GetLocationX(l)
 local real y                = GetLocationY(l)
 local real X
 local real Y
//Local Setting

 call GroupEnumUnitsInRange(g, x, y, 500.00, null)
 call GroupAddGroup(g, g2)
 
loop

 set e = FirstOfGroup(g2)
 exitwhen e == null
 set X = GetUnitX(e)
 set Y = GetUnitY(e)
 
 set Light[a] = AddLightning( "CLPB", true, X, Y, x, y)
 
 set a = a+1
 call GroupRemoveUnit(g2, e)
 
endloop

 call PolledWait(2.00)
 
loop

 exitwhen a < 0
 
 call DestroyLightning(Light[a])
 
 set a = a-1
 
endloop
 
endfunction

//===========================================================================
private function Init takes nothing returns nothing
    local trigger trig = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( trig, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( trig, Condition( function Cons ) )
    call TriggerAddAction( trig, function Actions )
endfunction

endscope
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
1) remove your leak.
2)
JASS:
private function ID takes nothing returns integer
  return 'A000'
endfunction

You can make it as constant globals, since variable is faster than calling a function.
3) Create a function like
JASS:
private function Cons takes nothing returns boolean
   return GetSpellAbilityId() == ID
endfunction

to filter units.
 

Exide

I am amazingly focused right now!
Reaction score
448
Your trigger is quite difficult to read. You should indent it.

Why are these functions?
JASS:

private function ID takes nothing returns integer
  return 'A000'
endfunction

private function Unit_ID takes nothing returns integer
  return 'h000'
endfunction

private function Boo takes nothing returns boolexpr
   return null
endfunction

private function Radius takes nothing returns real
   return 350.00
endfunction



Why are you using two groups?
Remove g2, and use g only.

EDIT: g should be a private global variable.
If you do this, you don't need to 'call DestroyGroup(g)'


JASS:
call GroupEnumUnitsInRange(g, x, y, 500.00, null)

instead of 'null', add a function:

JASS:

function A takes nothing returns boolean
    //return Some Condition Here
endfunction


    //Lots of actions and whatnot..

    call GroupEnumUnitsInRange(g, x, y, 500.00, Filter(function A))
 

Squll2

je'ne sais pas
Reaction score
76
I was told that GroupAddGroup() and using two groups is a better method then just using one group?

Those functions are there, exide, for easy customastion, so I can add them down below and instead of searching for them I will just change their values there, but in this version of the trigger I havn't used them ><

Thanks for the help exide +rep, kingking, when your talking to a noob, please evaluate what you mean.. I know what i have to do I just don't know where to put it and how.. >.>

Edit: Exide what do you mean Why are these functions? Should they be something else?
 

Exide

I am amazingly focused right now!
Reaction score
448
Yea, they should be variables.
Calling a function is unnecessary work.
Using private globals you can declare them at the top of your trigger, so it's equally easy to modify the values.

>I was told that GroupAddGroup() and using two groups is a better method then just using one group?
I never heard anything about that. It sounds silly, though.
Check out this thread: http://www.thehelper.net/forums/showthread.php?t=131720
 

Zaraf

New Member
Reaction score
22
For your purposes, you actually don't even need a group.

I've modified your code to show you what I mean

JASS:
scope CounterEnergy initializer Init
        
        globals
            private constant integer ID      = &#039;A000&#039;
            private constant integer Unit_ID = &#039;h000&#039;
            private constant real    Radius  = 350.0
            
            private real Xfilter
            private real Yfilter
            
            private boolexpr LightActions
            private lightning array Light
            
            group ENUM_GROUP = CreateGroup()
        endglobals

private function Cons takes nothing returns boolean
   return GetSpellAbilityId() == ID
endfunction

private function LightActionsAdded takes nothing returns boolean
    local unit f = GetFilterUnit()
    local real x = Xfilter
    local real y = Yfilter
    
    set Light[a] = AddLightning( &quot;CLPB&quot;, true, GetUnitX(f), GetUnitY(f), x, y)

    return false
endfunction

private function DestroyLight takes nothing returns nothing
    local integer a = 0
    
    loop
        exitwhen DestroyLightning(Light[a]) == null
        call DestroyLightning(Light[a])
        set Light[a] = null
        set a = a+1
    endloop
    
    call DestroyTimer(GetExpiredTimer())
endfunction

private function Actions takes nothing returns nothing
    //Local Setting
    local unit u                = GetTriggerUnit()
    local player p              = GetOwningPlayer(u)
    local location l            = GetSpellTargetLoc()
    local real x                = GetLocationX(l)
    local real y                = GetLocationY(l)
    local timer t               = CreateTimer()
    //Local Setting
    
    set Xfilter = x
    set Yfilter = y
    call GroupEnumUnitsInRange(ENUM_GROUP, x, y, 500.00, LightActions)

    call TimerStart(t, 2.00, false, function DestroyLight)

    call RemoveLocation(l)
    set t = null
    set l = null
    set u = null
endfunction

//===========================================================================
private function Init takes nothing returns nothing
    local trigger trig = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(trig, EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition(trig, Condition( function Cons))
    call TriggerAddAction(trig, function Actions)
    
    set LightActions = Condition(function LightActionsAdded)
endfunction

endscope


Basically, you can perform your actions in the filter function.

The code turned out to be a bit messy since I was trying to avoid using a struct. If you use a struct, then this works flawlessly. But as it is right now, it's not MUI, and there are other problems. But this is more to illustrate to you how you can completely avoid the group altogether, and make your code run faster and better.

I've explained this no group concept in more detail here:

http://www.thehelper.net/forums/showpost.php?p=1076839&postcount=3

I encourage you to learn this technique, and if you'd like, I can speak with you further on it to better explain, and show you how to rewrite your spell using structs to improve it.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Monovertex Monovertex:
    How are you all? :D
    +1
  • Ghan Ghan:
    Howdy
  • 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

      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