• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[JASS] Cannot Convert group to unit

Status
Not open for further replies.
Level 9
Joined
Apr 23, 2011
Messages
460
In my script to loop create a hero for each player, it's telling me when i try to compile script that it cannot convert the group to unit. What group is there in my script? I'm new to this.
JASS:
    set udg_Hero[i]=CreateNUnitsAtLoc(1 , udg_Random[GetRandomInt(1 , 24)] , Player(i) , udg_tempLoc , bj_UNIT_FACING)

Here is the full trigger script
JASS:
function Trig_Random_Actions takes nothing returns nothing
local integer i = 0
set udg_tempLoc = (GetRectCenter(gg_rct_Hero_Spawn))
loop
    exitwhen i > 11
    set udg_Hero[i] = CreateUnitAtLoc( Player(i), udg_Random[GetRandomInt(1, 24)], udg_tempLoc, bj_UNIT_FACING)
    set i = i + 1
endloop
call RemoveLocation(udg_tempLoc)
endfunction

//===========================================================================
function InitTrig_Random takes nothing returns nothing
    local trigger RandomHero = CreateTrigger()
    call TriggerRegisterDialogButtonEvent(RandomHero, udg_StartDialogButton[1])
    call TriggerAddAction( RandomHero, function Trig_Random_Actions )
endfunction
 
Level 20
Joined
Jul 6, 2009
Messages
1,885
CreateNUnitsAtLoc returns a group since the function has possibility of creating multiple units. (Still, you can use bj_lastCreatedUnit variable from this function because the function is a BJ and it sets the last created, among N units, to bj_lastCreatedUnit variable.)

Just use CreateUnit takes player owner, integer rawcode, real x, real y, real facing returns unit function.
 
Level 20
Joined
Jul 6, 2009
Messages
1,885
Here's an optimized version of your code, you should examine it. It's more efficient to use coordinates instead of locations, they also don't leak.
Also BJ functions (the red highlighted ones should be avoided because they call on other functions within themselves so it's always better to use functions from within it (you can find such things in tools like JassCraft))
JASS:
function Trig_Random_Actions takes nothing returns nothing
    local integer i = 0
    loop
        exitwhen i > 11
        set udg_Hero[i] = CreateUnit(Player(i),udg_Random[GetRandomInt(1, 24)],GetRectCenterX(gg_rct_Hero_Spawn),GetRectCenterY(gg_rct_Hero_Spawn),270.0)
        set i = i + 1
    endloop
endfunction

//===========================================================================
function InitTrig_Random takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterDialogButtonEvent(t, udg_StartDialogButton[1])
    call TriggerAddAction(t, function Trig_Random_Actions )
    set t = null
endfunction
 
Level 9
Joined
Apr 23, 2011
Messages
460
For some reason when i make the Dialog buttons or something involving dialog buttons, it's not saving the dialog buttons to the array.
JASS:
function Trig_Startup_Actions takes nothing returns nothing
call DialogClear(udg_StartDialog)
set udg_StartDialog = DialogCreate()
call DialogSetMessage(udg_StartDialog, "Pick Mode")
set udg_StartDialogButton[1] = DialogAddButton(udg_StartDialog,"All Random", 1)
set udg_StartDialogButton[2] = DialogAddButton(udg_StartDialog,"All Pick", 2)
call DialogDisplay(Player(0), udg_StartDialog, true)
endfunction

//===========================================================================
function InitTrig_Startup takes nothing returns nothing
    local trigger Startup = CreateTrigger()
    call TriggerRegisterTimerEventSingle( Startup , 1.00)
    call TriggerAddAction( Startup, function Trig_Startup_Actions )
endfunction

I think it's right, but I'm sure im wrong.

EDIT: I have JassCraft, but when scripting I use JPNG. Should i switch to JC?
 
Level 20
Joined
Jul 6, 2009
Messages
1,885
It does save them, the thing is, their value is assigned after the event that fires upon button click is created.
Use this code instead: (You also don't need Random trigger if you use this)

JASS:
function Trig_Random_Actions takes nothing returns boolean
    local integer i = 0
    if GetClickedButton() == udg_StartDialogButton[1] then
        loop
            exitwhen i > 11
            set udg_Hero[i] = CreateUnit(Player(i),udg_Random[GetRandomInt(1, 24)],GetRectCenterX(gg_rct_Hero_Spawn),GetRectCenterY(gg_rct_Hero_Spawn),270.0)
            set i = i + 1
        endloop
    elseif GetClickedButton() == udg_StartDialogButton[2] then
        //actions for button 2
    endif
    return false
endfunction

function Trig_Startup_Actions takes nothing returns nothing
    local trigger t = CreateTrigger()
    call DialogClear(udg_StartDialog)
    set udg_StartDialog = DialogCreate()
    call DialogSetMessage(udg_StartDialog, "Pick Mode")
    set udg_StartDialogButton[1] = DialogAddButton(udg_StartDialog,"All Random", 1)
    set udg_StartDialogButton[2] = DialogAddButton(udg_StartDialog,"All Pick", 2)
    call TriggerRegisterDialogButtonEvent(t, udg_StartDialogButton[1])
    call TriggerRegisterDialogButtonEvent(t, udg_StartDialogButton[2])
    call TriggerAddCondition(t,Condition(function Trig_Random_Actions))
    call DialogDisplay(Player(0), udg_StartDialog, true)
    set t = null
endfunction

//===========================================================================
function InitTrig_Startup takes nothing returns nothing
    call TimerStart(CreateTimer(),1.00,false,function Trig_Startup_Actions)
endfunction
I suggest you examine the code a bit.
I have JassCraft, but when scripting I use JPNG. Should i switch to JC?
It doesn't matter, you can use JNGP too. Though i find JassCraft's native list easier to work with.
I have them both opened when scripting, i just use JC for native list.
 
Status
Not open for further replies.
Top