HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

My logic flawed :/

09-27-2004, 02:24 AM#1
Stinky_Pooh
Code:
 function IsRoad takes unit whichunit returns boolean
    if ((GetUnitTypeId(whichunit) == 'h00E') and (GetItemName(UnitItemInSlot(whichunit, 1)) == "Connected Road")) then
        call DisplayTextToForce( GetPlayersAll(), "It is a connected road connected" )
        return true
    endif
    return false
endfunction

function IsItaRoad takes nothing returns nothing
    //requires a global, boolean udg_Roads_OnRoad
    if (IsRoad(GetEnumUnit())) then
        call DisplayTextToForce( GetPlayersAll(), "Found a road" )
        set udg_Roads_OnRoad = true
    endif
endfunction

function IsAttachedToRoad takes unit who, integer size returns boolean
    //size = 1 for a 4x4, 2 for a 8x8
    // ======
    // =1 22=
    // =  22=
    // ======
    //requires two globals, udg_Roads_TemplateSize1;udg_Roads_TemplateSize2
    local location unitspot = GetUnitLoc (who)
    set udg_Roads_OnRoad = false
    if (size==1) then
        call DisplayTextToForce( GetPlayersAll(), "Got Size 1" )
        call MoveRectTo(udg_Roads_TemplateSize1, GetLocationX(unitspot), GetLocationY(unitspot))
        call ForGroupBJ(GetUnitsInRectAll(udg_Roads_TemplateSize1), function IsItaRoad)        
    endif
    if (size==2) then
        call MoveRectTo(udg_Roads_TemplateSize2, GetLocationX(unitspot), GetLocationY(unitspot))
        call ForGroupBJ(GetUnitsInRectAll(udg_Roads_TemplateSize2), function IsItaRoad)
    endif
    if (udg_Roads_OnRoad==true) then
        return true
    endif
    return false
endfunction

function RoadBuilt takes unit road returns nothing
    if (IsAttachedToRoad ( road , 1 ) == true ) then
        call UnitAddItemSwapped ( CreateItem ('I007',0,0), road)
    else
        call UnitAddItemSwapped ( CreateItem ('I008',0,0), road)
    endif
endfunction 

uh, so if i call RoadBuilt, shouldn't a the very least it put item 'I008' in "road"s inventory? cause, it will display "Got Size 1" tag, so i know its sorta working, however, it doesn't put ANY item into the built road, and i would like to know why...

Notes :
I007 is Connected Road, I008 is Not Connected Road (both items)
udg_Roads_TemplateSize1 is a rect that is 12x12 pathing "squares" (a house is 4x4, so is a road)
udg_Roads_TemplateSize2 is a rect that is 16x16 (allowing for a 8x8 center unit to see if there is road around it, not to hard of a consept i hope, only it doesn't work :()
09-27-2004, 04:46 PM#2
RaeVanMorlock
Rather than calling UnitAddItemSwapped, you might have better luck with calling this function:

UnitAddItemById takes unit whichUnit, integer itemId returns item


I'll take a closer look in a minute, I'm not sure why it wouldn't be adding the item unless either
1) using CreateItem within UnitAddItemSwapped produces a bug
or
2) the unit 'road' is somehow invalid.

You might want to test the result of the function call by assigning a boolean value to it and then displaying it to the screen.



UPDATE:
Also, what output are you getting? And where's your call to RoadBuilt()?
09-28-2004, 01:02 AM#3
Stinky_Pooh
Quote:
Originally Posted by RaeVanMorlock

UPDATE:
Also, what output are you getting? And where's your call to RoadBuilt()?

call DisplayTextToForce( GetPlayersAll(), "Got Size 1" ) i get this output, the Got Size 1 displays, so i know that its being called correctly, i call it when the unit is built, or created. The Got Size 1 appears in both cases... BUT it never calls call DisplayTextToForce( GetPlayersAll(), "It is a connected road connected" ) which would be ok if it was just giving me a negative all time, then i would at least know parts of it are working, but im not going to change my code if NOTHING happens after the Got Size 1 thing... its so freaken gay i wanna scream.
09-28-2004, 11:21 PM#4
RaeVanMorlock
Quote:
Originally Posted by Stinky_Pooh
call DisplayTextToForce( GetPlayersAll(), "Got Size 1" ) i get this output, the Got Size 1 displays, so i know that its being called correctly, i call it when the unit is built, or created. The Got Size 1 appears in both cases... BUT it never calls call DisplayTextToForce( GetPlayersAll(), "It is a connected road connected" ) which would be ok if it was just giving me a negative all time, then i would at least know parts of it are working, but im not going to change my code if NOTHING happens after the Got Size 1 thing... its so freaken gay i wanna scream.


Well, all the other code aside, you should definitely get at least one of the items. Make a temporary function that just gives you an item using either of your ItemSwapped function calls and make sure it works that way.
09-29-2004, 05:16 PM#5
Stinky_Pooh
Quote:
Originally Posted by RaeVanMorlock
And where's your call to RoadBuilt()?

