1. Head to the 33rd Modeling Contest Poll and drink to your heart's desire.
    Dismiss Notice
  2. Choose your means of doom in the 17th Mini Mapping Contest Poll.
    Dismiss Notice
  3. A slave to two rhythms, the 22nd Terraining Contest is here.
    Dismiss Notice
  4. The heavens smile on the old faithful. The 16th Techtree Contest has begun.
    Dismiss Notice
  5. The die is cast - the 6th Melee Mapping Contest results have been announced. Onward to the Hive Cup!
    Dismiss Notice
  6. The glory of the 20th Icon Contest is yours for the taking!
    Dismiss Notice
  7. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

[Solved] check what is wrong with these jass code please

Discussion in 'Triggers & Scripts' started by AnonymousPro, Sep 11, 2016.

  1. Dr Super Good

    Dr Super Good

    Spell Reviewer

    Joined:
    Jan 18, 2005
    Messages:
    26,099
    Resources:
    3
    Maps:
    1
    Spells:
    2
    Resources:
    3
    You have to return the correct type because otherwise the type cast exploit strikes back at you and returns a physical cast as opposed to a logical one. The result is one can create a separate set of I2R and R2I type casts which return values that are kept bit identical, rather than numerically similar.

    Your loop makes little sense? Try this.
    Code (vJASS):
    function Trig_Tiles_Actions takes nothing returns nothing
    //Always ALWAYS avoid locations wherever you can-- they are the DEVIL in wc3 (memory leaks, slow, not useful, etc.)
        local real rxMax
        local real rxMin
        local real ryMax
        local real ryMin
        local integer i = 1

        set udg_CheckRect[1] = gg_rct_Area14
        set udg_CheckRect[2] = gg_rct_Area15
        set udg_CheckRect[3] = gg_rct_Area16
        set udg_CheckRect[4] = gg_rct_Area17

        loop
        exitwhen i>4
            call SetTerrainType(GetRectCenterX(udg_CheckRect[i]),GetRectCenterY(udg_CheckRect[i]), 'Ldrt', -1, 8, 1 )
            set udg_CheckRect[i] = null
            set i = i+1
        endloop
    endfunction

    //===========================================================================
    function InitTrig_Tiles takes nothing returns nothing
        set gg_trg_Tiles = CreateTrigger(  )
        call TriggerAddAction( gg_trg_Tiles, function Trig_Tiles_Actions )
    endfunction
     
     
  2. DracoL1ch

    DracoL1ch

    Joined:
    Dec 12, 2010
    Messages:
    2,036
    Resources:
    2
    Tutorials:
    2
    Resources:
    2
    nope, jass thread fall out instead of working with wrong number.
     
  3. Dr Super Good

    Dr Super Good

    Spell Reviewer

    Joined:
    Jan 18, 2005
    Messages:
    26,099
    Resources:
    3
    Maps:
    1
    Spells:
    2
    Resources:
    3
    Try explaining that to this nonsense...
    Code (vJASS):

    library ReinterpretCast
         private function realToIndex takes real r returns integer
             loop
                 return r
             endloop
             return 0
         endfunction

         private function cleanInt takes integer i returns integer
             return i
         endfunction

         private function indexToReal takes integer i returns real
             loop
                 return i
             endloop
             return 0.0
         endfunction

         private function cleanReal takes real r returns real
             return r
         endfunction
         
         function ReinterpretI2R takes integer i returns real
             return cleanReal(indexToReal(i))
         endfunction

         function ReinterpretR2I takes real r returns integer
             return cleanInt(realToIndex(r))
         endfunction
    endlibrary
     
     
  4. DracoL1ch

    DracoL1ch

    Joined:
    Dec 12, 2010
    Messages:
    2,036
    Resources:
    2
    Tutorials:
    2
    Resources:
    2
    try to run my example functions instead. typecasting is bit different from normal behavior of jass VM
     
  5. AnonymousPro

    AnonymousPro

    Joined:
    Nov 18, 2012
    Messages:
    311
    Resources:
    0
    Resources:
    0
    it still only sets the terrain of the first rct
     
  6. Pyrogasm

    Pyrogasm

    Joined:
    Feb 27, 2007
    Messages:
    3,788
    Resources:
    1
    Spells:
    1
    Resources:
    1
    You can have a region array in regular JASS, but it can't be a global region array-- you're limited to local region variables. You don't even have to USE JNGP for anything if you just install it for its ability to declare globals freely, which I think would massively benefit you.
    Code (vJASS):
    //Without JNGP
    function a takes nothing returns nothing
        local region array Rarray
        set Rarray[3] = RegionAddRect(...)
    endfunction

    //With JNGP
    globals
        region array RarrayGlobal
    endglobals
    function b takes nothing returns nothing
        set RarrayGlobal[3] = RegionAddRect(...)
    endfunction


    With JNGP installed, saving the map will run a syntax check and compile the code if it passes the check. Pressing the Test Map button will not compile the map properly so you must save before pressing that button.

    Then you're off to a good start! Don't pull your hair out over locations, just avoid them in the future if you can. For ex: GUI is almost entirely dependent on locations but it still works fine, so imagine if you didn't have to think about using
    RemoveLocation()
    all the time? Nice, eh?

    Not that I can see.


    I made a mistake and forgot something in this line of my example (I never checked to see if it's the correct portal that will teleport you for real!)
    Code (vJASS):
    function Trig_RandomGen_Actions takes nothing returns nothing
        local unit u = GetTriggerUnit()
        local real ux = GetUnitX(u)    //Always ALWAYS avoid locations wherever you can-- they are the DEVIL in wc3 (memory leaks, slow, not useful, etc.)
        local real uy = GetUnitY(u)
        local real rxMax
        local real rxMin
        local real ryMax
        local real ryMin
        local integer i = 1
        local rect CheckRect

        loop
            if i == 1 then
                set CheckRect = gg_rct_Region_009
            elseif i == 2 then
                set CheckRect = gg_rct_Region_010
            elseif i == 3 then
                set CheckRect = gg_rct_Region_011
            elseif i == 4 then
                set CheckRect = gg_rct_Region_012
            else
                set CheckRect = null //this is a safety call, probably unnecessary
            endif

            set rxMax = GetRectMaxX(CheckRect)
            set rxMin = GetRectMinX(CheckRect)
            set ryMax = GetRectMaxY(CheckRect)
            set ryMin = GetRectMinY(CheckRect)


            @HERE@
            if (rxMax >= ux and ux >= rxMin) and (ryMax >= uy and uy >= ryMin)
                //If ux and uy are within its boundary then the unit must be inside
                if udg_AccessofPortal[i] then
                    //If it's the right portal, move the unit to the safe region
                    call SetUnitX(GetRectCenterX(gg_rct_Region_13))
                    call SetUnitY(GetRectCenterY(gg_rct_Region_13))
                else
                    //If it's the wrong portal, move the unit to HELL
                    call SetUnitX(GetRectCenterX(gg_rct_Region_HELL_OMG))
                    call SetUnitY(GetRectCenterY(gg_rct_Region_HELL_OMG))
                endif
                exitwhen true //leave the loop early, no need to do more
            endif

            set i = i+1
            exitwhen i > TOTAL_PORTALS // Probably 4, again
        endloop

        set u = null
        set CheckRect = null
    endfunction
     

    ______________________________
    Now, why is yours not working? I'm not sure, but again your trigger has no events (unless you're manually calling Trig_Tiles_Actions() it should never run. My best guess is that some of your arguments to
    SetTerrainType(... , 'Ldrt', @-1@, 8, 1 )
    are invalid. Try playing with the numbers at the end, and I'm pretty sure they can't be less than 0 or thread crash.

    Aside from that
    CheckRect
    should just be a normal rect, not a rect array. In fact it doesn't HAVE to be global either (in my example it's local) unless you want to store all the possible rects you could be teleported to. While that might help you in the long run if you have lots of these different portal/groups of portals, I think it'll just be easier to keep doing a pseudo-switch/case like I wrote. You could even write a function for it to make it more clear why you only need a local CheckRect:
    Code (vJASS):
    function GetRectToCheck_1 takes integer i returns rect
        local rect r = null

        if i == 1 then
            set CheckRect = gg_rct_Region_009
        elseif i == 2 then
            set CheckRect = gg_rct_Region_010
        elseif i == 3 then
            set CheckRect = gg_rct_Region_011
        elseif i == 4 then
            set CheckRect = gg_rct_Region_012
        endif
        //else no longer needed, safety call taken care of at r declaration

        return r
    endfunction
    //...
        loop
            set CheckRect = GetRectToCheck_1(i)

            set rxMax = GetRectMaxX(CheckRect)
            set rxMin = GetRectMinX(CheckRect)
            set ryMax = GetRectMaxY(CheckRect)
            set ryMin = GetRectMinY(CheckRect)
    //...
     
  7. Dr Super Good

    Dr Super Good

    Spell Reviewer

    Joined:
    Jan 18, 2005
    Messages:
    26,099
    Resources:
    3
    Maps:
    1
    Spells:
    2
    Resources:
    3
    It should set 1 tile at the centre of every of the 4 rects, as you specified.
     
  8. AnonymousPro

    AnonymousPro

    Joined:
    Nov 18, 2012
    Messages:
    311
    Resources:
    0
    Resources:
    0
    I assume JNGP allows me to declare a global region array.. I'll try

    Kinda figured that out after failing some syntax check due to autosave lol :p

    So If I were to use locations, do I have to use
    Code (vJASS):
    RemoveLocation()
    to avoid mass leak?

    Thanks for the awesome number of inputs! I have set CheckRect to array because I want all my map's portal to have randomized teleports, which is more like dungeon. (I hope it work this way)

    Setting the Terrain was actually converted from GUI trigger so I think it works that way, since it has changed the first terrain to that tiles
    I thought it should too, but it didn't. I'll try again.

    PS: sorry for late reply, I'm having fun in internship now so I could do more on mapmaking probably on weekends. Cheers!
     
  9. Pyrogasm

    Pyrogasm

    Joined:
    Feb 27, 2007
    Messages:
    3,788
    Resources:
    1
    Spells:
    1
    Resources:
    1
    Yeah, you can have everything except a
    code array
    . You're correct about the terrain: -1 gives random texture variation, so that can't be the issue. instead of changing the terrain type I would do something like create a footman in the middle of each checked rect because that's a lot more visible and will show you every time it runs rather than only the first time (because after that the terrain is already changed so you won't see change!). Pick your poison, though-- you could use special effects too as easy indicators.

    RemoveLocation()
    is necessary for any
    location
    you don't want to keep around and/or use again. Generally speaking: yes, every time a 'new' location is 'gotten' (through
    GetSpellTargetPoint()
    ,
    GetUnitLoc()
    , etc.) it will need to be removed by a subsequent
    RemoveLocation()
    call.

    Understand that you are removing the location data itself from the game (so it doesn't eat up used memory for no reason, which is why they're considered 'leaks'), not just deleting a variable. See below.
    Code (vJASS):
    //Leak free!
    set Loc = GetSpellTargetLoc()
    call RemoveLocation(Loc)
    set Loc = GetUnitLoc(GetTriggerUnit())
    call RemoveLocation(Loc)
    set Loc = null //also important to do this for non-basic types in JASS, unless I'm archaic in my methods


    //Leaks 1 location!
    set Loc = GetSpellTargetLoc()
    set Loc = GetUnitLoc(GetTriggerUnit())
    call RemoveLocation(Loc)
    set Loc = null


    I see no reason you code would just stop executing, so perhaps there's a new error in the updated code. Can you post all of your portal-related triggers (if there are indeed more than one, that's unclear to me atm) or upload your map? In general you can use the JNGP's JassHelper syntax checker when you save, but if isn't showing you what the error is you might have to select "JassHelper >> Show previous errors" from the toolbar after it tells you there's one.

    To problem-solve myself without understanding or knowing about a particular syntax error, I just start commenting things out and add in
    BJDebugMsg("part __")
    calls everywhere until I figure out exactly which lines will compile/are running properly and which are not. you can make multi-line comments in vJASS to quickly comment out stuff
    Code (vJASS):
    call Whatever()
    //the line below 'starts' a multiline comment

    /*
    set i = 0
    loop
        set i = i+1
        exitwhen MyFunc(i)
    endloop
    */


    //the line above ends a multiline comment

    call WhateverElse()
     
  10. AnonymousPro

    AnonymousPro

    Joined:
    Nov 18, 2012
    Messages:
    311
    Resources:
    0
    Resources:
    0
    Code (vJASS):
    function RandomPortal takes nothing returns integer
        return GetRandomInt(1,4)
    endfunction

    function SetPortalNumber takes nothing returns nothing
        local integer i = 1

        loop
            set udg_AccessofPortal[i] = false
            set i = i+1
            exitwhen i > 4 //I'm guessing this is 4 for your map? Confused by you using 5 since there are only 4 rects you check in.
        endloop

        set udg_AccessofPortal[RandomPortal()] = true
    endfunction

    function Trig_RandomGen_Actions takes nothing returns nothing
        local unit u = GetTriggerUnit()
        local real ux = GetUnitX(u)     //Always ALWAYS avoid locations wherever you can-- they are the DEVIL in wc3 (memory leaks, slow, not useful, etc.)
        local real uy = GetUnitY(u)
        local real rxMax
        local real rxMin
        local real ryMax
        local real ryMin
        local integer i = 1
        local rect CheckRect

        loop
            if i == 1 then
                set CheckRect = gg_rct_Region_009
            elseif i == 2 then
                set CheckRect = gg_rct_Region_010
            elseif i == 3 then
                set CheckRect = gg_rct_Region_011
            elseif i == 4 then
                set CheckRect = gg_rct_Region_012
            else
                set CheckRect = null //this is a safety call, probably unnecessary
            endif

            set rxMax = GetRectMaxX(CheckRect)
            set rxMin = GetRectMinX(CheckRect)
            set ryMax = GetRectMaxY(CheckRect)
            set ryMin = GetRectMinY(CheckRect)

            if (rxMax >= ux and ux >= rxMin) and (ryMax >= uy and uy >= ryMin) then
                //If ux and uy are within its boundary then the unit must be inside
                if udg_AccessofPortal[i] then
                    //If it's the right portal, move the unit to the safe region
                    call SetUnitX(u,GetRectCenterX(gg_rct_Region_013))
                    call SetUnitY(u,GetRectCenterY(gg_rct_Region_013))
                else
                    //If it's the wrong portal, move the unit to HELL
                    call SetUnitX(u,GetRectCenterX(gg_rct_Region_011))
                    call SetUnitY(u,GetRectCenterY(gg_rct_Region_011))
                endif
                exitwhen true //leave the loop early, no need to do more
            endif

            set i = i+1
            exitwhen i > 4 // Probably 4, again
        endloop

        set u = null
        set CheckRect=null
    endfunction

    //===========================================================================
    function InitTrig_RandomGen1 takes nothing returns nothing
        call SetPortalNumber()
        set gg_trg_RandomGen1 = CreateTrigger(  )
        call TriggerAddAction( gg_trg_RandomGen1, function Trig_RandomGen_Actions )
    endfunction
     

    this is giving me fatal error somehow :<
     
  11. Dr Super Good

    Dr Super Good

    Spell Reviewer

    Joined:
    Jan 18, 2005
    Messages:
    26,099
    Resources:
    3
    Maps:
    1
    Spells:
    2
    Resources:
    3
    At initialization? Or at some other time?

    If at some other time you will need to show the events you bind to the trigger. As a rough guess it might be cyclic recurrence due to moving the unit.
     
  12. AnonymousPro

    AnonymousPro

    Joined:
    Nov 18, 2012
    Messages:
    311
    Resources:
    0
    Resources:
    0
    Okay test map work at initialization, but i don't get teleported in any of the portals
     
    Last edited: Sep 16, 2016
  13. AnonymousPro

    AnonymousPro

    Joined:
    Nov 18, 2012
    Messages:
    311
    Resources:
    0
    Resources:
    0
    @Pyrogasm @Dr Super Good
    Hello, I have edited slightly, and I feel the code should have no problem.
    However, the rects won't teleport my units into the next rect

    Code (vJASS):

    function RandomPortal takes nothing returns integer
        return GetRandomInt(1,4)
    endfunction

    function SetPortalNumber takes nothing returns nothing
        local integer i = 1

        loop
            set udg_AccessofPortal[i] = false
            set i = i+1
            exitwhen i > 4 //I'm guessing this is 4 for your map? Confused by you using 5 since there are only 4 rects you check in.
        endloop

        set udg_AccessofPortal[RandomPortal()] = true             // udg_AccessofPortal[x] will be true
    endfunction

    function Trig_RandomGen_Actions takes nothing returns nothing
        local unit u = GetTriggerUnit()
        local real ux = GetUnitX(u)     //Always ALWAYS avoid locations wherever you can-- they are the DEVIL in wc3 (memory leaks, slow, not useful, etc.)
        local real uy = GetUnitY(u)
        local real rxMax
        local real rxMin
        local real ryMax
        local real ryMin
        local integer i = 1
        local integer ii = 0
        local rect CheckRect                               //local rect checks the rect at portal entrance

        loop
            if i == 1 then
                set CheckRect = gg_rct_Region_009
            elseif i == 2 then
                set CheckRect = gg_rct_Region_010
            elseif i == 3 then
                set CheckRect = gg_rct_Region_011
            elseif i == 4 then
                set CheckRect = gg_rct_Region_012
            else
                set CheckRect = null //this is a safety call, probably unnecessary
            endif

            set rxMax = GetRectMaxX(CheckRect)
            set rxMin = GetRectMinX(CheckRect)
            set ryMax = GetRectMaxY(CheckRect)
            set ryMin = GetRectMinY(CheckRect)

            if (rxMax >= ux and ux >= rxMin) and (ryMax >= uy and uy >= ryMin) then
                //If ux and uy are within its boundary then the unit must be inside            
                if udg_AccessofPortal[i]==true then
                    //if portal is right
                   
                    set ii=ii+1 //If it's the right portal, set correct count to +1, move the unit to the center of TG1 (safe region)              
                    call SetUnitX(u,GetRectCenterX(gg_rct_TrainingGround1))
                    call SetUnitY(u,GetRectCenterY(gg_rct_TrainingGround1))
                    elseif udg_AccessofPortal[i]==true and ii>2 then
                    //if >2 correct count, then set location to Area 2
                    call SetUnitX(u,GetRectCenterX(gg_rct_Region_018))
                    call SetUnitY(u,GetRectCenterY(gg_rct_Region_018))
                else
                    //If it's the wrong portal, move the unit to HELL
                    call SetUnitX(u,GetRectCenterX(gg_rct_Region_013))
                    call SetUnitY(u,GetRectCenterY(gg_rct_Region_013))
                endif
                exitwhen udg_AccessofPortal[i]==true // leave the loop early, no need to do more
            endif

            set i = i+1
            exitwhen i > 4 // Probably 4, again
        endloop

        set u = null
        set CheckRect=null
    endfunction

    //===========================================================================
    function InitTrig_RandomGen1 takes nothing returns nothing
        call SetPortalNumber()
        set gg_trg_RandomGen1 = CreateTrigger(  )
        call TriggerAddAction( gg_trg_RandomGen1, function Trig_RandomGen_Actions )
    endfunction
     


    I think my rects are small and the unit cannot be completely bound by the rect, so it won't teleport.
    Can that be the reason?
    What can I do to make it so that if the unit is touching any part of the rect and will teleport into the next rect?
     
  14. Dr Super Good

    Dr Super Good

    Spell Reviewer

    Joined:
    Jan 18, 2005
    Messages:
    26,099
    Resources:
    3
    Maps:
    1
    Spells:
    2
    Resources:
    3
    There are no events attached to the trigger?
    No it cannot be the reason.

    Maybe change to using regions instead? Regions allow you to detect unit entry to them with a trigger event.
     
  15. AnonymousPro

    AnonymousPro

    Joined:
    Nov 18, 2012
    Messages:
    311
    Resources:
    0
    Resources:
    0
    @Dr Super Good
    Code (vJASS):

    globals
    region array udg_SaveRegion
    endglobals
    function RandomPortal takes nothing returns integer
        return GetRandomInt(1,4)
    endfunction

    function SetPortalNumber takes nothing returns nothing
        local integer i = 1

        loop
            set udg_AccessofPortal[i] = false
            set i = i+1
            exitwhen i > 4 //I'm guessing this is 4 for your map? Confused by you using 5 since there are only 4 rects you check in.
        endloop

        set udg_AccessofPortal[RandomPortal()] = true             // udg_AccessofPortal[x] will be true
    endfunction

    function Trig_RandomGen_Actions takes nothing returns nothing
        local unit u = GetTriggerUnit()
        local real ux = GetUnitX(u)     //Always ALWAYS avoid locations wherever you can-- they are the DEVIL in wc3 (memory leaks, slow, not useful, etc.)
        local real uy = GetUnitY(u)
        local real rxMax
        local real rxMin
        local real ryMax
        local real ryMin
        local integer i = 5
        local integer ii = 0
                       //local rect checks the rect at portal entrance
        loop
            if i == 5 then
                set udg_CheckRect[i] = gg_rct_Region_009
            elseif i == 6 then
                set udg_CheckRect[i] = gg_rct_Region_010
            elseif i == 7 then
                set udg_CheckRect[i] = gg_rct_Region_011
            elseif i == 8 then
                set udg_CheckRect[i] = gg_rct_Region_012
            else        
            endif
            call RegionAddRect(udg_SaveRegion[1],udg_CheckRect[i])
            set rxMax = GetRectMaxX(udg_CheckRect[i])
            set rxMin = GetRectMinX(udg_CheckRect[i])
            set ryMax = GetRectMaxY(udg_CheckRect[i])
            set ryMin = GetRectMinY(udg_CheckRect[i])

            if (rxMax >= ux and ux >= rxMin) and (ryMax >= uy and uy >= ryMin) then
                //If ux and uy are within its boundary then the unit must be inside            
                if udg_AccessofPortal[i]==true then
                    //if portal is right
                   
                    set ii=ii+1 //If it's the right portal, set correct count to +1, move the unit to the center of TG1 (safe region)              
                    call SetUnitX(u,GetRectCenterX(gg_rct_TrainingGround1))
                    call SetUnitY(u,GetRectCenterY(gg_rct_TrainingGround1))
                    elseif udg_AccessofPortal[i]==true and ii>2 then
                    //if >2 correct count, then set location to Area 2
                    call SetUnitX(u,GetRectCenterX(gg_rct_Region_018))
                    call SetUnitY(u,GetRectCenterY(gg_rct_Region_018))
                else
                    //If it's the wrong portal, move the unit to HELL
                    call SetUnitX(u,GetRectCenterX(gg_rct_Region_013))
                    call SetUnitY(u,GetRectCenterY(gg_rct_Region_013))
               endif
                exitwhen udg_AccessofPortal[i]==true // leave the loop early, no need to do more
            endif

            set i = i+1
            exitwhen i > 4 // Probably 4, again
        endloop

        set u = null
    endfunction
    function funcfunc takes nothing returns boolean
    return true//return is unit a hero
    endfunction
    //===========================================================================
    function InitTrig_RandomGen1 takes nothing returns nothing
        call SetPortalNumber()
        set gg_trg_RandomGen1 = CreateTrigger(  )
        call TriggerRegisterEnterRegion(gg_trg_RandomGen1,udg_SaveRegion[1],Condition(function funcfunc))
        call TriggerAddAction( gg_trg_RandomGen1, function Trig_RandomGen_Actions )
    endfunction
     
     
  16. Dr Super Good

    Dr Super Good

    Spell Reviewer

    Joined:
    Jan 18, 2005
    Messages:
    26,099
    Resources:
    3
    Maps:
    1
    Spells:
    2
    Resources:
    3
    Where do you do anything with udg_SaveRegion[1]?

    Looks like it would be null and hence no meaningful event attached to the trigger.
     
  17. AnonymousPro

    AnonymousPro

    Joined:
    Nov 18, 2012
    Messages:
    311
    Resources:
    0
    Resources:
    0
    I am experiencing problem with the unit move to the center of the whole map area when it is suppose to go somewhere else.
    I realize if i set this trigger to activate on initialization, it will do the same thing
    Code (vJASS):

    function Trig_Trap_Enter_TrainingGround1_Actions takes nothing returns nothing
    local rect r = gg_rct_TrainingGround1
    local real mx = GetRectMinX(r)
    local real Mx = GetRectMaxX(r)
    local real my = GetRectMinY(r)
    local real My = GetRectMaxY(r)
        call SetUnitPositionLoc( GetTriggerUnit(), GetRectCenter(r) )
    //    call SetCameraBounds(mx, my, Mx, my, Mx, My, mx, My)
        call RemoveRect(r)
    endfunction

    //===========================================================================
    function InitTrig_Trap_Enter_TrainingGround1 takes nothing returns nothing
        set gg_trg_Trap_Enter_TrainingGround1 = CreateTrigger(  )
        call TriggerRegisterEnterRectSimple( gg_trg_Trap_Enter_TrainingGround1, gg_rct_TrapToMap )
        call TriggerAddAction( gg_trg_Trap_Enter_TrainingGround1, function Trig_Trap_Enter_TrainingGround1_Actions )
    endfunction

     

    why is that so


    okay and i found the problem, it happens when I change this
    Code (vJASS):

    function Trig_EnterTrainingGround1_Actions takes nothing returns nothing
        call SetUnitPositionLoc( GetTriggerUnit(), GetRectCenter(gg_rct_TrainingGround1) )
     //   call SetCameraBoundsToRectForPlayerBJ( Player(0), gg_rct_TrainingGround1 )
        call SetCameraTargetControllerNoZForPlayer( Player(0), GroupPickRandomUnit(GetUnitsInRectOfPlayer(gg_rct_TrainingGround1, Player(0))), 0, 0, false )
        call StartTimerBJ( udg_DungeonTimer, false, 600.00 )
    endfunction

    /////////////////////////////////////////INTO THIS
    function Trig_EnterTrainingGround1_Actions takes nothing returns nothing
    local rect r = gg_rct_TrainingGround1
    local real mx = GetRectMinX(r)
    local real Mx = GetRectMaxX(r)
    local real my = GetRectMinY(r)
    local real My = GetRectMaxY(r)
        call SetUnitPositionLoc( GetTriggerUnit(), GetRectCenter(r) )
    //call SetCameraBounds(mx, my, Mx, my, Mx, My, mx, My) //problematic
        call SetCameraTargetControllerNoZForPlayer( Player(0), GroupPickRandomUnit(GetUnitsInRectOfPlayer(r, Player(0))), 0, 0, false )
        call StartTimerBJ( udg_DungeonTimer, false, 600.00 )
        call RemoveRect(r)
    endfunction

    //===========================================================================
    function InitTrig_EnterTrainingGround1 takes nothing returns nothing
        set gg_trg_EnterTrainingGround1 = CreateTrigger(  )
        call TriggerRegisterEnterRectSimple( gg_trg_EnterTrainingGround1, gg_rct_TG1_Portal )
        call TriggerAddAction( gg_trg_EnterTrainingGround1, function Trig_EnterTrainingGround1_Actions )
    endfunction
     

    okay the GetRectCenter is not defined
    Okay I just solved this 2nd part
    Code (vJASS):

    function Trig_EnterTrainingGround1_Actions takes nothing returns nothing
    local rect r = gg_rct_TrainingGround1
    local real mx = GetRectMinX(r)
    local real Mx = GetRectMaxX(r)
    local real my = GetRectMinY(r)
    local real My = GetRectMaxY(r)
    local unit u = GetTriggerUnit()
    //call SetUnitPositionLoc(u , GetRectCenter(r) )
    //change to
    //
    //
    call SetUnitPosition(u,GetRectCenterX(r),GetRectCenterY(r))
    ///////////////////////////////////////////////////////////////


    //call SetCameraBounds(mx, my, Mx, my, Mx, My, mx, My) //problematic
        call SetCameraTargetControllerNoZForPlayer( Player(0), GroupPickRandomUnit(GetUnitsInRectOfPlayer(r, Player(0))), 0, 0, false )
        call StartTimerBJ( udg_DungeonTimer, false, 600.00 )

    set u = null
    endfunction

    //===========================================================================
    function InitTrig_EnterTrainingGround1 takes nothing returns nothing
        set gg_trg_EnterTrainingGround1 = CreateTrigger(  )
        call TriggerRegisterEnterRectSimple( gg_trg_EnterTrainingGround1, gg_rct_TG1_Portal )
        call TriggerAddAction( gg_trg_EnterTrainingGround1, function Trig_EnterTrainingGround1_Actions )
    endfunction
     


    I also realized removing the rect would cause it to go to middle of the map the 2nd time entering
    okay i solved that as well, just set it below locals, so it will be set again to a value when re-entering
    Code (vJASS):

    function Trig_EnterTrainingGround1_Actions takes nothing returns nothing
    local rect r
    local real mx
    local real Mx
    local real my
    local real My
    local unit u = GetTriggerUnit()
    set r= gg_rct_TrainingGround1
    set mx = GetRectMinX(r)
    set Mx = GetRectMaxX(r)
    set my = GetRectMinY(r)
    set My = GetRectMaxY(r)
    //call SetUnitPositionLoc(u , GetRectCenter(r) )
    //change to
    //
    //
    call SetUnitPosition(u,GetRectCenterX(r),GetRectCenterY(r))
    ///////////////////////////////////////////////////////////////


    //call SetCameraBounds(mx, my, Mx, my, Mx, My, mx, My) //problematic
        call SetCameraTargetControllerNoZForPlayer( Player(0), GroupPickRandomUnit(GetUnitsInRectOfPlayer(r, Player(0))), 0, 0, false )
        call StartTimerBJ( udg_DungeonTimer, false, 600.00 )
    //    call RemoveRect(r)
    //cannot remove rect or the 2nd time entering will be send to middle
    set u = null
    endfunction

    //===========================================================================
    function InitTrig_EnterTrainingGround1 takes nothing returns nothing
        set gg_trg_EnterTrainingGround1 = CreateTrigger(  )
        call TriggerRegisterEnterRectSimple( gg_trg_EnterTrainingGround1, gg_rct_TG1_Portal )
        call TriggerAddAction( gg_trg_EnterTrainingGround1, function Trig_EnterTrainingGround1_Actions )
    endfunction

     
     
    Last edited: Sep 25, 2016
  18. Dr Super Good

    Dr Super Good

    Spell Reviewer

    Joined:
    Jan 18, 2005
    Messages:
    26,099
    Resources:
    3
    Maps:
    1
    Spells:
    2
    Resources:
    3
    It is because you are moving it to the centre of a destroyed rect. The variable gg_rct_TrainingGround1 is a constant, so destroying its rect object means that the rect is gone for good and the constant has no meaning anymore.

    You also leak a location since you create a location object using GetRectCenter(r) which you never remove.

    Try...
    Code (vJASS):

    function Trig_Trap_Enter_TrainingGround1_Actions takes nothing returns nothing
        local rect r = gg_rct_TrainingGround1
        local real mx = GetRectMinX(r)
        local real Mx = GetRectMaxX(r)
        local real my = GetRectMinY(r)
        local real My = GetRectMaxY(r)
        call SetUnitPosition(GetTriggerUnit(), GetRectCenterX(r), GetRectCenterX(r))
        call SetCameraBounds(mx, my, Mx, my, Mx, My, mx, My)
        set r = null
    endfunction

    //===========================================================================
    function InitTrig_Trap_Enter_TrainingGround1 takes nothing returns nothing
        set gg_trg_Trap_Enter_TrainingGround1 = CreateTrigger(  )
        call TriggerRegisterEnterRectSimple( gg_trg_Trap_Enter_TrainingGround1, gg_rct_TrapToMap )
        call TriggerAddAction( gg_trg_Trap_Enter_TrainingGround1, function Trig_Trap_Enter_TrainingGround1_Actions )
    endfunction
     
     
  19. AnonymousPro

    AnonymousPro

    Joined:
    Nov 18, 2012
    Messages:
    311
    Resources:
    0
    Resources:
    0
    Yeah I figured that out :p
    I think the getrectcenter is already fixed with

    call SetUnitPosition(u,GetRectCenterX(r),GetRectCenterY(r))
     
  20. AnonymousPro

    AnonymousPro

    Joined:
    Nov 18, 2012
    Messages:
    311
    Resources:
    0
    Resources:
    0
    I don't know why, but it always sets the gg_rct_TG1Rdm3 to the right portal, and never changes.
    How to make it random every time when ii=ii+1?
    Code (vJASS):

    globals
    region array udg_SaveRegion
    boolean array Portal
    rect array CheckRect
    integer ii=0
    boolean bb=false
    endglobals
    function RandomPortal takes nothing returns integer
        return GetRandomInt(1,4)
    endfunction

    function SetPortalNumber takes nothing returns nothing
        local integer i = 1


        loop
     
        exitwhen i > 4
     
        //exit when portal > total quantity
            set Portal[i] = false
            set i = i+1
    //when it ends i=5      
        endloop
       
    set Portal[RandomPortal()] = true
        // Portal[x] will be true
    endfunction
    function InitRegions takes nothing returns nothing
    set udg_SaveRegion[1]=CreateRegion()
    set udg_SaveRegion[2]=CreateRegion()
    set udg_SaveRegion[3]=CreateRegion()
    set udg_SaveRegion[4]=CreateRegion()
    endfunction
    function Trig_RandomGen_Actions takes nothing returns nothing
        local unit u = GetTriggerUnit()
        local real ux = GetUnitX(u)     //Always ALWAYS avoid locations wherever you can-- they are the DEVIL in wc3 (memory leaks, slow, not useful, etc.)
        local real uy = GetUnitY(u)
        local real rxMax
        local real rxMin
        local real ryMax
        local real ryMin
        local integer i = 1
                       //local rect checks the rect at portal entrance
    loop
    exitwhen i > 4
            if i == 1 then
                set CheckRect[i] = gg_rct_TG1Rdm1
            elseif i == 2 then
                set CheckRect[i] = gg_rct_TG1Rdm2          
            elseif i == 3 then
                set CheckRect[i] = gg_rct_TG1Rdm3          
            elseif i == 4 then
                set CheckRect[i] = gg_rct_TG1Rdm4          
            endif
            call RegionAddRect(udg_SaveRegion[i],CheckRect[i])
            set rxMax = GetRectMaxX(CheckRect[i])
            set rxMin = GetRectMinX(CheckRect[i])
            set ryMax = GetRectMaxY(CheckRect[i])
            set ryMin = GetRectMinY(CheckRect[i])

            if (rxMax >= ux and ux >= rxMin) and (ryMax >= uy and uy >= ryMin) then
                //If ux and uy are within its boundary then the unit must be inside          
    if Portal[i]==false then
    //If it's the wrong portal, move the unit to HELL
    call SetUnitX(u,GetRectCenterX(gg_rct_TG1TrapPoint))
    call SetUnitY(u,GetRectCenterY(gg_rct_TG1TrapPoint))          
    set bb=true
    elseif ii==2 then
    call DisplayTimedTextToPlayer(Player(0),0,0,0,"You have Passed "+I2S(ii+1)+" times and moved to next district")
    //if >2 correct count, then set location to Area 2
    call SetUnitX(u,GetRectCenterX(gg_rct_District2Point))
    call SetUnitY(u,GetRectCenterY(gg_rct_District2Point))
              else
                 
    //if Portal[i]==true then
    //if portal is right
                 
                    set ii=ii+1 //If it's the right portal, set correct count to +1, move the unit to the center of TG1 (safe region)              
    call DisplayTimedTextToPlayer(Player(0),0,0,0,"You have Passed "+I2S(ii)+" times")
    call SetUnitX(u,GetRectCenterX(gg_rct_District1))
    call SetUnitY(u,GetRectCenterY(gg_rct_District1))
              endif
                exitwhen Portal[i]==true // leave the loop early, no need to do more
            endif

            set i = i+1
        endloop
    //call ExecuteFunc("InitTrig_RandomGen1") //causes leak, but helps in randomizing
    //call RegionAddRect(udg_SaveRegion[9],gg_rct_TrainingGround1)

    set u = null

    //call RegionClearRect(udg_SaveRegion[1],CheckRect[1])
    //call RegionClearRect(udg_SaveRegion[2],CheckRect[2])
    //call RegionClearRect(udg_SaveRegion[3],CheckRect[3])
    //call RegionClearRect(udg_SaveRegion[4],CheckRect[4])
    set CheckRect[1]=null
    set CheckRect[2]=null
    set CheckRect[3]=null
    set CheckRect[4]=null
    set udg_SaveRegion[1]=null
    set udg_SaveRegion[2]=null
    set udg_SaveRegion[3]=null
    set udg_SaveRegion[4]=null
    endfunction
    function funcfunc9 takes nothing returns boolean
    return true
    endfunction

    //should return is unit a hero but since it's not even working
    //should return is unit in region

    //===========================================================================

    function InitTrig_RandomGen1 takes nothing returns nothing
        call SetPortalNumber()
        call InitRegions()
        set gg_trg_RandomGen1 = CreateTrigger(  )
        call TriggerRegisterEnterRegion(gg_trg_RandomGen1,udg_SaveRegion[1],Condition(function funcfunc9))
        call TriggerRegisterEnterRegion(gg_trg_RandomGen1,udg_SaveRegion[2],Condition(function funcfunc9))
        call TriggerRegisterEnterRegion(gg_trg_RandomGen1,udg_SaveRegion[3],Condition(function funcfunc9))
        call TriggerRegisterEnterRegion(gg_trg_RandomGen1,udg_SaveRegion[4],Condition(function funcfunc9))
        call TriggerAddAction( gg_trg_RandomGen1, function Trig_RandomGen_Actions )
     
    endfunction