My Help me with Jass Thread

Joker(Div)

Always Here..
Reaction score
86
ok i was messing around with Jasscraft, and i was trying to make a simple jass trigger, but this keep coming up and idk what to do
Code:
function Trig_NewTrigger_Conditions takes nothing returns boolean
if ( IsUnitType(GetSpellAbilityUnit(), UNIT_TYPE_HERO ) == true ) then
    return true
endif
    return true
endfunction

function Trig_NewTrigger_Actions takes nothing returns nothing
  
endfunction

//==== Init Trigger NewTrigger ====
function InitTrig_NewTrigger takes nothing returns nothing
    set gg_trg_NewTrigger = CreateTrigger()
    call TriggerRegister (gg_trg_NewTrigger, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition(gg_trg_NewTrigger, Condition(function Trig_NewTrigger_Conditions))
    call TriggerAddAction(gg_trg_NewTrigger, function Trig_NewTrigger_Actions)
endfunction
Line 15: Undeclared variable: gg_NewTrigger
Line 15: Undeclared function TriggerRegister
 

SFilip

Gone but not forgotten
Reaction score
634
> Line 15: Undeclared variable: gg_NewTrigger
JassCraft can't detect trigger variables which are created automatically. just ignore this.

> Line 15: Undeclared function TriggerRegister
ummm you used TriggerRegister which doesn't exist as a function. you should probably use TriggerRegisterAnyUnitEventBJ instead.
 

SFilip

Gone but not forgotten
Reaction score
634
exactly. it simply adds the EVENT_PLAYER_UNIT_SPELL_EFFECT (starts the effect of an ability) for every player (thus the BJ - normal function would be unit owned by player event).
 

Chocobo

White-Flower
Reaction score
409
Joker(Div) said:
can someone explain how to use Unit Groups? like the loop actions

To use it : call ForGroup( group, functioncode callback)

Example

Code:
set bj_wantDestroyGroup = true
call ForGroup(GetUnitsOfTypeIdAll('Hpal'),function Indicator)

function Indicator takes nothing returns nothing
call AddIndicator( GetEnumUnit(), 100, 0, 0, 0)
 

SFilip

Gone but not forgotten
Reaction score
634
alternate solution (most likely better since it allows you to put a wait)

Code:
    local group g = GetUnitsOfTypeIdAll('Hpal')
    local unit u
    loop
        set u = FirstOfGroup(g)
        exitwhen u == null
        call GroupRemoveUnit(g, u)
        <do something with u here>
    endloop
    call DestroyGroup(g)

and btw chocobo...bj_wantDestroyGroup only works with ForGroupBJ.
 

Joker(Div)

Always Here..
Reaction score
86
my WE has gone wierd. The gui is being checked like a jass and its coming up with a whole bunch of messed up jass, which WE made itself. What is wrong with it?
 

SFilip

Gone but not forgotten
Reaction score
634
compile error i guess...any screenshots?
 

Joker(Div)

Always Here..
Reaction score
86
Ok
25170Untitled-1.png





also,
Code:
function Trig_Hero_Dies_Conditions takes nothing returns boolean
    if ( not ( IsUnitType(GetDyingUnit(), UNIT_TYPE_HERO) == true ) ) then
        return false
    endif
    if ( not ( IsUnitType(GetKillingUnitBJ(), UNIT_TYPE_HERO) == true ) ) then
        return false
    endif
    return true
endfunction

function Trig_Hero_Dies_Actions takes nothing returns nothing
    local string array base
    local string base[1] = ( "|c00ff0000" + ( GetPlayerName(Player(0)) + "|r" ) )
    local string base[2] = ( "|c000000ff" + ( GetPlayerName(Player(1)) + "|r" ) )
    local string base[3] = ( "|c0000ffff" + ( GetPlayerName(Player(2)) + "|r" ) )
    local string base[4] = ( "|c00800080" + ( GetPlayerName(Player(3)) + "|r" ) )
    local string base[5] = ( "|c00ffff00" + ( GetPlayerName(Player(4)) + "|r" ) )
    local string base[6] = ( "|c00ff8000" + ( GetPlayerName(Player(5)) + "|r" ) )
    call DisplayTextToForce( GetPlayersAll(), ( base[GetConvertedPlayerId(GetOwningPlayer(GetDyingUnit()))] + ( " has been pwned by " + base[GetConvertedPlayerId(GetOwningPlayer(GetKillingUnitBJ()))] + " and stole 100 gold! " ) ) )
    call AdjustPlayerStateBJ( 100, GetOwningPlayer(GetKillingUnitBJ()), PLAYER_STATE_RESOURCE_GOLD )
    call AdjustPlayerStateBJ( -100, GetOwningPlayer(GetDyingUnit()), PLAYER_STATE_RESOURCE_GOLD )
endfunction
//===========================================================================
function InitTrig_Hero_Dies takes nothing returns nothing
    set gg_trg_Hero_Dies = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Hero_Dies, EVENT_PLAYER_UNIT_DEATH )
    call TriggerAddCondition( gg_trg_Hero_Dies, Condition( function Trig_Hero_Dies_Conditions ) )
    call TriggerAddAction( gg_trg_Hero_Dies, function Trig_Hero_Dies_Actions )
