1. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  2. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still havn't received your rank award? Then please contact the administration.
    Dismiss Notice
  3. The Lich King demands your service! We've reached the 19th edition of the Icon Contest. Come along and make some chilling servants for the one true king.
    Dismiss Notice
  4. The 4th SFX Contest has started. Be sure to participate and have a fun factor in it.
    Dismiss Notice
  5. The poll for the 21st Terraining Contest is LIVE. Be sure to check out the entries and vote for one.
    Dismiss Notice
  6. The results are out! Check them out.
    Dismiss Notice
  7. Don’t forget to sign up for the Hive Cup. There’s a 555 EUR prize pool. Sign up now!
    Dismiss Notice
  8. The Hive Workshop Cup contest results have been announced! See the maps that'll be featured in the Hive Workshop Cup tournament!
    Dismiss Notice
  9. 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:
    25,596
    Resources:
    3
    Maps:
    1
    Spells:
    2
    Resources:
    3
    Maybe the following will work? It might have syntax errors as I wrote it without a checker.
    Code (vJASS):

    globals
        region PortalSafeRegion
        region PortalAllRegion
        integer PortalSafePortal
        rect array CheckRect
        integer PortalCorrectCount = 0
    endglobals

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

    function InitPortals takes nothing returns nothing
        local integer i = 1

        set CheckRect[1] = gg_rct_TG1Rdm1
        set CheckRect[2] = gg_rct_TG1Rdm2
        set CheckRect[3] = gg_rct_TG1Rdm3
        set CheckRect[4] = gg_rct_TG1Rdm4

        set PortalSafeRegion = CreateRegion()
        set PortalAllRegion = CreateRegion()

        // add all rects to region for entry event
        loop
            exitwhen i > 4
            call RegionAddRect(PortalAllRegion, CheckRect[i])
            set i = i + 1
        endloop

        // initialize safe region
        set PortalSafePortal = RandomPortal()
        call RegionAddRect(PortalSafeRegion, CheckRect[PortalSafePortal])
    endfunction

    function Trig_RandomGen_Actions takes nothing returns nothing
        local unit u = GetTriggerUnit()

        if IsUnitInRegion(PortalSafeRegion, u) then
            // correct portal
            set PortalCorrectCount = PortalCorrectCount + 1  
            if PortalCorrectCount < 3 then
                // move to safe area
                call DisplayTimedTextToPlayer(Player(0),0,0,0,"You have Passed "+I2S(PortalCorrectCount)+" times")
                call SetUnitX(u,GetRectCenterX(gg_rct_District1))
                call SetUnitY(u,GetRectCenterY(gg_rct_District1))
            else
                // move to next district
                call DisplayTimedTextToPlayer(Player(0),0,0,0,"You have Passed "+I2S(PortalCorrectCount)+" times and moved to next district")
                call SetUnitX(u,GetRectCenterX(gg_rct_District2Point))
                call SetUnitY(u,GetRectCenterY(gg_rct_District2Point))
            endif

            // setup new random portal
            call RegionClearRect(PortalSafeRegion, CheckRect[PortalSafePortal])
            set PortalSafePortal = RandomPortal()
            call RegionAddRect(PortalSafeRegion, CheckRect[PortalSafePortal])
        else
            // wrong portal, go to hell
            call SetUnitX(u,GetRectCenterX(gg_rct_TG1TrapPoint))
            call SetUnitY(u,GetRectCenterY(gg_rct_TG1TrapPoint))
        endif

        set u = 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 InitPortals()
        set gg_trg_RandomGen1 = CreateTrigger(  )
        call TriggerRegisterEnterRegion(gg_trg_RandomGen1, PortalAllRegion, Condition(function funcfunc9))
        call TriggerAddAction( gg_trg_RandomGen1, function Trig_RandomGen_Actions )
    endfunction
     
     
  2. AnonymousPro

    AnonymousPro

    Joined:
    Nov 18, 2012
    Messages:
    311
    Resources:
    0
    Resources:
    0
    okay in local area it also don't random
    It does random the first portal. but not the 2nd or 3rd
    The InitPortals() is only called once, so it doesn't random after the first time
    and it haunts me every time I want the right portal to random after every entrance to a region

    thanks you made me learn that you can just add the region without the array number behind it.
     
    Last edited: Sep 29, 2016
  3. Dr Super Good

    Dr Super Good

    Spell Reviewer

    Joined:
    Jan 18, 2005
    Messages:
    25,596
    Resources:
    3
    Maps:
    1
    Spells:
    2
    Resources:
    3
    But it should randomly select after every correct guess...
    That is because it sets the initial state. Further randomization is done later.
    Code (vJASS):

            // setup new random portal
            call RegionClearRect(PortalSafeRegion, CheckRect[PortalSafePortal])
            set PortalSafePortal = RandomPortal()
            call RegionAddRect(PortalSafeRegion, CheckRect[PortalSafePortal])
     

    The above removes the random rect from the safe region, sets the portal to a new random portal and then adds that new portal rect to the safe region.
    After every entrance to a region? But earlier you said only after every correct guess... Which is it?
    What was there to learn? Either a variable is an array or not. Does not matter the type, except code array which throws a syntax error for security reasons.
     
  4. AnonymousPro

    AnonymousPro

    Joined:
    Nov 18, 2012
    Messages:
    311
    Resources:
    0
    Resources:
    0
    I meant it randoms after every correct entrance.
    I'm pretty sure it doesn't set new portal location because I tested it more than 5 times..
     
  5. Dr Super Good

    Dr Super Good

    Spell Reviewer

    Joined:
    Jan 18, 2005
    Messages:
    25,596
    Resources:
    3
    Maps:
    1
    Spells:
    2
    Resources:
    3
    I am pretty sure it does because I coded it to do so... Unless of course the natives used are acting in strange unpredictable ways in which case some debugging and changes will be needed. Specifically if RegionClearRect is not clearing properly (a bug with that native) it would not appear random, and as I never used the native before I cannot promise it works properly.

    If that is really the case, you will need to provide a map demonstrating the problem for further debugging. This is to rule out other possible errors. The trigger can be extracted and placed into a blank test map if necessary but it must be setup for easy testing.
     
  6. Pyrogasm

    Pyrogasm

    Joined:
    Feb 27, 2007
    Messages:
    3,056
    Resources:
    1
    Spells:
    1
    Resources:
    1
    Probably not the issue but make sure File -> Preferences -> Test Map -> Checkbox "Use Fixed Random Seed" is off.
     
  7. AnonymousPro

    AnonymousPro

    Joined:
    Nov 18, 2012
    Messages:
    311
    Resources:
    0
    Resources:
    0
    i checked RandomPortal() it gives random integers accurately.
    I think RegionClearRect is not functioning correctly, since the first entry is randomized every time. But the next entry to the same region will be the correct rect
     
  8. Dr Super Good

    Dr Super Good

    Spell Reviewer

    Joined:
    Jan 18, 2005
    Messages:
    25,596
    Resources:
    3
    Maps:
    1
    Spells:
    2
    Resources:
    3
    You will need to post a demonstration map with the system implemented and ready for testing then. This is so that it can be debugged.