Jass Script Help

ShadowSnipe4

New Member
Reaction score
4
I was making a trigger in Jass, and saving it periodicly to make sure i had it right but it came up with the error "Expected Array Index" one the line
Code:
call SetCameraTargetControllerNoZForPlayer( Player (currentPlayer + 1), udg_MoveUnit, 0, 0, false )

The whole code is
Code:
function Trig_First_Person_View_Actions takes nothing returns nothing
    local integer currentPlayer = 0
    local unit currentUnit = null
    loop
        set currentUnit = udg_MoveUnit[currentPlayer + 1]
        if currentUnit != null then
        call SetCameraTargetControllerNoZForPlayer( Player (currentPlayer + 1), udg_MoveUnit, 0, 0, false )
    endif
        set currentPlayer = currentPlayer + 1
        exitwhen currentPlayer > 9
    endloop
    set currentUnit = null
endfunction

//===========================================================================
function InitTrig_First_Person_View takes nothing returns nothing
    set gg_trg_First_Person_View = CreateTrigger(  )
    call TriggerRegisterTimerEventPeriodic( gg_trg_First_Person_View, 0.20 )
    call TriggerAddAction( gg_trg_First_Person_View, function Trig_First_Person_View_Actions )
endfunction
 

pladams9

Seth's Good-Twin
Reaction score
19
I believe the problem is with:

Code:
(currentPlayer + 1)

I'm not sure why (and I don't have much experience with JASS programming specifically) but I believe that WC3 is having trouble interpreting that as an array index. Possibly it should be in square brackets ("[]") instead of parantheses. Just a guess. Quite possibly wrong. At the very least I believe the problem is something about that part of the line.
 

Korolen

New User (Why do I keep getting those red bars?)
Reaction score
69
Heh Heh... Heres that trigger that I said I would make, you can set the position of a unit or whatever to the value of udg_pos, with the angle of udg_angle.

"Events" trigger:
Code:
function gi takes nothing returns integer
 return GetConvertedPlayerId(GetTriggerPlayer()) - 1
endfunction

function MoveUp    takes nothing returns nothing
 if udg_v[gi()] == -1 then
  set udg_v[gi()] = 2
 else
  set udg_v[gi()] = 1
 endif
endfunction

function MoveDown  takes nothing returns nothing
 if udg_v[gi()] == 1 then
  set udg_v[gi()] = -2
 else
  set udg_v[gi()] = -1
 endif
endfunction

function MoveLeft  takes nothing returns nothing
 if udg_h[gi()] == 1 then
  set udg_h[gi()] = -2
 else
  set udg_h[gi()] = -1
 endif
endfunction

function MoveRight takes nothing returns nothing
 if udg_h[gi()] == -1 then
  set udg_h[gi()] = 2
 else
  set udg_h[gi()] = 1
 endif
endfunction

function StopUp    takes nothing returns nothing
 if udg_v[gi()] == 2 then
  set udg_v[gi()] = -1
 else
  set udg_v[gi()] = 0
 endif
endfunction

function StopDown  takes nothing returns nothing
 if udg_v[gi()] == -2 then
  set udg_v[gi()] = 1
 else
  set udg_v[gi()] = 0
 endif
endfunction

function StopLeft  takes nothing returns nothing
 if udg_h[gi()] == -2 then
  set udg_h[gi()] = 1
 else
  set udg_h[gi()] = 0
 endif
endfunction

function StopRight takes nothing returns nothing
 if udg_h[gi()] == 2 then
  set udg_h[gi()] = -1
 else
  set udg_h[gi()] = 0
 endif
endfunction


