This project is read-only.

IndexOutOfRangeException Obstruction Cells

Jan 30, 2013 at 3:56 AM

I am attempting to create a path for the creeps to travel by using Obstruction cells 

When I do this I run into the below error

At the time of this error the following values were
IndexY = 11
Columns = 19
indexX = 4


namespace Coding4Fun.ScriptTD.Engine.Logic
    public class Grid
        public Cell this[int indexX, int indexY]
            get { return CellArray[(indexY * Columns) + indexX]; }

File 1.xml
      <Cell CellId="spawn" Type="Entrance" X="0" Y="4" />
      <Cell CellId="exit" Type="Exit" X="18" Y="6" />
    <Cell CellId="04" Type="Obstruction" X="0" Y="4" />
    <Cell CellId="14" Type="Obstruction" X="1" Y="4" />
    <Cell CellId="24" Type="Obstruction" X="2" Y="4" />
    <Cell CellId="34" Type="Obstruction" X="3" Y="4" />
    <Cell CellId="44" Type="Obstruction" X="4" Y="4" />
    <Cell CellId="54" Type="Obstruction" X="5" Y="4" />
    <Cell CellId="06" Type="Obstruction" X="0" Y="6" />
    <Cell CellId="16" Type="Obstruction" X="1" Y="6" />
    <Cell CellId="26" Type="Obstruction" X="2" Y="6" />
    <Cell CellId="36" Type="Obstruction" X="3" Y="6" />
    <Cell CellId="46" Type="Obstruction" X="4" Y="6" />
    <Cell CellId="64" Type="Obstruction" X="6" Y="4" />
    <Cell CellId="65" Type="Obstruction" X="6" Y="5" />
    <Cell CellId="66" Type="Obstruction" X="6" Y="6" />
    <Cell CellId="67" Type="Obstruction" X="6" Y="7" />
    <Cell CellId="47" Type="Obstruction" X="4" Y="7" />
    <Cell CellId="48" Type="Obstruction" X="4" Y="8" />
    <Cell CellId="49" Type="Obstruction" X="4" Y="9" />
    <Cell CellId="410" Type="Obstruction" X="4" Y="10" />
    <Cell CellId="68" Type="Obstruction" X="6" Y="8" />
    <Cell CellId="69" Type="Obstruction" X="6" Y="9" />
    <Cell CellId="411" Type="Obstruction" X="4" Y="11" />
    <Cell CellId="511" Type="Obstruction" X="5" Y="11" />
    <Cell CellId="611" Type="Obstruction" X="6" Y="11" />
    <Cell CellId="711" Type="Obstruction" X="7" Y="11" />
    <Cell CellId="79" Type="Obstruction" X="7" Y="9" />
    <Cell CellId="89" Type="Obstruction" X="8" Y="9" />
    <Cell CellId="99" Type="Obstruction" X="9" Y="9" />
    <Cell CellId="98" Type="Obstruction" X="9" Y="8" />
    <Cell CellId="97" Type="Obstruction" X="9" Y="7" />
    <Cell CellId="96" Type="Obstruction" X="9" Y="6" />
    <Cell CellId="106" Type="Obstruction" X="10" Y="6" />
    <Cell CellId="811" Type="Obstruction" X="8" Y="11" />
    <Cell CellId="911" Type="Obstruction" X="9" Y="11" />
    <Cell CellId="1011" Type="Obstruction" X="10" Y="11" />
    <Cell CellId="1111" Type="Obstruction" X="11" Y="11" />
    <Cell CellId="1110" Type="Obstruction" X="11" Y="10" />
    <Cell CellId="119" Type="Obstruction" X="11" Y="9" />
    <Cell CellId="118" Type="Obstruction" X="11" Y="8" />
    <Cell CellId="116" Type="Obstruction" X="11" Y="6" />
    <Cell CellId="126" Type="Obstruction" X="12" Y="6" />
    <Cell CellId="136" Type="Obstruction" X="13" Y="6" />
    <Cell CellId="128" Type="Obstruction" X="12" Y="8" />
    <Cell CellId="138" Type="Obstruction" X="13" Y="8" />
    <Cell CellId="146" Type="Obstruction" X="14" Y="6" />
    <Cell CellId="156" Type="Obstruction" X="15" Y="6" />
    <Cell CellId="148" Type="Obstruction" X="14" Y="8" />
    <Cell CellId="158" Type="Obstruction" X="15" Y="8" />
    <Cell CellId="159" Type="Obstruction" X="15" Y="9" />
    <Cell CellId="1510" Type="Obstruction" X="15" Y="10" />
    <Cell CellId="1511" Type="Obstruction" X="15" Y="11" />
    <Cell CellId="1512" Type="Obstruction" X="15" Y="12" />
    <Cell CellId="1513" Type="Obstruction" X="15" Y="13" />
    <Cell CellId="166" Type="Obstruction" X="16" Y="6" />
    <Cell CellId="176" Type="Obstruction" X="17" Y="6" />
    <Cell CellId="177" Type="Obstruction" X="17" Y="7" />
    <Cell CellId="178" Type="Obstruction" X="17" Y="8" />
    <Cell CellId="179" Type="Obstruction" X="17" Y="9" />
    <Cell CellId="1710" Type="Obstruction" X="17" Y="10" />
    <Cell CellId="1711" Type="Obstruction" X="17" Y="11" />
    <Cell CellId="1811" Type="Obstruction" X="18" Y="11" />
    <Cell CellId="1613" Type="Obstruction" X="16" Y="13" />
    <Cell CellId="1713" Type="Obstruction" X="17" Y="13" />
    <Cell CellId="1813" Type="Obstruction" X="18" Y="13" />

System.IndexOutOfRangeException was unhandled  Message=IndexOutOfRangeException  StackTrace:       at Coding4Fun.ScriptTD.Engine.Logic.Grid.get_Item(Int32 indexX, Int32 indexY)       at Coding4Fun.ScriptTD.Engine.Logic.Grid.ApplyMap(MapData& map)       at Coding4Fun.ScriptTD.Engine.Logic.GameSession.LoadMapData(ContentManager content)       at Coding4Fun.ScriptTD.Sample.Screens.GameScreen.<>c__DisplayClass2.<LoadGraphics>b__1(ContentManager c)       at Coding4Fun.ScriptTD.Sample.BackgroundLoader.ThreadWorker()       at System.Threading.ThreadHelper.ThreadStartHelper(ThreadHelper t)       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)       at System.Threading.ThreadHelper.ThreadStartHelper()

Jan 30, 2013 at 7:26 AM

Currently, It is a fixed 11x19 grid.  Since we're zero-based indexed, that means valid values are 0-10 for Y, by 0-18 for x.

Jan 31, 2013 at 12:38 AM
Oh man I feel like a moron I can't believe I missed that.
I figure I will share with everyone an easy Obstruction Cell Builder When you go to that link click on the cells you want to be blocked by an obstruction and it will generate the XML code for you.
Work smarter not harder.

Thank you again
Jan 31, 2013 at 12:43 AM
Edited Jan 31, 2013 at 12:45 AM
That's awesome, thanks for sharing the tool!

Edit - Email reply didn't want to work right.