• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[JASS] Take a look at me code please =)

Status
Not open for further replies.
Level 3
Joined
May 1, 2007
Messages
29
Wellllllll.....I haven't a danmdest clue why this wont work. The problem is this. We have caves, and when we kill the rubble in front of the cave the caves is "open", when we destroy a dummy object you collapse the cave and thuse closing it. This all works well and good, BUT the problem is this. Units are suppose to spawn when the cave is considered "open" and not spawn when it is "closed". Only problem is that it seems as if after i initlilize the values the caves wont change from being closed or open.

Code for the caves
JASS:
function SetCaveOpen takes location l returns nothing
call SetHandleInt(l, "open", 1)
endfunction


function SetCaveClosed takes location l returns nothing
call SetHandleInt(l, "open", 2)
endfunction


function IsCaveOpen takes location cave returns boolean
if GetHandleInt(cave, "open") == 1 then
return true
else
return false
endif
endfunction


function CloseCave takes unit u returns nothing
local location temp = GetUnitLoc(u)

//call KillUnit(u)
call SetCaveClosed(temp)
call SetCaveCreepProgression(I2R(0), GetUnitLoc(u))

call CreateUnitAtLoc(Player(15), GetCaveClosedId(), temp, I2R(0))
set temp = null
endfunction

//////////////////////////////////////////

function OpenCave takes unit u returns nothing
local location temp = GetUnitLoc(u)
//call DisplayTextToPlayer(Player(0), 0,0, "New Unit Loc is"  + R2S(GetLocationX(temp)) + "," +  R2S(GetLocationY(temp))) 
//call KillUnit(u)
call CreateUnitAtLoc(Player(15), GetCaveOpenId(), temp, I2R(0))
call SetCaveOpen(temp)
call SetCaveCreepProgression(GetCreepSpeed(), temp)
set temp = null
endfunction 


function Trig_Caves takes nothing returns nothing

if(GetUnitTypeId(GetTriggerUnit()) == GetCaveClosedId()) then
    call OpenCave(GetTriggerUnit())
else
    call CloseCave(GetTriggerUnit())
endif    
endfunction


function InitTrig_Caves takes nothing returns nothing
    set gg_trg_Caves = CreateTrigger()
    call TriggerRegisterPlayerUnitEvent(gg_trg_Caves,Player(15), EVENT_PLAYER_UNIT_DEATH , null)
    call TriggerAddCondition(gg_trg_Caves, Condition(function Trig_UnitCaveCheck))
    call TriggerAddAction(gg_trg_Caves, function Trig_Caves)
endfunction
Code that uses Cave info

JASS:
function SpawnWeak takes nothing returns nothing
local integer i = 0

loop
exitwhen i > udg_numCaves
if IsCaveOpen(udg_Caves[i]) then
    call SpawnZerglings(udg_Caves[i])
    call SpawnHydralisks(udg_Caves[i])
else
call DisplayTextToPlayer(Player(0), 0,0, "CaveClosed!" + R2S(GetLocationX(udg_Caves[i])) + "," + R2S(GetLocationY(udg_Caves[i])))
endif

set i = i + 1
endloop

endfunction

function SpawnMedium takes nothing returns nothing
local integer i = 0
loop
exitwhen i > udg_numCaves
if IsCaveOpen(udg_Caves[i]) then
    call SpawnZerglings(udg_Caves[i])
    call SpawnHydralisks(udg_Caves[i])
else
call DisplayTextToPlayer(Player(0), 0,0, "CaveClosed!" + R2S(GetLocationX(udg_Caves[i])) + "," + R2S(GetLocationY(udg_Caves[i])))
endif
set i = i + 1
endloop

endfunction

function SpawnHard takes nothing returns nothing
local integer i = 0
loop
exitwhen i > udg_numCaves

if IsCaveOpen(udg_Caves[i]) then
    call SpawnZerglings(udg_Caves[i])
    call SpawnHydralisks(udg_Caves[i])
    call SpawnUltralisks(udg_Caves[i])
endif

set i = i + 1
endloop

endfunction

function wave takes nothing returns nothing
if udg_GameStage == 1  then
//call CreepProgression()
call SpawnWeak()
elseif udg_GameStage == 2   then
//call CreepProgression()
call SpawnMedium()
elseif udg_GameStage == 3   then
//call CreepProgression()
call SpawnHard()
endif
//call CreepProgression()    
endfunction

function Trig_Waves takes nothing returns nothing
local integer i = 0
set udg_Wave = CreateTrigger()
call TriggerAddAction(udg_Wave, function wave)


if GetGameMode() == 2 then
    call TriggerSleepAction(10)
    call StageIncreased()
    loop
    exitwhen i > GetWavesPerStage()
    call TriggerExecute(udg_Wave)
    call TriggerSleepAction(20)
    endloop
    call StageIncreased()
    set i = 0
    loop
    exitwhen i > GetWavesPerStage()
    call TriggerExecute(udg_Wave)
    call TriggerSleepAction(20)
    endloop
    call StageIncreased()
    set i = 0
    loop
    exitwhen i > 10000
    call TriggerExecute(udg_Wave)
    call TriggerSleepAction(20)
    endloop
endif
endfunction

function InitTrig_Waves takes nothing returns nothing
    set gg_trg_Waves = CreateTrigger()
    call TriggerRegisterTimerEventSingle(gg_trg_Waves, 4.00)
    call TriggerAddAction(gg_trg_Waves, function Trig_Waves)
endfunction

Now i am 99.9% sure that the problem lies within the IsCaveOpen function. But i have checked it a ton and have no idea. My only theory is that the sethandlehandle function when using like a location doesn;t define the string based of the data but the memory location. But if thats true....BGSDFSAADASDA

Whatever. And don't say be more specific or something cause if your confused you won't be able to answer my question.
 
Last edited by a moderator:
Level 5
Joined
May 5, 2007
Messages
120
...

If you're "99.9% sure that the problem lies within the IsCaveOpen function", try this:
function IsCaveOpen takes location cave returns boolean
return GetHandleInt(cave, "open") == 1
endfunction

That didn't fix his problem, btw.

There's another solution I gave him, but it requires starting over. :p
 
Level 5
Joined
Feb 16, 2006
Messages
151
Don't use locations for such things, the location of a different unit is always another location, even if it has the same X/Y.
Like, after each GetUnitLoc(unit) you would create a new location, it's like an invisible object.
Use global boolean array instead and SetHandleInt the cave id into the dummy units
JASS:
globals
    boolean array udg_Cave_Open
endglobals
...    
function Map_init takes nothing returns nothing
    call SetHandleInt(CAVE_DUMMY_1,"Cave ID",1)
    call SetHandleInt(CAVE_DUMMY_2,"Cave ID",2)
    ...
endfunction

function SetCaveClosed takes integer i returns nothing
    set udg_Cave_Open[i] = false
endfunction

function CloseCave takes unit u returns nothing
    call SetCaveClosed(GetHandleInt(u,"Cave ID"))
endfunction

Or, just use lot of global triggers for each Cave Dummy death...
 
Level 3
Joined
May 1, 2007
Messages
29
Yeah i figured out that much. Wasn't sure when i wrote the code exactly how jass deals with it, but i thought that was my issue. I have fixed it, and it is no longer an issue. Thanks for responses. Oh and i used rects instead which worked out. Btw UnMi, I posted this thinking that was the issue, but not completely sure. I really wanted to see if others on here truly could live up to the talk that they talk =). You seem like a talented programmer to me :)
 
Status
Not open for further replies.
Top