Need help with my vJass trigger!

Regga-Voska

New Member
Reaction score
0
Hi, I am new to vJass, as you can see...
JASS:
//Move and rotate the picked unit, make the owner of the picked unit face the same angle as the picked unit and also pan the camera to the units location.
function Trig_Execute_Player_Reds_Unit_Functions_Func002Func005A takes nothing returns nothing
    call SetCameraFieldForPlayer( GetOwningPlayer(GetEnumUnit()), CAMERA_FIELD_ROTATION, GetUnitFacing(GetEnumUnit()), 0.10 )
    call PanCameraToTimedLocForPlayer( GetOwningPlayer(GetEnumUnit()), udg_Temp_Point_Red, 0.10 )
endfunction

function Trig_Execute_Player_Reds_Unit_Functions_Func002A takes nothing returns nothing
    set udg_Temp_Point_Red = GetUnitLoc(GetEnumUnit())
    set udg_Temp_Point_Red_Two = PolarProjectionBJ(udg_Temp_Point_Red, udg_Move_Red, ( GetUnitFacing(GetEnumUnit()) + udg_Rotation_Red ))
    call SetUnitPositionLoc( GetEnumUnit(), udg_Temp_Point_Red_Two )
    call SetUnitFacingTimed( GetEnumUnit(), ( GetUnitFacing(GetEnumUnit()) + ( udg_Rotation_Red + udg_Bonus_Rotation[1] ) ), 0 )
    call ForGroupBJ( udg_Temp_Group_Red, function Trig_Execute_Player_Reds_Unit_Functions_Func002Func005A )
    call RemoveLocation (udg_Temp_Point_Red)
    call RemoveLocation (udg_Temp_Point_Red_Two)
endfunction

function Trig_Execute_Player_Reds_Unit_Functions_Actions takes nothing returns nothing
    set udg_Temp_Group_Red = GetUnitsOfPlayerAndTypeId(Player(0), 'h000')
    call ForGroupBJ( udg_Temp_Group_Red, function Trig_Execute_Player_Reds_Unit_Functions_Func002A )
    call DestroyGroup (udg_Temp_Group_Red)
endfunction

//Periodic Event "Every 0.02 second"
function InitTrig_Execute_Player_Reds_Unit_Functions takes nothing returns nothing
    set gg_trg_Execute_Player_Reds_Unit_Functions = CreateTrigger(  )
    call TriggerRegisterTimerEventPeriodic( gg_trg_Execute_Player_Reds_Unit_Functions, 0.02 )
    call TriggerAddAction( gg_trg_Execute_Player_Reds_Unit_Functions, function Trig_Execute_Player_Reds_Unit_Functions_Actions )
endfunction
//Done
But I got a few errors called Undeclared Variables, and may I ask you guys how to fix them?
 
Try this:
JASS:
scope Name initializer Init

    globals
        private group Red = CreateGroup()
        private constant integer MoveRed = 100
        private constant integer RotationRed = 100
        private integer array BonusRotation
    endglobals
    
    private function RedGroup takes nothing returns nothing
        local unit eu = GetEnumUnit()
        local real x = GetUnitX(eu)
        local real y = GetUnitY(eu)
        local real x2 = x + MoveRed * Cos(RotationRed * bj_DEGTORAD)
        local real y2 = y + MoveRed * Sin(RotationRed * bj_DEGTORAD)
        
        call SetUnitX(eu, x2)
        call SetUnitY(eu, y2)
        call SetUnitFacingTimed(eu, GetUnitFacing(eu) + (RotationRed + BonusRotation[1]), 0)
        if(GetLocalPlayer() == GetOwningPlayer(eu)) then
            call SetCameraField(CAMERA_FIELD_ROTATION, GetUnitFacing(eu), 0.10)
        endif
        if(GetLocalPlayer() == GetOwningPlayer(eu)) then
            call PanCameraToTimed(x, y, 0.10)
        endif
        call GroupRemoveUnit(Red, eu)
        set eu = null
    endfunction
    
    private function Actions takes nothing returns nothing
        set bj_groupEnumTypeId = 'h000'
        call GroupEnumUnitsOfPlayer(Red, Player(0), filterGetUnitsOfPlayerAndTypeId)
        call ForGroup(Red, function RedGroup)
    endfunction


