HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Creatiing Units Failed

04-28-2009, 01:04 PM#1
wraithseeker
Collapse JASS:
library Initialization initializer Init

globals
    private constant integer DOLPHIN = 'h00C'
    private constant integer FISHSCHOOL = 'h00A'
    private constant integer SHARK = 'h00B'
    private real mx
    private real my
    private real bx
    private real by
endglobals

private function Actions takes nothing returns nothing
    local integer i = 0
    local unit u
    local real x
    local real y
    local boolean b
    loop
        exitwhen i > GetRandomInt(2,4)
        set x = GetRandomReal(mx,bx)
        set y = GetRandomReal(my,by)
        if not IsTerrainPathable(x,y,PATHING_TYPE_FLYABILITY) then
            set u = CreateUnit(Player(PLAYER_NEUTRAL_PASSIVE),DOLPHIN,x,y,GetRandomReal(0,360))
        else
            loop
                exitwhen b == false
                set x = GetRandomReal(mx,bx)
                set y = GetRandomReal(my,by)
                set b = IsTerrainPathable(x,y,PATHING_TYPE_FLYABILITY)
            endloop
        if b == false then
            set u = CreateUnit(Player(PLAYER_NEUTRAL_PASSIVE),DOLPHIN,x,y,GetRandomReal(0,360))
        endif
        endif
        call BJDebugMsg("UNIT IS CREATED")
        set i = i + 1
        endloop
        set u = null
endfunction

//===========================================================================
private function Init takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerAddAction(t, function Actions)
    set mx = GetRectMinX(gg_rct_Underwater)
    set my = GetRectMinY(gg_rct_Underwater)
    set bx = GetRectMaxX(gg_rct_Underwater)
    set by = GetRectMaxY(gg_rct_Underwater)
endfunction

endlibrary

What this is supposed to do is to start a loop and set x and y to a random point in a rect and checks if the point is boundary.

I am not very sure true or false is boundary but I know this detects boundary.

Collapse JASS:
  if IsTerrainPathable(x,y,PATHING_TYPE_FLYABILITY)

And when the point is boundary, it runs a loop that will exit when x and y becomes a point that is not boundary and then I do a check if b == false and create the unit. But right now, it is doing nothing at all.

Anybody have a slight clue of what is wrong?
04-28-2009, 05:05 PM#2
cosmicat
IsTerrainPathable returns true if the terrain is pathable.

Your code seems to generate a random pair of coordinates within a pathable rect, and keep doing so until it gets a random pair of coordinates that are not pathable. You might want to take out the "not" in your first if statement and exitwhen b == true in your loop, since right now I think you have an infinite loop.
04-29-2009, 05:21 AM#3
snowtiger
Quote:
Originally Posted by cosmicat
IsTerrainPathable returns true if the terrain is pathable.
Did you test that? As far as I remember, IsTerrainBuildable returned false if it was, and true if it wasn't.
04-29-2009, 05:43 AM#4
wraithseeker
Here is the current code, don't know why my screen isn't filled with BJDebugMsgs since I did a loop of 60 times and it displayed about only 6 times.

Collapse JASS:
scope test initializer Init

globals
    private constant integer DOLPHIN = 'h00C'
    private constant integer FISHSCHOOL = 'h00A'
    private constant integer SHARK = 'h00B'
    private real mx
    private real my
    private real bx
    private real by
endglobals

function Trig_Untitled_Trigger_001_Actions takes nothing returns nothing
 local integer i = 0
    local unit u
    local real x
    local real y
    local boolean b
    loop
        exitwhen i > 60
        set x = GetRandomReal(mx,bx)
        set y = GetRandomReal(my,by)
        if not IsTerrainPathable(x,y,PATHING_TYPE_FLYABILITY) then
            set u = CreateUnit(Player(PLAYER_NEUTRAL_PASSIVE),DOLPHIN,x,y,GetRandomReal(0,360))
        else
            loop
                exitwhen b == false
                set x = GetRandomReal(mx,bx)
                set y = GetRandomReal(my,by)
                set b = IsTerrainPathable(x,y,PATHING_TYPE_FLYABILITY)
            endloop
        if b == false then
            set u = CreateUnit(Player(PLAYER_NEUTRAL_PASSIVE),DOLPHIN,x,y,GetRandomReal(0,360))
            set b = true
        endif
    
        endif
        call BJDebugMsg("UNIT IS CREATED")
        set i = i + 1
        endloop
        call PanCameraToTimed(x,y,0)
endfunction

//===========================================================================
function Init takes nothing returns nothing
    local trigger t = CreateTrigger(  )
    call TriggerRegisterTimerEvent(t,2,false)
    call TriggerAddAction(t, function Trig_Untitled_Trigger_001_Actions )
     set mx = GetRectMinX(gg_rct_Underwater)
    set my = GetRectMinY(gg_rct_Underwater)
    set bx = GetRectMaxX(gg_rct_Underwater)
    set by = GetRectMaxY(gg_rct_Underwater)
endfunction

endscope
04-29-2009, 06:04 AM#5
snowtiger
Quote:
Originally Posted by wraithseeker
Here is the current code, don't know why my screen isn't filled with BJDebugMsgs since I did a loop of 60 times and it displayed about only 6 times.

Collapse JASS:
scope test initializer Init