endfunction
thats got serveral errors idk how to fix :( and i didnt null the string b/c idk how
 

emjlr3

Change can be a good thing
Reaction score
395
the only thing wrong with that, other then the obvious un optimization, is that, u declare each of your string variables

local string array s, is all the declaration you need

after that

its just

set s[1] =
set s[2] =

etc.
 

emjlr3

Change can be a good thing
Reaction score
395
i suggest, if you have not already, to read Daelin's JASS tut that explains about optimizing functions

for ex.

Code:
function Trig_Hero_Dies_Conditions takes nothing returns boolean
    if ( not ( IsUnitType(GetDyingUnit(), UNIT_TYPE_HERO) == true ) ) then
        return false
    endif
    if ( not ( IsUnitType(GetKillingUnitBJ(), UNIT_TYPE_HERO) == true ) ) then
        return false
    endif
    return true
endfunctio

could be
Code:
function Trig_Hero_Dies_Conditions takes nothing returns boolean
    return IsUnitType(GetDyingUnit(), UNIT_TYPE_HERO) == true and IsUnitType(GetKillingUnit(), UNIT_TYPE_HERO) == true 
endfunction

i removed you bj killing unit function, and made it smaller in general, and faster

other then that

bj functions are worthless(ex. , AdjustPlayerStateBJ )

search JASS Craft for the bj function, and it shows you the natives it is made up of
 
D

dadads

Guest
If World Editor says "expected a name" for a function declaration, then it could mean you've got a double function declaration

i.e. Check if you got the "Trig_Instant_Repair_Conditions" function declared twice.

Code:
local string base[1] = ( "|c00ff0000" + ( GetPlayerName(Player(0)) + "|r" ) )
    local string base[2] = ( "|c000000ff" + ( GetPlayerName(Player(1)) + "|r" ) )
    local string base[3] = ( "|c0000ffff" + ( GetPlayerName(Player(2)) + "|r" ) )
    local string base[4] = ( "|c00800080" + ( GetPlayerName(Player(3)) + "|r" ) )
    local string base[5] = ( "|c00ffff00" + ( GetPlayerName(Player(4)) + "|r" ) )
    local string base[6] = ( "|c00ff8000" + ( GetPlayerName(Player(5)) + "|r" ) )
I suggest that this block of code should not be used.
Instead, you can make a function which changes the names of all players to a colored one, and then you could simply use GetPlayerName
That way, you would simplify most of the functions which will require showing colored player names and there would be no more local string initializations (as shown above) at each function you would use.
Here's a function which replaces all player names to colored ones
Code:
//Sets initial player names
function init_playerNames takes nothing returns nothing
    local string array colors
    local integer a = 0
    local player p
    set colors[0] = "|c00ff0000"
    set colors[1] = "|c000000ff"
    set colors[2] = "|c0018e7bd"
    set colors[3] = "|c00520084"
    set colors[4] = "|c00ffff00"
    set colors[5] = "|c00ff8a08"
    set colors[6] = "|c0018be00"
    set colors[7] = "|c00e759ad"
    set colors[8] = "|c00949694"
    set colors[9] = "|c007bbef7"
    set colors[10] = "|c00086142"
    set colors[11] = "|c004a2800"
    loop
        exitwhen a > 11
        set p = Player(a)
        call SetPlayerName(p,colors[a] + GetPlayerName(Player(a)) + "|r")
        set colors[a] = null
        set p = null
        set a = a + 1
    endloop
endfunction

Anyways
I've tried to fix that code, here's the result (with local variable nulling included):
Code:
function Trig_Hero_Dies_Conditions takes nothing returns boolean
    return IsUnitType(GetDyingUnit(), UNIT_TYPE_HERO) and IsUnitType(GetKillingUnit(), UNIT_TYPE_HERO)
endfunction

function Trig_Hero_Dies_Actions takes nothing returns nothing
    local string array base
    local unit u = GetKillingUnit()
    local player p = GetOwningPlayer(u)
    local integer i = GetPlayerId(p)
    local integer j
    set base[0] = ("|c00ff0000"+(GetPlayerName(Player(0))+"|r"))
    set base[1] = ("|c000000ff"+(GetPlayerName(Player(1))+"|r"))
    set base[2] = ("|c0000ffff"+(GetPlayerName(Player(2))+"|r"))
    set base[3] = ("|c00800080"+(GetPlayerName(Player(3))+"|r"))
    set base[4] = ("|c00ffff00"+(GetPlayerName(Player(4))+"|r"))
    set base[5] = ("|c00ff8000"+(GetPlayerName(Player(5))+"|r"))
    set u = GetDyingUnit()
    set p = GetOwningPlayer(u)
    set j = GetPlayerId(p)
    call DisplayTextToForce(bj_FORCE_ALL_PLAYERS,base[i] + " has just pwned " + base[j] + " and stole 100 gold! ")
    call AdjustPlayerStateBJ(-100,p,PLAYER_STATE_RESOURCE_GOLD)
    set u = GetKillingUnit()
    set p = GetOwningPlayer(u)
    call AdjustPlayerStateBJ(100,p,PLAYER_STATE_RESOURCE_GOLD)
    set u = null
    set p = null
    set base[0] = null
    set base[1] = null
    set base[2] = null
    set base[3] = null
    set base[4] = null
    set base[5] = null
endfunction
//===========================================================================
function InitTrig_Hero_Dies takes nothing returns nothing
    set gg_trg_Hero_Dies = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(gg_trg_Hero_Dies,EVENT_PLAYER_UNIT_DEATH)
    call TriggerAddCondition(gg_trg_Hero_Dies,Condition(function Trig_Hero_Dies_Conditions ))
    call TriggerAddAction(gg_trg_Hero_Dies,function Trig_Hero_Dies_Actions)
endfunction
Probably your error was in lines declaring variables such as "local string base[0] = ("|c00ff0000"+(GetPlayerName(Player(0))+"|r"))" when the same variable has already been declared previously in "local string array base"

I've tried it in a test map of mine, and it works (World Editor does not give me those errors). If WE still gives you errors, then it is not because of this code.
 

emjlr3

Change can be a good thing
Reaction score
395
Joker(Div) said:
can someone tell me how to null arrays and why my map has over 2000 errors (scroll up) ?

say you got an array

local location array l

to null one of them

just

set l[#] = null

simple
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top