• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Unit Type Id : Integer or Unit Type Variable?

Status
Not open for further replies.
Level 4
Joined
Aug 18, 2013
Messages
71
Hey guys, I've been searching around for this a long time and no one ever can seem to explain it to me.
When Using Jass, Do I use the unit-type variable type or integer when using functions such as spawn unit. I'm always forced to manually type unit types (Ex: 'f000') into the function because putting either variable type into that parameter never works. Integers don't work, unit-type doesn't work. And it honestly annoys the fuck out of me.

My code currently wont display anything.
JASS:
function Trig_List_Unit_Types_Actions takes nothing returns nothing
    local integer i = 0
    local integer max = 5
    //start human
    set i = 0
    loop
    call DisplayTextToPlayer(Player(0),0,0,UnitId2String(udg_HumanCards[i]))
        exitwhen i == max
    set i=i+1 
    endloop 
    //star orc 
    set i = 0
    loop
    call DisplayTextToPlayer(Player(0),0,0,UnitId2String(udg_OrcCards[i]))
        exitwhen i == max
    set i=i+1 
    endloop
    //start night elf   
    set i = 0
    loop
    call DisplayTextToPlayer(Player(0),0,0,UnitId2String(udg_UndeadCards[i]))
        exitwhen i == max
    set i=i+1 
    endloop
    //start undead   
    set i = 0
    loop
    call DisplayTextToPlayer(Player(0),0,0,UnitId2String(udg_NightElfCards[i]))
        exitwhen i == max
    set i=i+1 
    endloop
endfunction

//===========================================================================
function InitTrig_List_Unit_Types takes nothing returns nothing
    local trigger t = CreateTrigger(  )
    call TriggerRegisterPlayerChatEvent( t, Player(0), "-unittypes", true )
    call TriggerAddAction( t, function Trig_List_Unit_Types_Actions )
    set t= null
endfunction

I have no idea...
 
It shouldn't really matter as both are used the same. I always use integers though.
Not sure why they made a separate GUI variable for that since they are all integers.

So you can browse units when setting the variable.

Hey guys, I've been searching around for this a long time and no one ever can seem to explain it to me.
When Using Jass, Do I use the unit-type variable type or integer when using functions such as spawn unit. I'm always forced to manually type unit types (Ex: 'f000') into the function because putting either variable type into that parameter never works. Integers don't work, unit-type doesn't work. And it honestly annoys the fuck out of me.

My code currently wont display anything.
I have no idea...

You should be using integer in JASS, the unit-type variable is just a pseudo type.

I would useGetObjectNameinstead ofUnitId2String
 
Level 4
Joined
Aug 18, 2013
Messages
71
I'm using globals because it was easier to seperate what i had into 2 triggers. I'm combining them and making everything local

Like so
JASS:
function Trig_GameDrawCardRed_Conditions takes nothing returns boolean
    return( ((GetTriggerUnit() == gg_unit_n00C_0053)or(GetTriggerUnit() == gg_unit_n00C_0020) ) and( GetPlayerState(GetTriggerPlayer(), PLAYER_STATE_RESOURCE_LUMBER) > 0 )) 
endfunction

