• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[vJASS] Creeps

Status
Not open for further replies.
Level 3
Joined
Oct 17, 2013
Messages
29
Why wont this work?
- Creeps
- it doesn't initialize
- it's mean't to create units(complete) and, moveloop(incomplete).
- psss. I'm new to this so don't expect me to write structs and modules and such.
- :vw_wtf:
JASS:
library Creeps /*
            */  initializer Init
                 //requires 
                      //GroupUtils 
                      //RandomRectXY
                      //AutoIndex
                    
    globals
        /*         Constants       */
        /*         Time Interval - Lesser for Better Performance, Higher for Lesser Lag Spikes 
        0.50 - 2.00 */  private constant real MOVE_INTERVAL     = 0.90
        /*  Spawn Interval, Distance - 30 to 90 */
        private constant real SPAWN_INTERVAL    = 60.00
        /*        Player Id        */
        private constant player DP = Player(5)
        private constant player EP = Player(11)
        /*         Unit Id         */
        private constant integer DMid = 'Hmkg'
        private constant integer DRid = 'Emoo'
        private constant integer EMid = 'Edem'
        private constant integer ERid = 'Hblm'
        /*         Trigger         */
        /*        Region/Rect      */
        private rect DSpawnRect
        private rect ESpawnRect
        private rect array TopMoveRect
        private rect array MidMoveRect
        private rect array BotMoveRect
        /*         Timer           */
        private timer SpawnTimer = CreateTimer()
        /*      End Constants      */
        private boolean Spawning
        private integer SpawnTime
        private integer SpawnCount
        private boolean array TopLane
        private boolean array MidLane
        private boolean array BotLane
        private real array Cx
        private real array Cy
        private real array Mx
        private real array My
        
    endglobals
    
    private function SpawnUnits takes nothing returns nothing
        if SpawnTime <= SPAWN_INTERVAL then
            set SpawnTime = SpawnTime + 1
            call DisplayTextToForce( GetPlayersAll(), "SpawnTime = " + R2S(SpawnTime) )
        else
            set SpawnTime = 0
            set Spawning = true
            call DisplayTextToForce( GetPlayersAll(), "Spawning" )
        endif
        if Spawning == true then
            call DisplayTextToForce( GetPlayersAll(), "SpawnCount = " + R2S(SpawnCount) )
            set SpawnCount = SpawnCount + 1
            set Cx[1] = GetRectCenterX(DSpawnRect)
            set Cy[1] = GetRectCenterY(DSpawnRect)
            set Cx[2] = GetRectCenterX(ESpawnRect)
            set Cy[2] = GetRectCenterY(ESpawnRect)
            set Mx[1] = GetRectCenterX(TopMoveRect[1])
            set My[1] = GetRectCenterY(TopMoveRect[1])
            set Mx[2] = GetRectCenterX(ESpawnRect)
            set My[2] = GetRectCenterY(ESpawnRect)
            set Mx[3] = GetRectCenterX(BotMoveRect[1])
            set My[3] = GetRectCenterY(BotMoveRect[1])
            set Mx[4] = GetRectCenterX(TopMoveRect[2])
            set My[4] = GetRectCenterY(TopMoveRect[2])
            set Mx[5] = GetRectCenterX(ESpawnRect)
            set My[5] = GetRectCenterY(ESpawnRect)
            set Mx[6] = GetRectCenterX(BotMoveRect[2])
            set My[6] = GetRectCenterY(BotMoveRect[2])
            if SpawnCount <= 5 then
                call CreateUnit(DP,DMid,Cx[1],Cy[1],0.00)
                set TopLane[GetUnitId(bj_lastCreatedUnit)] = true
                call IssuePointOrder(bj_lastCreatedUnit,"attack",Mx[1],My[1])
                call CreateUnit(EP,EMid,Cx[2],Cy[2],180.00)
                set TopLane[GetUnitId(bj_lastCreatedUnit)] = true
                call IssuePointOrder(bj_lastCreatedUnit,"attack",Mx[4],My[4])
                call CreateUnit(DP,DMid,Cx[1],Cy[1],0.00)
                set MidLane[GetUnitId(bj_lastCreatedUnit)] = true
                call IssuePointOrder(bj_lastCreatedUnit,"attack",Mx[2],My[2])
                call CreateUnit(EP,EMid,Cx[2],Cy[2],180.00)
                set MidLane[GetUnitId(bj_lastCreatedUnit)] = true
                call IssuePointOrder(bj_lastCreatedUnit,"attack",Mx[5],My[5])
                call CreateUnit(DP,DMid,Cx[1],Cy[1],0.00)
                set BotLane[GetUnitId(bj_lastCreatedUnit)] = true
                call IssuePointOrder(bj_lastCreatedUnit,"attack",Mx[3],My[3])
                call CreateUnit(EP,EMid,Cx[2],Cy[2],180.00)
                set BotLane[GetUnitId(bj_lastCreatedUnit)] = true
                call IssuePointOrder(bj_lastCreatedUnit,"attack",Mx[6],My[6])
            else
                call CreateUnit(DP,DRid,Cx[1],Cy[1],0.00)
                set TopLane[GetUnitId(bj_lastCreatedUnit)] = true
                call IssuePointOrder(bj_lastCreatedUnit,"attack",Mx[1],My[1])
                call CreateUnit(EP,ERid,Cx[2],Cy[2],180.00)
                set TopLane[GetUnitId(bj_lastCreatedUnit)] = true
                call IssuePointOrder(bj_lastCreatedUnit,"attack",Mx[4],My[4])
                call CreateUnit(DP,DRid,Cx[1],Cy[1],0.00)
                set MidLane[GetUnitId(bj_lastCreatedUnit)] = true
                call IssuePointOrder(bj_lastCreatedUnit,"attack",Mx[2],My[2])
                call CreateUnit(EP,ERid,Cx[2],Cy[2],180.00)
                set MidLane[GetUnitId(bj_lastCreatedUnit)] = true
                call IssuePointOrder(bj_lastCreatedUnit,"attack",Mx[5],My[5])
                call CreateUnit(DP,DRid,Cx[1],Cy[1],0.00)
                set BotLane[GetUnitId(bj_lastCreatedUnit)] = true
                call IssuePointOrder(bj_lastCreatedUnit,"attack",Mx[3],My[3])
                call CreateUnit(EP,ERid,Cx[2],Cy[2],180.00)
                set BotLane[GetUnitId(bj_lastCreatedUnit)] = true
                call IssuePointOrder(bj_lastCreatedUnit,"attack",Mx[6],My[6])
            endif
            if SpawnCount == 8 then
                set Spawning = false
            endif
        endif
    endfunction
    
    private function MoveLoop takes nothing returns nothing
        
    endfunction
    
    private function Init takes nothing returns nothing
        local trigger t = CreateTrigger()
        call TimerStart(SpawnTimer, 1.00, true, function SpawnUnits)
        call TriggerRegisterTimerEventPeriodic(t, 1.00)
        call TriggerAddAction(t, function SpawnUnits)
        /*        SpawnUnits      */
        set DSpawnRect = gg_rct_Spawn_Mid_1
        set ESpawnRect = gg_rct_Spawn_Mid_2
        set TopMoveRect[1] = gg_rct_Move_Top_1
        set TopMoveRect[2] = gg_rct_Move_Top_2
        set BotMoveRect[1] = gg_rct_Move_Bot_1
        set BotMoveRect[2] = gg_rct_Move_Bot_2
    endfunction