globals
    private constant integer DOLPHIN = 'h00C'
    private constant integer FISHSCHOOL = 'h00A'
    private constant integer SHARK = 'h00B'
    private real mx
    private real my
    private real bx
    private real by
endglobals

function Trig_Untitled_Trigger_001_Actions takes nothing returns nothing
 local integer i = 0
    local unit u
    local real x
    local real y
    local boolean b
    loop
        exitwhen i > 60
        set x = GetRandomReal(mx,bx)
        set y = GetRandomReal(my,by)
        if not IsTerrainPathable(x,y,PATHING_TYPE_FLYABILITY) then
            set u = CreateUnit(Player(PLAYER_NEUTRAL_PASSIVE),DOLPHIN,x,y,GetRandomReal(0,360))
        else
            loop
                exitwhen b == false
                set x = GetRandomReal(mx,bx)
                set y = GetRandomReal(my,by)
                set b = IsTerrainPathable(x,y,PATHING_TYPE_FLYABILITY)
            endloop
        if b == false then
            set u = CreateUnit(Player(PLAYER_NEUTRAL_PASSIVE),DOLPHIN,x,y,GetRandomReal(0,360))
            set b = true
        endif
    
        endif
        call BJDebugMsg("UNIT IS CREATED")
        set i = i + 1
        endloop
        call PanCameraToTimed(x,y,0)
endfunction
You didn't give b an initial value, so it stops when it has to evaluate that (the first time it loops trough).

EDIT: so the fix is:

local boolean b = true
04-29-2009, 06:23 AM#6
wraithseeker
Like this? I just wanted to double check.
Collapse JASS:
library Initialization initializer Init

globals
    private constant integer DOLPHIN = 'h00C'
    private constant integer FISHSCHOOL = 'h00A'
    private constant integer SHARK = 'h00B'
    private real mx
    private real my
    private real bx
    private real by
endglobals

private function Actions takes nothing returns nothing
    local integer i = 0
    local unit u
    local real x
    local real y
    local boolean b = true
    loop
        exitwhen i > 60
        set x = GetRandomReal(mx,bx)
        set y = GetRandomReal(my,by)
        if not IsTerrainPathable(x,y,PATHING_TYPE_FLYABILITY) then
            set u = CreateUnit(Player(PLAYER_NEUTRAL_PASSIVE),DOLPHIN,x,y,GetRandomReal(0,360))
        else
            loop
                exitwhen b == false
                set x = GetRandomReal(mx,bx)
                set y = GetRandomReal(my,by)
                set b = IsTerrainPathable(x,y,PATHING_TYPE_FLYABILITY)
            endloop
        if b == false then
            set u = CreateUnit(Player(PLAYER_NEUTRAL_PASSIVE),DOLPHIN,x,y,GetRandomReal(0,360))
        endif
        set b = true
        endif
        call BJDebugMsg("UNIT IS CREATED")
        set i = i + 1
        endloop
        call BJDebugMsg("started")
        call PanCameraToTimed(x,y,0)
endfunction

//===========================================================================
private function Init takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterTimerEventSingle(t,2)
    call TriggerAddAction(t, function Actions)
    set mx = GetRectMinX(gg_rct_Underwater)
    set my = GetRectMinY(gg_rct_Underwater)
    set bx = GetRectMaxX(gg_rct_Underwater)
    set by = GetRectMaxY(gg_rct_Underwater)
endfunction

endlibrary
04-29-2009, 06:31 AM#7
snowtiger
Yeah, because previously, warcraft looked if b was false, but b wasn't set yet, so it stopped executing that code, = no more units created.
04-29-2009, 06:36 AM#8
Pyrogasm
Some of your code is redundant. You should do:
Collapse JASS:
library Initialization initializer Init

globals
    private constant integer DOLPHIN = 'h00C'
    private constant integer FISHSCHOOL = 'h00A'
    private constant integer SHARK = 'h00B'
    private real mx
    private real my
    private real bx
    private real by
endglobals

private function Actions takes nothing returns nothing
    local integer i = 0
    local unit u
    local real x
    local real y

    loop
        exitwhen i > 60
            loop
                set x = GetRandomReal(mx,bx)
                set y = GetRandomReal(my,by)
                exitwhen not IsTerrainPathable(x,y,PATHING_TYPE_FLYABILITY)
            endloop
        set u = CreateUnit(Player(PLAYER_NEUTRAL_PASSIVE),DOLPHIN,x,y,GetRandomReal(0,360))
        call BJDebugMsg("UNIT IS CREATED")
        set i = i + 1
    endloop
 
    call BJDebugMsg("started")
    call PanCameraToTimed(x,y,0)
endfunction

//===========================================================================
private function Init takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterTimerEventSingle(t,2)
    call TriggerAddAction(t, function Actions)
    set mx = GetRectMinX(gg_rct_Underwater)
    set my = GetRectMinY(gg_rct_Underwater)
    set bx = GetRectMaxX(gg_rct_Underwater)
    set by = GetRectMaxY(gg_rct_Underwater)
endfunction

endlibrary
04-29-2009, 06:51 PM#9
cosmicat
Quote:
Originally Posted by snowtiger
Did you test that? As far as I remember, IsTerrainBuildable returned false if it was, and true if it wasn't.
Nope, sorry. I just expected the function name to make some kind of sense. You're right - Blizzard is retarded.