function Trig_GameDrawCardRed_Actions takes nothing returns nothing
    local player p = GetTriggerPlayer()
    local integer max = 5
    local real x = 900
    local real y = -900
    local integer rand = GetRandomInt(0,max) 
    //unittypes
    local array integer HumanCards
    local array integer OrcCards
    local array integer NightElfCards
    local array integer UndeadCards
    //----
    set HumanCards[0] = 'h000'//footman
    set HumanCards[1] = 'h001'//elven footman
    set HumanCards[2] = 'h00A'//captain
    set HumanCards[3] = 'h00K'//archer
    set HumanCards[4] = 'h00L'//dwarf rifleman
    set HumanCards[5] = 'h00O'//enforcer
    set HumanCards[6] = 'h00P'//spear master
    
    //orc cards
    set OrcCards[0] = 'h002'//grunt
    set OrcCards[1] = 'h007'//headhunter
    set OrcCards[2] = 'h00l'//troll axe thrower
    set OrcCards[3] = 'h00J'//troll beserker
    set OrcCards[4] = 'h00M'//raider
    set OrcCards[5] = 'h00N'//1headogre
    
    //night elf cards
    set NightElfCards[0] = 'h00B'//archer
    set NightElfCards[1] = 'h00C'//warrior
    set NightElfCards[2] = 'h00D'//huntress
    set NightElfCards[3] = 'h00R'//brawler
    set NightElfCards[4] = 'h00S'//dryad
    set NightElfCards[5] = 'h00T'//treant
    
    //undead cards
    set UndeadCards[0] = 'h003'//Skeleton Soldier
    set UndeadCards[1] = 'h005'//zombie
    set UndeadCards[2] = 'h006'//ghoul
    set UndeadCards[3] = 'h004'//skeleton grunt
    set UndeadCards[4] = 'h005'//zombie Knight
    set UndeadCards[5] = 'h00Q'//Ghost
    //endunittypes
    
    //adjust x and y
    if(p == Player(1)) then
        set y = 210
    endif
    
    call TriggerExecute( gg_trg_GameDeckInit )
    call AdjustPlayerStateBJ( -1, p, PLAYER_STATE_RESOURCE_LUMBER )
    if ( GetPlayerRace(p) == RACE_HUMAN ) then
        call CreateUnit(p,HumanCards[rand],x,y,0 )
    endif
    if ( GetPlayerRace(p) == RACE_ORC ) then
        call CreateUnit(p,OrcCards[rand],x,y,0 )
    endif
    if ( GetPlayerRace(p) == RACE_NIGHTELF ) then
        call CreateUnit(p,NightElfCards[rand],x,y,0 )
    endif
    if ( GetPlayerRace(p) == RACE_UNDEAD ) then
        call CreateUnit(p,UndeadCards[rand],x,y,0 )
    endif
    
    call DisplayTextToPlayer( p,0,0,"You've drawn a " + UnitId2StringBJ(GetUnitTypeId(GetLastCreatedUnit())) )
endfunction

//===========================================================================
function InitTrig_GameDrawCardRed takes nothing returns nothing
    local trigger t = CreateTrigger(  )
    call TriggerRegisterPlayerSelectionEventBJ( t, Player(0), true )
    call TriggerAddCondition( t, Condition( function Trig_GameDrawCardRed_Conditions ) )
    call TriggerAddAction( t, function Trig_GameDrawCardRed_Actions )  
    set t = null
endfunction
 
Last edited:
Level 4
Joined
Aug 18, 2013
Messages
71
so I'm fighting my way through this trigger, everytime i solve a problem i create another -_-

so here's my code now

JASS:
function Trig_GameDrawCardRed_OrCondition takes nothing returns nothing
    if(GetTriggerUnit() == gg_unit_n00C_0053) then
        return true 
    else
        if(GetTriggerUnit() == gg_unit_n00C_0020) then
            return true
        endif
    endif
    return false
endfunction

function Trig_GameDrawCardRed_Conditions takes nothing returns boolean
    return( (Trig_GameDrawCardRed_OrCondition == true) and ( GetPlayerState(GetTriggerPlayer(), PLAYER_STATE_RESOURCE_LUMBER) > 0 )) 
endfunction

