Help with function im noob

Bogomil16

New Member
Reaction score
1
Ok im making a spell that a unit called Spore Beast does something like spore nova-spawns 8 spores and they travel in 8 directions.I havent made the damage yet,but ill make it later.The problem is my function is giving me error:

JASS:

function SporeBurstAbi takes unit caster returns nothing
local location temp_point = GetUnitLoc(caster)
local location temp_point2 = null
local integer i = 0
local group spores = null
local real degrees = 0.0
loop
exitwhen( i == 8 )
call CreateUnitAtLoc( Player( GetUnitCurrentOrder ( caster ) ),'sbdu',temp_point,260.0)
call GroupAddUnit( spores,GetLastCreatedUnit( ) )
call SetUnitFacingTimed( GetLastCreatedUnit( ),degrees,0 )
set degrees = degrees + 45.0
set i = i + 1
endloop
set i = 0
loop
exitwhen(i == 100)
call ForGroup( spores,function SporeBurstAbi )
set temp_point = GetUnitLoc(GetEnumUnit())
set temp_point2 = PolarProjectionBJ( temp_point,5.0,GetUnitFacing( GetEnumUnit( ) ) )
call SetUnitPositionLoc( GetEnumUnit(),temp_point2 )
set i = i+1
set temp_point = null
set temp_point2 = null
endloop
set spores = null
endfunction


The error is at
JASS:
 call ForGroup( spores,function SporeBurstAbi )
.Im basicly trying to do: Pick units in the unit group spores,but i started doing jass 1 day ago and im still having trouble figuring out how things are done.Thanks in advance.
 

Nexor

...
Reaction score
74
use the
JASS:
 tags when writing in JASS to the forum.

you forgot to increase the variable <i> in the second loop</i>
 

Bogomil16

New Member
Reaction score
1
use the
JASS:
 tags when writing in JASS to the forum.

you forgot to increase the variable <i> in the second loop</i>
JASS:
<i>

ok i fixed it,but still the problem is in the ForGroup() thing.I think im not using the function properly <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite5" alt=":confused:" title="Confused    :confused:" loading="lazy" data-shortname=":confused:" /></i>
 

Nexor

...
Reaction score
74
Lol, ForGroup() needs another function above this function, you are calling the same function again and again, what are you trying to do with this function?

create some units and move them in a circle outwards?
 

Bogomil16

New Member
Reaction score
1
Yes

yes,exacly :D seems i didnt know how exacly to use ForGroup() .So basicly i put another function up that just moves the units outward like MoveUnit() and then i call Forgroup(spores,function MoveUnit).Hope this works.
 

Nexor

...
Reaction score
74
I can make it for you if ya want.

You will be able to change circa everything in the spell.

Just one question, will this be the effect of some ability? and will it create the units around the unit casting it or at a point?
 

Bogomil16

New Member
Reaction score
1
Thanks

Thanks,but i wanna make it,so i can get more experienced in jass.Its the effect of an ability of a unit im gonna use in my map.Its from a race of bug/lizard alien things and this is the Spore Beast that carries spores.
 