Heh, oops, im an idiot, i called it.. with constructed unit when it was a created unit, and with created unit when it was constructed... so naturally, it gave item, to the wrong unit. Also a few bugs were there but they all fixed now.. i hate programming, 20 min to write the logic, 4 hours to debug (im a comp sci major, and jass is seriously f'en up my java, i think first function spellchecker takes string returns boolean, then have to change it to java O_o im to stupid for this)

Code:
function IsRoad takes unit whichunit returns boolean
    call DisplayTextToForce( GetPlayersAll(), "Seeing if it has good item" )
    if ((GetUnitTypeId(whichunit) == 'h00E') and (GetItemName(UnitItemInSlotBJ(whichunit,1)) == "Connected Road")) then
        //call DisplayTextToForce( GetPlayersAll(), "It is a connected road" )
        return true
    endif
    return false
endfunction

function IsItaRoad takes nothing returns nothing
    //requires a global, boolean udg_Roads_OnRoad
    //call DisplayTextToForce( GetPlayersAll(), "Checking a unit" )
    if (IsRoad(GetEnumUnit()) == true) then
        //call DisplayTextToForce( GetPlayersAll(), "Returning True" )
        set udg_Roads_OnRoad = true
    endif
endfunction

function IsAttachedToRoad takes unit who, integer size returns boolean
    //size = 1 for a 4x4, 2 for a 8x8
    // ======
    // =1 22=
    // =  22=
    // ======
    //requires two globals, udg_Roads_TemplateSize1;udg_Roads_TemplateSize2
    local location unitspot = GetUnitLoc (who)
    set udg_Roads_OnRoad = false
    if (size==1) then
        //call DisplayTextToForce( GetPlayersAll(), "Got Size 1" )
        call MoveRectToLoc( udg_Roads_TemplateSize1, unitspot )
        //call DisplayTextToForce( GetPlayersAll(), "Moved Location" )
        call ForGroupBJ(GetUnitsInRectAll(udg_Roads_TemplateSize1), function IsItaRoad)        
    endif
    if (size==2) then
        call MoveRectToLoc( udg_Roads_TemplateSize2, unitspot )
        call ForGroupBJ(GetUnitsInRectAll(udg_Roads_TemplateSize2), function IsItaRoad)
    endif
    if (udg_Roads_OnRoad==true) then
        return true
    endif
    return false
endfunction

function RoadBuilt takes unit road returns nothing
    if (IsAttachedToRoad ( road , 1 ) == true ) then
        call UnitAddItemSwapped ( CreateItem ('I007',0,0), road)
    else
        call UnitAddItemSwapped ( CreateItem ('I008',0,0), road)
    endif
endfunction

This is new code, could u tell me how to make it leak free?
09-29-2004, 07:03 PM#6
RaeVanMorlock
Quote:
Originally Posted by Stinky_Pooh
This is new code, could u tell me how to make it leak free?

Cubasis wrote an excellent tutorial on that here.
09-30-2004, 04:17 AM#7
Stinky_Pooh
Quote:
Originally Posted by RaeVanMorlock
Cubasis wrote an excellent tutorial on that here.

I've read that many times, unfortunatly i have no idea how to apply that to my map, the group thats i call, i dont set to any particular variable, so how do i destroy it?
09-30-2004, 04:30 AM#8
Rafael Br
The function IsAttachedToRoad is the only that have several leaks, it will look like this removing the leaks:

Code:
function IsAttachedToRoad takes unit who, integer size returns boolean
    //size = 1 for a 4x4, 2 for a 8x8
    // ======
    // =1 22=
    // =  22=
    // ======
    //requires two globals, udg_Roads_TemplateSize1;udg_Roads_TemplateSize2
    local location unitspot = GetUnitLoc (who)
    local group TempGroup
    set udg_Roads_OnRoad = false
    if (size==1) then
        //call DisplayTextToForce( GetPlayersAll(), "Got Size 1" )
        call MoveRectToLoc( udg_Roads_TemplateSize1, unitspot )
        set TempGroup = GetUnitsInRectAll(udg_Roads_TemplateSize1)
        //call DisplayTextToForce( GetPlayersAll(), "Moved Location" )
        call ForGroupBJ(TempGroup, function IsItaRoad)
        call RemoveLocation(unitspot)
        call DestroyGroup(TempGroup)        
    endif
    if (size==2) then
        call MoveRectToLoc( udg_Roads_TemplateSize2, unitspot )
        set TempGroup = GetUnitsInRectAll(udg_Roads_TemplateSize2)
        call ForGroupBJ(TempGroup, function IsItaRoad)
        call RemoveLocation(unitspot)
        call DestroyGroup(TempGroup)
    endif
    if (udg_Roads_OnRoad==true) then
        return true
    endif
    return false
endfunction
09-30-2004, 12:49 PM#9
RaeVanMorlock
Quote:
Originally Posted by Stinky_Pooh
I've read that many times, unfortunatly i have no idea how to apply that to my map, the group thats i call, i dont set to any particular variable, so how do i destroy it?

As Rafael Br demonstrated, you'll have to change your code to assign the group to a variable so that you can destroy it afterwards. You should pretty much always assign things to variables in order to use them. People commonly use Temp<VarType> to achieve this: TempPoint, TempGroup, TempReal, etc. That way it's evident that they have no real significance in your code, can be destroyed, and used again later.
09-30-2004, 04:27 PM#10
Stinky_Pooh
Thank you very much guys... so basically no more enum units? how do i make unit groups when it has nothing to do with a rectangle?....