• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[vJASS] GetRectCenterY causing my wc3 to crash:S

Status
Not open for further replies.
Level 19
Joined
Oct 12, 2007
Messages
1,821
Heya.

Once again a question but this problem is pretty mysterious to me.

I was working on something to let units move in a given formation towards certain fields on the map. Since the map is devided into various rects these rects are all documented with an X and Y coordinate. Those rects are called Field[X][Y].
All units in the map have an own id that can be tracked by GetUnitId(unit), and every unit has its own X and Y coordinate based on those rects. Those integers are called Unit_X[unit id] and Unit_Y[unit id].

At first I made a typo and this caused the units to move to a weird place and I couldn't figure out why until I found out I made a typo.
Here was my mistake:

JASS:
function UnitLineUp takes unit u returns nothing
    local integer id = GetUnitId(u)
    local real x = GetRectCenterX(Field[Unit_X[id]][Unit_Y[id]])
    local real y = GetRectCenterX(Field[Unit_X[id]][Unit_Y[id]])

As you can see I used GetRectCenterX twice, resulting into wrong coordinates for the units to move to.

However, now that I changed it correctly, the map crashes whenever the UnitLineUp function is being called, while really the only thing I changed was changing an X to an Y.

I have no idea what is causing this crash.:s



Here's the full code now.

JASS:
library RegimentHandling

function UnitLineUp takes unit u returns nothing
    local integer id = GetUnitId(u)
    local real x = GetRectCenterX(Field[Unit_X[id]][Unit_Y[id]])
    local real y = GetRectCenterY(Field[Unit_X[id]][Unit_Y[id]])
    local integer Spot = Unit_Reg_Spot[id]
    local integer Size = Unit_Reg_Size[id]
    
        /// --- Regiment Size: 16 --- ///
    
        if Size == 16 then
            /// Setting the X value ///
            if Spot == 1 or Spot == 5 or Spot == 9 or Spot == 13 then
                set x = x -120.
            elseif Spot == 2 or Spot == 6 or Spot == 10 or Spot == 14 then
                set x = x -40.
            elseif Spot == 3 or Spot == 7 or Spot == 11 or Spot == 15 then
                set x = x +40.
            else
                set x = x +120.
            endif
            /// Setting the Y value ///
            if Spot > 0 and Spot < 5 then
                set y = y -120.
            elseif Spot > 4 and Spot < 9 then
                set y = y -40.
            elseif Spot > 8 and Spot < 13 then
                set y = y + 40.
            else
                set y = y + 120.
            endif
            /// Ordering the unit to move ///
            call MoveWithFace(u, x, y)
        endif
    
    set u = null
endfunction
endlibrary
 
Level 19
Joined
Oct 12, 2007
Messages
1,821
I just found out that the problem has to be somewere within the MoveWithFace function.
I checked if all Id's, coordinates and other things are right with Debugmessages.
The documentation is 100% accurate so that's not the case.
 
Level 19
Joined
Oct 12, 2007
Messages
1,821
My arrays arrays are fine.
I'm just very confused because the entire trigger works when I don't use the GetRectCenterY call...
It orders units to move and all... But with the Y call it doesn't work anymore all of a sudden.

The MoveWithFace function appears NOT to be the problem, because I replaced it with call IssuePointOrder(u, "move", x, y) and it still doesnt work...
 
Level 19
Joined
Oct 12, 2007
Messages
1,821
This is where I use the UnitLineUp function in:

JASS:
library UsingItems initializer OnInit
globals
    boolean array UsingItem[2]
    item array ItemBeingUsed[2]
endglobals

private function Actions takes nothing returns boolean
    local item t = GetManipulatedItem()
    local integer iid = GetItemTypeId(t)
    local player p = GetOwningPlayer(GetTriggerUnit())
    local integer i = MaxItems
    local integer range
    local integer id = GetPlayerId(p)
    local integer x
    local integer y
    local integer counter = 0
    local rect r
    local unit u
    
    loop
    exitwhen Item_Id[i] == iid or i == 0
        set i = i - 1
    endloop
    
    if UsingItem[id] == true then ///Second Press - Creating units
        set UsingItem[id] = false
        set SelectionMode[id] = false
        
        if Field_Pathable[SelectionX[id]][SelectionY[id]] == true then
            set r = Field[SelectionX[id]][SelectionY[id]]
            loop
            exitwhen counter == Item_Reg_Units[i]
                set u = CreateUnit(p, Item_Reg_UnitType[i], GetRectCenterX(r), GetRectCenterY(r),270. - (I2R(id)*180.))
                set Unit_Reg_Size[GetUnitId(u)] = Item_Reg_Size[i]
                set Unit_Reg_Spot[GetUnitId(u)] = counter + 1
                set Unit_X[GetUnitId(u)] = SelectionX[id]
                set Unit_Y[GetUnitId(u)] = SelectionY[id]
                call UnitLineUp(u)
                set counter = counter + 1
            endloop
            
            call RemoveItem(t)
        endif
        
        call SetAllFieldsBrown(p)
        
        
    else ///First Press - Adding Colors
        set UsingItem[id] = true
        
        call SetAllFieldsRed(p)
        
        ///Regiment///
        if Item_Classification[i] == "Regiment" then
            set SelectionMode[id] = true
            set x = 3
            if id == 0 then
                set y = 1
            else
                set y = 16
            endif
            loop
            exitwhen x > 7
                if Field_Path[x][y] == 0 then
                    set Field_Pathable[x][y] = true
                    if GetLocalPlayer() == p then
                        call ShowDestructable(Tile_Green[x][y], true)
                        call ShowDestructable(Tile_Red[x][y], false)
                    endif
                endif
            set x = x + 1
            endloop
            set SelectionX[id] = 5
            set SelectionY[id] = y 
        endif
    endif
    return false
endfunction

private function TurnCheck takes nothing returns boolean
    return PlayerTurn == GetPlayerId(GetOwningPlayer(GetTriggerUnit()))
endfunction

private function OnInit takes nothing returns nothing
    call RegisterAnyUnitEvent(EVENT_PLAYER_UNIT_USE_ITEM, function TurnCheck, function Actions)
endfunction
endlibrary

- the "///Second Press - Creating units" section is the important part.

What basically happens is this:
My Hero uses an item. That item has an id stored in an other trigger together with some variables attached to that id.
This trigger checks which item it is and checks if it is classified as a regiment.
If that's so, it will first show some colors on the map that will display where the player is able to use the item on.
When the player presses the item a second time the actual 'using' of the item will begin. This is where the map currently crashes.

The item im testing it with has this as its given settings:
JASS:
/////////////////////////////////////////
    set Item_Id[i] = 'I00M'
    set Item_Classification[i] = "Regiment"
    set Item_Reg_UnitType[i] = 'H008'
    set Item_Reg_Units[i] = 16
    set Item_Reg_Size[i] = 16
    /////////////////////////////////////////



Checking through this code now, but I can't find any bad loops or anything.



EDIT:
You know what, it might be alot easier if someone would like to take a look at what I've got in the map.
Just test the game to see what happens. During selection mode use your arrow keys to select a field on the game board.
 

Attachments

  • BoardGame.w3x
    5.3 MB · Views: 32
Status
Not open for further replies.
Top