Scope problem

Dryvnt

New Member
Reaction score
10
Why wont my scope start?

Current code:
JASS:
library PhysLib

    function PhysApplyForceX takes real XForce, unit whichUnit returns nothing
        local integer CustomID = GetUnitUserData(whichUnit)
        set X[CustomID] = X[CustomID] + XForce //Anything above 2000 will probably make your unit go completely out of the map
    endfunction
    
    function PhysApplyForceY takes real YForce, unit whichUnit returns nothing
        local integer CustomID = GetUnitUserData(whichUnit)
        set Y[CustomID] = Y[CustomID] + YForce //Anything above 2000 will probably make your unit go completely out of the map
    endfunction
    
    function PhysApplyForceZ takes real ZForce, unit whichUnit returns nothing
        local integer CustomID = GetUnitUserData(whichUnit)
        set Z[CustomID] = Z[CustomID] + (ZForce * 0.1)
    endfunction
    
    function PhysApplyForceAngle takes unit whichUnit, real Angle, real Force returns nothing
        call PhysApplyForceX(Cos(Angle * bj_DEGTORAD) * Force, whichUnit)
        call PhysApplyForceY(Sin(Angle * bj_DEGTORAD) * Force, whichUnit)
    endfunction
    
    function PhysUpdateUnits takes nothing returns nothing
        local unit FOG
        local integer Index = 0
        local rect TurnRect = bj_mapInitialPlayableArea
        call GroupEnumUnitsInRect(PhysUnits, GetWorldBounds(), null)
        set bj_wantDestroyGroup = true
        set PhysNumUnits = CountUnitsInGroup(PhysUnits)
        loop
        exitwhen Index > PhysNumUnits
            set FOG = FirstOfGroup(PhysUnits)
            set CurrentUnit[Index] = FOG
            call SetUnitUserData( FOG, Index )
            if GetUnitX(FOG) > GetRectMaxX(TurnRect) or GetUnitX(FOG) < GetRectMinX(TurnRect) then
                set X[Index] = -X[Index]
            endif
            if GetUnitY(FOG) > GetRectMaxY(TurnRect) or GetUnitY(FOG) < GetRectMinY(TurnRect) then
                set Y[Index] = -Y[Index]
            endif
            set Index = Index + 1
            call GroupRemoveUnit(PhysUnits, FOG)
        endloop
        set FOG = null
    endfunction
    
    function PhysCreateUnit takes player id, integer unitid, real x, real y, real face returns unit
        local unit a = CreateUnit(id,unitid,x,y,face)
        call PhysUpdateUnits()
        return a
    endfunction
endlibrary

scope Physics initializer Start

globals
group PhysUnits
integer PhysNumUnits
real array X
real array Y
real array Z
unit array CurrentUnit
endglobals

function PhysGetUnitZ takes unit whichUnit returns real
        local location Loc = GetUnitLoc(whichUnit)
        return GetLocationZ (Loc) + GetUnitFlyHeight (whichUnit)
    endfunction

function PhysicsMain takes nothing returns nothing
    local integer Index = 0
    local real Sign
    local location TempLoc
    local location TempLoc1
    local location TempLocX
    local location TempLocY
    call PhysUpdateUnits()
    loop
    exitwhen Index == PhysNumUnits
        if X[Index] != 0 or Y[Index] != 0 then
            call SetUnitX(CurrentUnit[Index], (GetUnitX(CurrentUnit[Index]) + X[Index]))
            call SetUnitY(CurrentUnit[Index], (GetUnitY(CurrentUnit[Index]) + Y[Index]))
            if X[Index] > -1 and X[Index] < 1 then
                set X[Index] = 0
            elseif GetUnitFlyHeight(CurrentUnit[Index]) < 5 then
                set Sign = RSignBJ(X[Index])
                set X[Index] = X[Index] - ((X[Index] / (Sign * 10)) * Sign)
            endif
            if Y[Index] > -1 and Y[Index] < 1 then
                set Y[Index] = 0
            elseif GetUnitFlyHeight(CurrentUnit[Index]) < 5 then
                set Sign = RSignBJ(Y[Index])
                set Y[Index] = Y[Index] - ((Y[Index] / (Sign * 10)) * Sign)
            endif
        endif
        set TempLoc = GetUnitLoc(CurrentUnit[Index])
        set TempLoc1 = Location((GetLocationX(TempLoc) + X[Index]), (GetLocationY(TempLoc) + Y[Index]))
        set TempLocX = Location((GetLocationX(TempLoc) + (X[Index])), GetLocationY(TempLoc))
        set TempLocY = Location(GetLocationX(TempLoc), (GetLocationY(TempLoc) + (Y[Index])))
        if GetUnitFlyHeight(CurrentUnit[Index]) + (60 * (X[Index] * 0.01) * RSignBJ(X[Index])) < ((GetLocationZ(TempLocX) - GetLocationZ(TempLoc))) then
            set X[Index] = -X[Index] * 0.1
        endif
        if GetUnitFlyHeight(CurrentUnit[Index]) + (60 * (X[Index] * 0.01) * RSignBJ(Y[Index])) < ((GetLocationZ(TempLocY) - GetLocationZ(TempLoc))) then
            set Y[Index] = -Y[Index] * 0.1
        endif        
        call SetUnitFlyHeight(CurrentUnit[Index], (GetUnitFlyHeight(CurrentUnit[Index]) + (GetLocationZ(TempLoc) - GetLocationZ(TempLoc1))), 100000)
        if Z[Index] <= 2 and PhysGetUnitZ(CurrentUnit[Index]) < (5 + GetLocationZ(TempLoc)) then
            if Z[Index] >= -2 then
                set Z[Index] = 0
            else
                set Z[Index] = -(Z[Index] * 0.5)
            endif
        else
            call UnitAddAbility(CurrentUnit[Index], 'Arav')
            call SetUnitFlyHeight(CurrentUnit[Index], (GetUnitFlyHeight(CurrentUnit[Index]) + Z[Index]), 100000)
            call UnitRemoveAbility(CurrentUnit[Index], 'Arav')
            set Z[Index] = Z[Index] - 1
        endif
    call RemoveLocation(TempLoc)
    call RemoveLocation(TempLoc1)
    call RemoveLocation(TempLocX)
    call RemoveLocation(TempLocY)
    set TempLoc = null
    set TempLoc1 = null
    set TempLocX = null
    set TempLocY = null
    set Index = (Index + 1)
    endloop
endfunction

function Start takes nothing returns nothing
    local timer CallPhysics = CreateTimer()
    local unit test = CreateUnit(Player(0), 'hpea', 0, 0, 0)
    call PhysUpdateUnits()
    call PhysApplyForceX(100,test)
    call BJDebugMsg("This text aint showing")
    call TimerStart(CallPhysics, 0.05, true, function PhysicsMain)
endfunction

endscope
 

Viikuna

No Marlo no game.
Reaction score
265
He means that you need to create your group:

JASS:
globals
    group G = CreateGroup() // This group works
    group G2 // This one aint
endglobals


EDIT. I read your code a bit more, and noticed that you are leaking locations here:
JASS:
function PhysGetUnitZ takes unit whichUnit returns real
        local location Loc = GetUnitLoc(whichUnit)
        return GetLocationZ (Loc) + GetUnitFlyHeight (whichUnit)
endfunction
 
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