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.
  • 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