function Trig_GameDrawCardRed_Actions takes nothing returns nothing
    local player p = GetTriggerPlayer()
    local integer max = 5
    local real x = 900
    local real y = -900
    local integer rand = GetRandomInt(0,max) 
    //unittypes
    local integer array HumanCards
    local integer array OrcCards
    local integer array NightElfCards
    local integer array UndeadCards
    //----
    set HumanCards[0] = 'h000'//footman
    set HumanCards[1] = 'h001'//elven footman
    set HumanCards[2] = 'h00A'//captain
    set HumanCards[3] = 'h00K'//archer
    set HumanCards[4] = 'h00L'//dwarf rifleman
    set HumanCards[5] = 'h00O'//enforcer
    set HumanCards[6] = 'h00P'//spear master
    
    //orc cards
    set OrcCards[0] = 'h002'//grunt
    set OrcCards[1] = 'h007'//headhunter
    set OrcCards[2] = 'h00l'//troll axe thrower
    set OrcCards[3] = 'h00J'//troll beserker
    set OrcCards[4] = 'h00M'//raider
    set OrcCards[5] = 'h00N'//1headogre
    
    //night elf cards
    set NightElfCards[0] = 'h00B'//archer
    set NightElfCards[1] = 'h00C'//warrior
    set NightElfCards[2] = 'h00D'//huntress
    set NightElfCards[3] = 'h00R'//brawler
    set NightElfCards[4] = 'h00S'//dryad
    set NightElfCards[5] = 'h00T'//treant
    
    //undead cards
    set UndeadCards[0] = 'h003'//Skeleton Soldier
    set UndeadCards[1] = 'h005'//zombie
    set UndeadCards[2] = 'h006'//ghoul
    set UndeadCards[3] = 'h004'//skeleton grunt
    set UndeadCards[4] = 'h005'//zombie Knight
    set UndeadCards[5] = 'h00Q'//Ghost
    //endunittypes
    
    //adjust x and y
    if(p == Player(1)) then
        set y = 210
    endif
    
    call TriggerExecute( gg_trg_GameDeckInit )
    call AdjustPlayerStateBJ( -1, p, PLAYER_STATE_RESOURCE_LUMBER )
    if ( GetPlayerRace(p) == RACE_HUMAN ) then
        call CreateUnit(p,HumanCards[rand],x,y,0 )
    endif
    if ( GetPlayerRace(p) == RACE_ORC ) then
        call CreateUnit(p,OrcCards[rand],x,y,0 )
    endif
    if ( GetPlayerRace(p) == RACE_NIGHTELF ) then
        call CreateUnit(p,NightElfCards[rand],x,y,0 )
    endif
    if ( GetPlayerRace(p) == RACE_UNDEAD ) then
        call CreateUnit(p,UndeadCards[rand],x,y,0 )
    endif
    
    call DisplayTextToPlayer( p,0,0,"You've drawn a " + UnitId2StringBJ(GetUnitTypeId(GetLastCreatedUnit())) )
endfunction

//===========================================================================
function InitTrig_GameDrawCardRed takes nothing returns nothing
    local trigger t = CreateTrigger(  )
    call TriggerRegisterPlayerSelectionEventBJ( t, Player(0), true )
    call TriggerAddCondition( t, Condition( function Trig_GameDrawCardRed_Conditions ) )
    call TriggerAddAction( t, function Trig_GameDrawCardRed_Actions )  
    set t = null
endfunction

and my error says
Error: Unexpected return
its referring to
JASS:
if(GetTriggerUnit() == gg_unit_n00C_0053) then
        return true
whats the deal? i code in java and c++. i see no flaw here...

EDIT: The function should return a boolean shouldn't it haha

BUT IM STILL NOT ALLOWED TO HAVE NICE THINGS
ERROR REPORT:

AQQXsxF.png


Adiktuz: BEAT YOU TO IT :p
 
Level 4
Joined
Aug 18, 2013
Messages
71
Adiktuz: I already had changed that. but i still had other problems. wc3 editor apparently hadn't indexed the unit i selected. weird shit. i fixed it... somehow but this new problem is a doozie.

So I save right, get an error:

FYGIbCW.png


So i was like, Aight let me go find this code and see whats up
Fucking Que Heart Attack
JASS:
function Trig_GameDrawCardRed_OrCondition takes nothing returns boolean
    if((GetTriggerUnit() == gg_unit_n00C_0053)or(GetTriggerUnit() == gg_unit_n00C_0020)) then
        return true 
    //else
    //   if(GetTriggerUnit() == gg_unit_n00C_0020) then
    //        return true
    //   endif
    else
        return false
    endif
endfunction

function Trig_GameDrawCardRed_Conditions takes nothing returns boolean
    return( (Trig_GameDrawCardRed_OrCondition == true) and ( GetPlayerState(GetTriggerPlayer(), PLAYER_STATE_RESOURCE_LUMBER) > 0 )) 
endfunction

This does not equal the code displayed in the error.... what do?
CAUSE THIS IS SOME BULLSHIT RIGHT HERRR
 
