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.
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +1
  • V-SNES V-SNES:
    Happy Friday!
    +1

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top