endlibrary
 

Attachments

  • Creeps.w3x
    169.3 KB · Views: 64
Last edited:

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,202
You need to initialisize integers if you want to read them out. Set them to 0.
To clarify, this only applies to non arrays if I recall, with arrays always being 0 initialized. WC3 really has some strange behaviour at times.

Even still, it is always good practice to initialize variables before use. Any resources this could possibly waste is trivial and is more than compensated by easier maintainability and less chances of errors.
 
Level 3
Joined
Oct 17, 2013
Messages
29
initialisize
i don't know what you mean
To clarify, this only applies to non arrays if I recall, with arrays always being 0 initialized. WC3 really has some strange behaviour at times.

Even still, it is always good practice to initialize variables before use. Any resources this could possibly waste is trivial and is more than compensated by easier maintainability and less chances of errors.
I can't understand. I mean, whats there to initialize? the integers of the spawned units, SpawnTime or SpawnCount?
// ugh. so tiring
 
Level 6
Joined
Jun 18, 2004
Messages
119
every variable that you want to READ (i.e., if variableInt > 0 then, or anything else except for set variableInt = ) needs to have a value assigned first. If you only declare the variable it will crash the thread upon the read (which means, the code stops executing).

This will not function (does not display ANY message):
JASS:
function test takes nothing returns nothing
    local integer i
    if i > 0 then
       call BJDebugMsg("runs true!")
    else
       call BJDebugMsg("runs false!")
    endif