function InitTrig_Events takes nothing returns nothing
 local trigger up     = CreateTrigger()
 local trigger down   = CreateTrigger()
 local trigger left   = CreateTrigger()
 local trigger right  = CreateTrigger()
 local trigger up2    = CreateTrigger()
 local trigger down2  = CreateTrigger()
 local trigger left2  = CreateTrigger()
 local trigger right2 = CreateTrigger()

 local integer i = 0

 loop
  exitwhen i >= 12 //Put number of players here
  call TriggerRegisterPlayerKeyEventBJ(up,     Player(i), bj_KEYEVENTTYPE_DEPRESS, bj_KEYEVENTKEY_UP   )
  call TriggerRegisterPlayerKeyEventBJ(down,   Player(i), bj_KEYEVENTTYPE_DEPRESS, bj_KEYEVENTKEY_DOWN )
  call TriggerRegisterPlayerKeyEventBJ(left,   Player(i), bj_KEYEVENTTYPE_DEPRESS, bj_KEYEVENTKEY_LEFT )
  call TriggerRegisterPlayerKeyEventBJ(right,  Player(i), bj_KEYEVENTTYPE_DEPRESS, bj_KEYEVENTKEY_RIGHT)
  call TriggerRegisterPlayerKeyEventBJ(up2,    Player(i), bj_KEYEVENTTYPE_RELEASE, bj_KEYEVENTKEY_UP   )
  call TriggerRegisterPlayerKeyEventBJ(down2,  Player(i), bj_KEYEVENTTYPE_RELEASE, bj_KEYEVENTKEY_DOWN )
  call TriggerRegisterPlayerKeyEventBJ(left2,  Player(i), bj_KEYEVENTTYPE_RELEASE, bj_KEYEVENTKEY_LEFT )
  call TriggerRegisterPlayerKeyEventBJ(right2, Player(i), bj_KEYEVENTTYPE_RELEASE, bj_KEYEVENTKEY_RIGHT)
  set i = i + 1
 endloop

 call TriggerAddAction(up,     function MoveUp   )
 call TriggerAddAction(down,   function MoveDown )
 call TriggerAddAction(left,   function MoveLeft )
 call TriggerAddAction(right,  function MoveRight)
 call TriggerAddAction(up2,    function StopUp   )
 call TriggerAddAction(down2,  function StopDown )
 call TriggerAddAction(left2,  function StopLeft )
 call TriggerAddAction(right2, function StopRight)
endfunction


"Move" trigger:
Code:
function Move takes nothing returns nothing
 local integer i = 0
 local locaiton np

 loop
  exitwhen i >= 12

  if       udg_h[i] < 0 then
   set udg_angle[i] = udg_angle[i] - 0.5
  elseif   udg_h[i] > 0 then
   set udg_angle[i] = udg_angle[i] + 0.5
  endif

  if     udg_v[i] > 0 then
   set np = PolarProjectionBJ(udg_pos[i], 6,  udg_angle[i])
  elseif udg_v[i] < 0 then
   set np = PolarProjectionBJ(udg_pos[i], -2, udg_angle[i])
  endif

  if IsTerrainPathableBJ(np, PATHING_TYPE_WALKABILITY) then
   set udg_pos[i] = np
  endif


 endloop
endfunction

function InitTrig_Move takes nothing returns nothing
    set gg_trg_Move = CreateTrigger()
    call TriggerRegisterTimerEventPeriodic(gg_trg_Move, 0.01)
    call TriggerAddAction(gg_trg_Move, function Move)
endfunction

Globals:
Code:
 v: integer array(12)
 h: integer array(12)
 pos: point array(12)
 angle: real array(12)

Oh, and why are you adding 1 to all your indexes?
 

Korolen

New User (Why do I keep getting those red bars?)
Reaction score
69
Yea, it is that udg_MoveUnit is an array, because he gives it an index on another line, see?
 

ShadowSnipe4

New Member
Reaction score
4
Korolen said:
Heh Heh... Heres that trigger that I said I would make, you can set the position of a unit or whatever to the value of udg_pos, with the angle of udg_angle.

"Events" trigger:
Code:
function gi takes nothing returns integer
 return GetConvertedPlayerId(GetTriggerPlayer()) - 1
endfunction

function MoveUp    takes nothing returns nothing
 if udg_v[gi()] == -1 then
  set udg_v[gi()] = 2
 else
  set udg_v[gi()] = 1
 endif
endfunction

function MoveDown  takes nothing returns nothing
 if udg_v[gi()] == 1 then
  set udg_v[gi()] = -2
 else
  set udg_v[gi()] = -1
 endif
endfunction

function MoveLeft  takes nothing returns nothing
 if udg_h[gi()] == 1 then
  set udg_h[gi()] = -2
 else
  set udg_h[gi()] = -1
 endif
endfunction

function MoveRight takes nothing returns nothing
 if udg_h[gi()] == -1 then
  set udg_h[gi()] = 2
 else
  set udg_h[gi()] = 1
 endif
endfunction

function StopUp    takes nothing returns nothing
 if udg_v[gi()] == 2 then
  set udg_v[gi()] = -1
 else
  set udg_v[gi()] = 0
 endif
endfunction

function StopDown  takes nothing returns nothing
 if udg_v[gi()] == -2 then
  set udg_v[gi()] = 1
 else
  set udg_v[gi()] = 0
 endif