return( (Trig_GameDrawCardRed_OrCondition == true) and ( GetPlayerState(GetTriggerPlayer(), PLAYER_STATE_RESOURCE_LUMBER) > 0 )) endfunction

should be

return( (Filter(function Trig_GameDrawCardRed_OrCondition)) and ( GetPlayerState(GetTriggerPlayer(), PLAYER_STATE_RESOURCE_LUMBER) > 0 )) endfunction

The game doesn't recognize a function unless you specify that it is a function... (which is why when parsed, this :Trig_GameDrawCardRed_OrCondition: just looked like (1))

PS: I'm not sure if the Filter is required for this...
 
Level 4
Joined
Aug 18, 2013
Messages
71
so yeah, remove the Filter part... I don't think you need the == true since the function is a boolean anyway...

What?
This is my code. there is no == true

JASS:
function Trig_GameDrawCardRed_OrCondition takes nothing returns boolean
    if((GetTriggerUnit() == gg_unit_n00C_0053)or(GetTriggerUnit() == gg_unit_n00C_0020)) then
        return true 
    //else
    //   if(GetTriggerUnit() == gg_unit_n00C_0020) then
    //        return true
    //   endif
    else
        return false
    endif
endfunction

function Trig_GameDrawCardRed_Conditions takes nothing returns boolean
    return( (Filter(function Trig_GameDrawCardRed_OrCondition)) and ( GetPlayerState(GetTriggerPlayer(), PLAYER_STATE_RESOURCE_LUMBER) > 0 ))
endfunction

if i use
JASS:
function Trig_GameDrawCardRed_Conditions takes nothing returns boolean
    return( (function Trig_GameDrawCardRed_OrCondition) and ( GetPlayerState(GetTriggerPlayer(), PLAYER_STATE_RESOURCE_LUMBER) > 0 ))
endfunction
i get the error : Cannot convert codereturnsboolean to boolean
 
THAT WAS MY CODE... your original code was Trig_GameDrawCardRed_OrCondition == true.. which I removed the == true part... and I just reiterated in that last post that I think you don't need it (because I forgot to tell you that you don't)

anyway, as I told you, just remove the Filter part...

though If I were you, I'd merge those two functions

EDIT: You know what? Try to it in GUI then convert to JASS and you'll see how they handle it...\

EDIT2: then try to bring back the == true

but really, If I were you, I'll just do this:

JASS:
function Trig_GameDrawCardRed_Conditions takes nothing returns boolean
  local unit a = GetTriggerUnit()
  if GetPlayerState(GetTriggerPlayer(), PLAYER_STATE_RESOURCE_LUMBER) > 0 and ((a == gg_unit_n00C_0053)or(a == gg_unit_n00C_0020)) then 
      set a = null
      return true
  else
      set a = null
      return false
  endif
endfunction
 
Level 4
Joined
Aug 18, 2013
Messages
71
originally, my issue arose because they were together so i added a function to solve the problem. but i rearranged it and now its okay. but removing Filter didnt solve the problem. I just want you to know what you suggested would not have worked. (No attack on you) just a friendly notice.
 
just in case you didn't noticed, I actually edited the post since you edited yours... :)

Adiktuz said:
but really, If I were you, I'll just do this:



JASS:
function Trig_GameDrawCardRed_Conditions takes nothing returns boolean
  local unit a = GetTriggerUnit()
  if GetPlayerState(GetTriggerPlayer(), PLAYER_STATE_RESOURCE_LUMBER) > 0 and ((a == gg_unit_n00C_0053)or(a == gg_unit_n00C_0020)) then 
      set a = null
      return true
  else
      set a = null
      return false
  endif
endfunction

and oh, you have experiences in 4 languages, I think things like this would have been easy to debug...
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,258
Unit types are integers just like ability types, destructible types, item types, upgrade types, and well pretty much all types. This property is very useful as it allows them to be used as a hashtable index directly. This means hashtables can be used to efficiently map data to types.

If you use JNGP you have much more control over the id assigned to each type instance. This lets you do very efficient but slightly unsafe ideas such as an array of abilities computed mathematically.
 
Status
Not open for further replies.
Top