//====================================================================================================
    private function Init takes nothing returns nothing
        local trigger t = CreateTrigger()   //Create the trigger
        
        call TriggerRegisterTimerEvent(t, 0.02, true)   //0.02 periodic event
        call TriggerAddAction(t, function Actions)   //Actions for your trigger
    endfunction

endscope
 
Try this:
JASS:
scope Name initializer Init

    globals
        private group Red = CreateGroup()
        private constant integer MoveRed = 100
        private constant integer RotationRed = 100
        private integer array BonusRotation
    endglobals
    
    private function RedGroup takes nothing returns nothing
        local unit eu = GetEnumUnit()
        local real x = GetUnitX(eu)
        local real y = GetUnitY(eu)
        local real x2 = x + MoveRed * Cos(RotationRed * bj_DEGTORAD)
        local real y2 = y + MoveRed * Sin(RotationRed * bj_DEGTORAD)
        
        call SetUnitX(eu, x2)
        call SetUnitY(eu, y2)
        call SetUnitFacingTimed(eu, GetUnitFacing(eu) + (RotationRed + BonusRotation[1]), 0)
        if(GetLocalPlayer() == GetOwningPlayer(eu)) then
            call SetCameraField(CAMERA_FIELD_ROTATION, GetUnitFacing(eu), 0.10)
        endif
        if(GetLocalPlayer() == GetOwningPlayer(eu)) then
            call PanCameraToTimed(x, y, 0.10)
        endif
        call GroupRemoveUnit(Red, eu)
        set eu = null
    endfunction
    
    private function Actions takes nothing returns nothing
        set bj_groupEnumTypeId = 'h000'
        call GroupEnumUnitsOfPlayer(Red, Player(0), filterGetUnitsOfPlayerAndTypeId)
        call ForGroup(Red, function RedGroup)
    endfunction


//====================================================================================================
    private function Init takes nothing returns nothing
        local trigger t = CreateTrigger()   //Create the trigger
        
        call TriggerRegisterTimerEvent(t, 0.02, true)   //0.02 periodic event
        call TriggerAddAction(t, function Actions)   //Actions for your trigger
    endfunction

endscope

Thank you one hundred and twenty five thousand times!
But, I guess I can't just Copy/Paste and replace my current trigger.
Am I correct? Because when I did that all my older errors disappeared BUT it came 53 new errors such as Statement outside of function, Syntax Error, Missing line break etc.
 