Reaction score
456
Learn to indent your code so people can actually read it:
JASS:
function SporeBurstAbi takes unit caster returns nothing
    local location temp_point = GetUnitLoc(caster)
    local location temp_point2 = null
    local integer i = 0
    local group spores = null
    local real degrees = 0.0
    loop
        exitwhen( i == 8 )
        call CreateUnitAtLoc( Player( GetUnitCurrentOrder ( caster ) ),&#039;sbdu&#039;,temp_point,260.0)
        call GroupAddUnit( spores,GetLastCreatedUnit( ) )
        call SetUnitFacingTimed( GetLastCreatedUnit( ),degrees,0 )
        set degrees = degrees + 45.0
        set i = i + 1
    endloop
    set i = 0
    loop
        exitwhen(i == 100)
        call ForGroup( spores,function SporeBurstAbi )
        set temp_point = GetUnitLoc(GetEnumUnit())
        set temp_point2 = PolarProjectionBJ( temp_point,5.0,GetUnitFacing( GetEnumUnit( ) ) )
        call SetUnitPositionLoc( GetEnumUnit(),temp_point2 )
        set i = i+1
        set temp_point = null
        set temp_point2 = null
    endloop
    set spores = null
endfunction


The three main problems of this code are:
- It does not work.
- It leaks.
- It looks too much of a converted GUI​


Now to make the code work. You have to create the group. Adding units to a null group, and then enumerating it is not that clever. So:
Code:
local group spores = [B]CreateGroup()[/B]


Code:
call CreateUnitAtLoc( Player( [B]GetUnitCurrentOrder ( caster )[/B] ),'sbdu',temp_point,260.0)
Explain this? GetUnitCurrentOrder? I'd probably change that to GetOwningPlayer(caster), and you should too.


There's two ways you can pick the units in the group and do actions to/with them. First is the ForGroup method, the second is a looping method.

1. ForGroup:
JASS:
function EnumFunction takes nothing returns nothing
    call ExplodeUnitBJ(GetEnumUnit()) //Do actions with picked units
endfunction

function ActionFunction takes nothing returns nothing
    local unit caster = GetTriggerUnit()
    local unit target = GetSpellTargetUnit()
    local group g = CreateGroup()
    
    call GroupAddUnit(g, caster)
    call GroupAddUnit(g, target)
    call ForGroup(g, function EnumFunction)
    
    set caster = null
    set target = null
    call DestroyGroup(g)
    set g = null
endfunction

You "need" another function for enumerating the units. However, you're not able to use the local variables from ActionFunction in EnumFunction. You'd have to pass them in some way.

2. Looping:
JASS:
function ActionFunction takes nothing returns nothing
    local unit caster = GetTriggerUnit()
    local unit target = GetSpellTargetUnit()
    local group g = CreateGroup()
    local unit f //This variable is used with looping
    
    call GroupAddUnit(g, caster)
    call GroupAddUnit(g, target)

    loop
        set f = FirstOfGroup(g) //Pick unit from the group
        exitwhen f == null //Exit the loop when group is empty
        call GroupRemoveUnit(g, f) //Remove the unit from the group so we don&#039;t cause infinite loop
        call ExplodeUnitBJ(f) //Do actions with picked unit
    endloop
    
    set caster = null
    set target = null
    call DestroyGroup(g)
    set g = null
endfunction

The advantages of this method is that you can freely use the local variables of ActionFunction.


I'm not quite sure what you're going to do with the group.. so I'll leave that part open. So next up is the leak removal:
JASS:
function SporeBurstAbi takes unit caster returns nothing
    local location temp_point = GetUnitLoc(caster)
    local location temp_point2 = null
    local integer i = 0
    local group spores = null
    local real degrees = 0.0
    loop
        exitwhen( i == 8 )
        call CreateUnitAtLoc( Player( GetUnitCurrentOrder ( caster ) ),&#039;sbdu&#039;,temp_point,260.0)
        call GroupAddUnit( spores,GetLastCreatedUnit( ) )
        call SetUnitFacingTimed( GetLastCreatedUnit( ),degrees,0 )
        set degrees = degrees + 45.0
        set i = i + 1
    endloop
    call RemoveLocation(temp_point) //Remove it after use
    set i = 0
    loop
        exitwhen(i == 100)
        call ForGroup( spores,function SporeBurstAbi )
        set temp_point = GetUnitLoc(GetEnumUnit())
        set temp_point2 = PolarProjectionBJ( temp_point,5.0,GetUnitFacing( GetEnumUnit( ) ) )
        call SetUnitPositionLoc( GetEnumUnit(),temp_point2 )
        set i = i+1
        call RemoveLocation(temp_point) //Remove it after use
        call RemoveLocation(temp_point2) //Remove it after use
    endloop
    call DestroyGroup(spores) //Destroy the group too.
    set spores = null
    set temp_point = null //You don&#039;t have to null them all the time, just when you&#039;re completely done with them
    set temp_point2 = null //^
endfunction



And to make it look less converted GUI, inline some of the BJs that are coloured red in NewGen. Then you should learn to use coordinates instead of locations.
 

Bogomil16

New Member
Reaction score
1
10x

I see i've made some silly mistakes.Jass is kinda strange to me,cuz im used to C++,so it takes me some time to get the hang of it.
 

Bogomil16

New Member
Reaction score
1
This is what i did

JASS:

function MoveSpores takes nothing returns nothing
local location temp_point = null
local location temp_point2 = null
local integer i = 0
loop
exitwhen( i == 100 )
set temp_point = GetUnitLoc( GetEnumUnit( ) )
set temp_point2 = PolarProjectionBJ( temp_point,5.00,GetUnitFacing( GetEnumUnit( ) ) )
set i = i + 1
call SetUnitPositionLoc( GetEnumUnit( ),temp_point2 )
call TriggerSleepAction( 0.10 )
call RemoveLocation(temp_point)
call RemoveLocation(temp_point2)
endloop
endfunction

function SporeBurstAbi takes unit caster returns nothing
local location temp_point = GetUnitLoc(caster)
local location temp_point2 = null
local integer i = 0
local group spores = CreateGroup()
local real degrees = 0.00
loop
exitwhen( i == 8 )
call CreateUnitAtLoc(GetOwningPlayer(caster),&#039;sbdu&#039;,temp_point,260.0)
call GroupAddUnit( spores,GetLastCreatedUnit( ) )
call SetUnitFacingTimed( GetLastCreatedUnit( ),degrees,0 )
set degrees = degrees + 45.00
set i = i + 1
endloop
call RemoveLocation(temp_point)
set i = 0
call ForGroup( spores,function MoveSpores )
call DestroyGroup(spores)
set spores = null
set temp_point = null
set temp_point2 = null
set spores = null
endfunction

function AbilityID_Check takes nothing returns boolean
    if ( not ( GetSpellAbilityId() == &#039;spba&#039; ) ) then
        return false
    endif
    return true
endfunction

function Trig_StartEffAbi_Actions takes nothing returns nothing
    if ( AbilityID_Check() == true ) then
    call SporeBurstAbi(GetTriggerUnit())
    else
    endif
endfunction

function InitTrig_StartEffAbi takes nothing returns nothing
    set gg_trg_StartEffAbi = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_StartEffAbi, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddAction( gg_trg_StartEffAbi, function Trig_StartEffAbi_Actions )
endfunction


Its supposed to send the spores in 8 directions like a Nova spell.Ill check out if it works.
 

Bogomil16

New Member
Reaction score
1
Still doesnt work

Am i missing something in the code above?It runs without errors,but when i use the ability the 8 spores are just created on the position of the unit and they dont move.
 

Strilanc

Veteran Scripter
Reaction score
42
Thanks,but i wanna make it,so i can get more experienced in jass.Its the effect of an ability of a unit im gonna use in my map.Its from a race of bug/lizard alien things and this is the Spore Beast that carries spores.

Right on.

... code ...

Couple issues you should fix:
- AbilityID_Check. Inline it! This function should disappear.
- SporeBurstAbi: degrees is redundant for i*45. No need to set i = 0 (local handles [eg. unit] only need to be nulled because of a reference-counting bug in wc3). Doesn't affect value types like int.
- temp_point2 unused
- GetUnitLoc/CreateUnitAtLoc can be replaced with GetUnitX/GetUnitY/CreateUnit. Gets rid of all that location cleanup cruft.
- Last argument of CreateUnit is facing angle, no need to do it afterwards with SetUnitFacing
- TriggerSleepAction is not accurate. It has to expire at the same time for all players, and the host includes the 'expire now' stuff in the sync packets (if I remember correctly). That means the wait time from TriggerSleepAction can be as high as 250ms! Not to mention each unit iteration will wait for the previous one to finish, so best case they go super slow one by one.
- To get around the wait issue, you will need a second trigger with a periodic event. These are implicitly synced, so they are very accurate. Make the spore group a global, add spores from the ability trigger, and move them from the periodic trigger. Give them a timed life, so you can stop moving them when they die.
 

Nexor

...
Reaction score
74
I know that you want it to make yourself, but I wanted to do something ( I have a little time before my exams) so I decided to make it for you.

It uses TimerTicker, everything is there what you need :)
just copy the 3 triggers to your map and change the raw codes and the other values in the Spore trigger in the global section.

View attachment Spore.w3x
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
Dont use location. Use X and Y instead. X and Y coordinate are faster than location and they do not need removed since they does not cause leak.
 
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