endfunction
the correct first line would be
JASS:
local integer i = 0 //first initialize if it is read afterwards.

This applies to globals in the same way.
 
Level 3
Joined
Oct 17, 2013
Messages
29
every variable that you want to READ (i.e., if variableInt > 0 then, or anything else except for set variableInt = ) needs to have a value assigned first. If you only declare the variable it will crash the thread upon the read (which means, the code stops executing).

This will not function (does not display ANY message):
JASS:
function test takes nothing returns nothing
    local integer i
    if i > 0 then
       call BJDebugMsg("runs true!")
    else
       call BJDebugMsg("runs false!")
    endif
endfunction
the correct first line would be
JASS:
local integer i = 0 //first initialize if it is read afterwards.

This applies to globals in the same way.

Then i have to initialize the global integers in the initialization function first like this?
JASS:
set SpawnCount = 0
set SpawnTime = 0
and the unit id's?
if so then i have to remove the constant and set this in the initialization too
JASS:
set DMid = 0
set DRid = 0
set EMid = 0
set ERid = 0
// and set unit ids
set DMid = 'Edem'
set DRid = 'Hpal'
set EMid = 'Hblm'
set ERid = 'Oblm'
Is that good?
 
This is an issue which tends to affect everyone when switching from GUI. GUI globals are auto-initialized to null/0/false so you never had to think about this before. Solution: change the global declarations for your non-arrays:

private boolean Spawning = false
private integer SpawnTime = 0
private integer SpawnCount = 0

Arrays in JASS are a funny thing. You don't need to initialize each index, but if you are re-using array indices you'll want to reset any apllicable array indices back to 0/null/false.

Then i have to initialize the global integers in the initialization function first like this?
JASS:
set SpawnCount = 0
set SpawnTime = 0
and the unit id's?
if so then i have to remove the constant and set this in the initialization too
JASS:
set DMid = 0
set DRid = 0
set EMid = 0
set ERid = 0
// and set unit ids
set DMid = 'Edem'
set DRid = 'Hpal'
set EMid = 'Hblm'
set ERid = 'Oblm'
Is that good?

Unnecessary. Set them to 0 when you declare them. For arrays, that might be necessary. While you're learning, you may just want to ask for clarification regarding arrays on a case-by-case basis. For normal variables, take the rule of thumb to just set everything to 0/false/null whenever you declare a non-array variable.
 
Level 3
Joined
Oct 17, 2013
Messages
29
This is an issue which tends to affect everyone when switching from GUI. GUI globals are auto-initialized to null/0/false so you never had to think about this before.
Oh. Sorry actually i know that you should put = null/0/false but i think i was in rush or just sleepy that i mixed it with all other globals.
Arrays in JASS are a funny thing. You don't need to initialize each index, but if you are re-using array indices you'll want to reset any apllicable array indices back to 0/null/false.
yeah. will do

Unnecessary. Set them to 0 when you declare them. For arrays, that might be necessary. While you're learning, you may just want to ask for clarification regarding arrays on a case-by-case basis. For normal variables, take the rule of thumb to just set everything to 0/false/null whenever you declare a non-array variable.
thanks for pointing out.
Edit:
Maybe tomorrow, my session's up.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,202
vJASS non-array globals can be initialized at declaration. This is because JASS does support initialization inside the global block and vJASS globals inline into that block.

Global arrays should automatically me initialized to 0 or null and should not cause a thread crash when accessed.
 
Last edited:

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,202
Go drunk DSG, you're home.
Or maybe my home is not drunk enough... hmmm...

JASS:
globals
    integer test1
    integer array test2
endglobals

function TestUninitializedGlobals takes nothing returns nothing
    local integer test3
    local integer array test4
    call BJDebugMsg("global variable test")
    call BJDebugMsg(I2S(test1)) // will cause thread crash
    call BJDebugMsg("global variable array test")
    call BJDebugMsg(I2S(test2[8191])) // this works
    call BJDebugMsg("local variable test")
    call BJDebugMsg(I2S(test3)) // will cause thread crash
    call BJDebugMsg("local variable array test")
    call BJDebugMsg(I2S(test4[8191])) // this works
endfunction
Arrays are automatically initialized to 0/null so can be used without prior assignment. It is still good practice to initialize them, especially since you often do not want initial values of 0 so forgetting to assign them causes an error.
 
Status
Not open for further replies.
Top