endfunction

function StopLeft  takes nothing returns nothing
 if udg_h[gi()] == -2 then
  set udg_h[gi()] = 1
 else
  set udg_h[gi()] = 0
 endif
endfunction

function StopRight takes nothing returns nothing
 if udg_h[gi()] == 2 then
  set udg_h[gi()] = -1
 else
  set udg_h[gi()] = 0
 endif
endfunction


function InitTrig_Events takes nothing returns nothing
 local trigger up     = CreateTrigger()
 local trigger down   = CreateTrigger()
 local trigger left   = CreateTrigger()
 local trigger right  = CreateTrigger()
 local trigger up2    = CreateTrigger()
 local trigger down2  = CreateTrigger()
 local trigger left2  = CreateTrigger()
 local trigger right2 = CreateTrigger()

 local integer i = 0

 loop
  exitwhen i >= 12 //Put number of players here
  call TriggerRegisterPlayerKeyEventBJ(up,     Player(i), bj_KEYEVENTTYPE_DEPRESS, bj_KEYEVENTKEY_UP   )
  call TriggerRegisterPlayerKeyEventBJ(down,   Player(i), bj_KEYEVENTTYPE_DEPRESS, bj_KEYEVENTKEY_DOWN )
  call TriggerRegisterPlayerKeyEventBJ(left,   Player(i), bj_KEYEVENTTYPE_DEPRESS, bj_KEYEVENTKEY_LEFT )
  call TriggerRegisterPlayerKeyEventBJ(right,  Player(i), bj_KEYEVENTTYPE_DEPRESS, bj_KEYEVENTKEY_RIGHT)
  call TriggerRegisterPlayerKeyEventBJ(up2,    Player(i), bj_KEYEVENTTYPE_RELEASE, bj_KEYEVENTKEY_UP   )
  call TriggerRegisterPlayerKeyEventBJ(down2,  Player(i), bj_KEYEVENTTYPE_RELEASE, bj_KEYEVENTKEY_DOWN )
  call TriggerRegisterPlayerKeyEventBJ(left2,  Player(i), bj_KEYEVENTTYPE_RELEASE, bj_KEYEVENTKEY_LEFT )
  call TriggerRegisterPlayerKeyEventBJ(right2, Player(i), bj_KEYEVENTTYPE_RELEASE, bj_KEYEVENTKEY_RIGHT)
  set i = i + 1
 endloop

 call TriggerAddAction(up,     function MoveUp   )
 call TriggerAddAction(down,   function MoveDown )
 call TriggerAddAction(left,   function MoveLeft )
 call TriggerAddAction(right,  function MoveRight)
 call TriggerAddAction(up2,    function StopUp   )
 call TriggerAddAction(down2,  function StopDown )
 call TriggerAddAction(left2,  function StopLeft )
 call TriggerAddAction(right2, function StopRight)
endfunction


"Move" trigger:
Code:
function Move takes nothing returns nothing
 local integer i = 0
 local locaiton np

 loop
  exitwhen i >= 12

  if       udg_h[i] < 0 then
   set udg_angle[i] = udg_angle[i] - 0.5
  elseif   udg_h[i] > 0 then
   set udg_angle[i] = udg_angle[i] + 0.5
  endif

  if     udg_v[i] > 0 then
   set np = PolarProjectionBJ(udg_pos[i], 6,  udg_angle[i])
  elseif udg_v[i] < 0 then
   set np = PolarProjectionBJ(udg_pos[i], -2, udg_angle[i])
  endif

  if IsTerrainPathableBJ(np, PATHING_TYPE_WALKABILITY) then
   set udg_pos[i] = np
  endif


 endloop
endfunction

function InitTrig_Move takes nothing returns nothing
    set gg_trg_Move = CreateTrigger()
    call TriggerRegisterTimerEventPeriodic(gg_trg_Move, 0.01)
    call TriggerAddAction(gg_trg_Move, function Move)
endfunction

Globals:
Code:
 v: integer array(12)
 h: integer array(12)
 pos: point array(12)
 angle: real array(12)

Oh, and why are you adding 1 to all your indexes?

Whats funny is that you post this after i already got that part.(with heptameron's help over msn) I've already moved on to the cameras :D

So its the udg_MoveUnit that's giving me trouble?
 

Vexorian

Why no custom sig?
Reaction score
187
Well yes, since it is an array you have to specify its index

udg_MoveUnit doesn't work
udg_MoveUnit[1] works
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top