You can place that into any trigger.
You just need NewGen (You should have it if you're doing vJASS :confused: ) .

That's exactly the same thing I downloaded a few hours ago. And i guess it's working correctly for me.
(When i trying to run the map, the Wc3 intro screen comes up, but the map where never loaded)
And all my variables will/needs to be affected by other triggers.
 
Could you post a screenshot of the errors or show me some lines that error?

EDIT: Also, make sure to have vJASS Syntax active.
 
Could you post a screenshot of the errors or show me some lines that error?

EDIT: Also, make sure to have vJASS Syntax active.

errors.jpg

There you go....
 
I just copied the code into a new trigger and it worked fine.

Make a new trigger,
Convert it to custom text;
Then replace everything that's there with the code:
JASS:
scope Name initializer Init

    globals
        private group Red = CreateGroup()
        private constant integer MoveRed = 100
        private constant integer RotationRed = 100
        private integer array BonusRotation
    endglobals
    
    private function RedGroup takes nothing returns nothing
        local unit eu = GetEnumUnit()
        local real x = GetUnitX(eu)
        local real y = GetUnitY(eu)
        local real x2 = x + MoveRed * Cos(RotationRed * bj_DEGTORAD)
        local real y2 = y + MoveRed * Sin(RotationRed * bj_DEGTORAD)
        
        call SetUnitX(eu, x2)
        call SetUnitY(eu, y2)
        call SetUnitFacingTimed(eu, GetUnitFacing(eu) + (RotationRed + BonusRotation[1]), 0)
        if(GetLocalPlayer() == GetOwningPlayer(eu)) then
            call SetCameraField(CAMERA_FIELD_ROTATION, GetUnitFacing(eu), 0.10)
        endif
        if(GetLocalPlayer() == GetOwningPlayer(eu)) then
            call PanCameraToTimed(x, y, 0.10)
        endif
        call GroupRemoveUnit(Red, eu)
        set eu = null
    endfunction
    
    private function Actions takes nothing returns nothing
        set bj_groupEnumTypeId = 'h000'
        call GroupEnumUnitsOfPlayer(Red, Player(0), filterGetUnitsOfPlayerAndTypeId)
        call ForGroup(Red, function RedGroup)
    endfunction


//====================================================================================================
    private function Init takes nothing returns nothing
        local trigger t = CreateTrigger()   //Create the trigger
        
        call TriggerRegisterTimerEvent(t, 0.02, true)   //0.02 periodic event
        call TriggerAddAction(t, function Actions)   //Actions for your trigger
    endfunction

endscope
 
I started the editor by pressing the Icon called NewGen WE.exe

vJASS requires you to actually save the map before testing it, otherwise it will just go to the wc3 main menu.

Also, the syntax checker is outdated (?) and does not work with vJASS, save is your only option of compiling.

Save before test map, always.
Even the slightest nudge in the code and you will have to re-compile the code.
Hope that works.

//==GooS
 
Ahh yeah.
Don't use the "Syntax Check" button.
Just Save (CTRL + S) the map and if nothing comes up you're good!
 
Huh?

Okey, now the unit moves. But not when I want it to...
(It moves constantly)

EDIT: And it only moves right. It should move forward. (The angle of the unit)
I will give you an example, when the unit looks right, he should move right. When the unit looks left, it should move left etc.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • The Helper The Helper:
    News portal has been retired. Main page of site goes to Headline News forum now
  • The Helper The Helper:
    I am working on getting access to the old news portal under a different URL for those that would rather use that for news before we get a different news view.
  • Ghan Ghan:
    Easily done
    +1
  • The Helper The Helper:
    https://www.thehelper.net/pages/news/ is a link to the old news portal - i will integrate it into the interface somewhere when i figure it out
  • Ghan Ghan:
    Need to try something
  • Ghan Ghan:
    Hopefully this won't cause problems.
  • Ghan Ghan:
    Hmm
  • Ghan Ghan:
    I have converted the Headline News forum to an Article type forum. It will now show the top 20 threads with more detail of each thread.
  • Ghan Ghan:
    See how we like that.
  • The Helper The Helper:
    I do not see a way to go past the 1st page of posts on the forum though
  • The Helper The Helper:
    It is OK though for the main page to open up on the forum in the view it was before. As long as the portal has its own URL so it can be viewed that way I do want to try it as a regular forum view for a while
  • Ghan Ghan:
    Yeah I'm not sure what the deal is with the pagination.
  • Ghan Ghan:
    It SHOULD be there so I think it might just be an artifact of having an older style.
  • Ghan Ghan:
    I switched it to a "Standard" article forum. This will show the thread list like normal, but the threads themselves will have the first post set up above the rest of the "comments"
  • The Helper The Helper:
    I don't really get that article forum but I think it is because I have never really seen it used on a multi post thread
  • Ghan Ghan:
    RpNation makes more use of it right now as an example: https://www.rpnation.com/news/
  • The Helper The Helper:
  • The Helper The Helper:
    What do you think Tom?
  • tom_mai78101 tom_mai78101:
    I will have to get used to this.
  • tom_mai78101 tom_mai78101:
    The latest news feed looks good
  • The Helper The Helper:
    I would like to see it again like Ghan had it the first time with pagination though - without the pagination that view will not work but with pagination it just might...
  • The Helper The Helper:
    This drink recipe I have had more than a few times back in the day! Mind Eraser https://www.thehelper.net/threads/cocktail-mind-eraser.194720/

      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