ID:261958
 
var/icon/I = new('pc.dmi')
I.CreateTree(rgb(0,0,0),2,4,1,85,1,32,1,2,3,5)

Above is the way I declare the function I made for the icon object. The problem is when I try and run the function it freezes and doesnt do any thing. I was thinking it might be an infinante loop but I cant seem to find out were its happening.

Please help thanks.

Bellow is the functions complete code.

icon/proc/CreateTree(rgb,widthmin,widthmax,Bend_Percentage,D ec_Percentage,Dec_Value,Height,Branchmin,Branchmax,Blengthmi n,Blengthmax)
world << "WHY IS IT FREEZEING!"
var/xRndBasePoint = rand(12,20)
var/yRndBasePoint = rand(3,5)
// Pick a random base point location (x,y)
var/LeftSideWidth = rand(widthmin,widthmax)
var/RightSideWidth = rand(widthmin,widthmax)
// Get a random width for the left and right sides of the tree
// trunk.
DrawBox(rgb,xRndBasePoint-LeftSideWidth,yRndBasePoint,xRndBa sePoint+RightSideWidth,yRndBasePoint)
// A line called the BaseLine is made were the tree trunk will
// work its way upward to complete the tree.
var/OxRndBasePoint = xRndBasePoint
while(yRndBasePoint<Height+OxRndBasePoint){
var/Bend = pick(
1,
prob(Bend_Percentage)
2,
prob(Bend_Percentage)
3
)
if(Bend==1) // No bending of Trunk Accures
{
yRndBasePoint++
LeftSideWidth = rand(LeftSideWidth-1,LeftSideWidth+1)
RightSideWidth = rand(RightSideWidth-1,RightSideWidth+1)
}
else if(Bend==2) // Tree bends too the left
{
yRndBasePoint++
xRndBasePoint--
LeftSideWidth = rand(LeftSideWidth-1,LeftSideWidth)
RightSideWidth = rand(RightSideWidth,RightSideWidth+1)
}
else // Tree bends too the right
{
yRndBasePoint++
xRndBasePoint++
LeftSideWidth = rand(LeftSideWidth,LeftSideWidth+1)
RightSideWidth = rand(RightSideWidth-1,RightSideWidth)
}

// Drawing branches on the tree
world << "DEBUG before Creating Branch?"
var/branching = rand(1,1000)
if(branching)
{
var/branchset=0
while(branchset < rand(Branchmin,Branchmax))
{
branchset++
var/Branchx=xRndBasePoint
var/Branchy=yRndBasePoint
var/lengthBranch = rand(Blengthmin,Blengthmax)
var/list/Branches
Branches = new/list()
var/inc = 1
var/split = 0
var/length=0
var/changexy=0
var/lastmove = 0
var/move = 0
world << "Branchset [branchset]."
while(split<2)
{
world << " SPLIT LOOP [length]:[lengthBranch]"
if(length > lengthBranch)
{
split++
changexy++
if(changexy)// Branch is going to split
{
Branches.Add(Branchx,Branchy)
lengthBranch=lengthBranch/3
length = 0
changexy = 0
}
if(split >= 2)
{
while(inc<Branches.len)
{
inc++
Branchy = Branches[Branches.len-inc]
inc++
Branchx = Branches[Branches.len-inc]
var/splitchance = rand(1,1000)
if(splitchance)
{
split=0
inc=1
break
}
}
}
}
length++
lastmove = move
move = rand(1,8)
if(lastmove==0)
{
// First time moving branch
GrowBranch(rgb,move,Branchx,Branchy)
}
else if(lastmove==1)
{
if(move==5)
{
move = lastmove
continue
}
else
GrowBranch(rgb,move,Branchx,Branchy)
}
else if(lastmove==2)
{
if(move==6)
{
move = lastmove
continue
}
else
GrowBranch(rgb,move,Branchx,Branchy)
}
else if(lastmove==3)
{
if(move==7)
{
move = lastmove
continue
}
else
GrowBranch(rgb,move,Branchx,Branchy)
}
else if(lastmove==4)
{
if(move==8)
{
move = lastmove
continue
}
else
GrowBranch(rgb,move,Branchx,Branchy)
}
else if(lastmove==5)
{
if(move==1)
{
move = lastmove
continue
}
else
GrowBranch(rgb,move,Branchx,Branchy)
}
else if(lastmove==6)
{
if(move==2)
{
move = lastmove
continue
}
else
GrowBranch(rgb,move,Branchx,Branchy)
}
else if(lastmove==7)
{
if(move==3)
{
move = lastmove
continue
}
else
GrowBranch(rgb,move,Branchx,Branchy)
}
else if(lastmove==8)
{
if(move==4)
{
move = lastmove
continue
}
else
GrowBranch(rgb,move,Branchx,Branchy)
}

}// While(split<1)

}// while(branchset < rand(Branchmin,Branchmax))
}
if(yRndBasePoint>(Dec_Percentage * 0.01) * Height)
{
LeftSideWidth = LeftSideWidth - Dec_Value
RightSideWidth = RightSideWidth - Dec_Value
}
if((LeftSideWidth<=0)||(RightSideWidth<=0))
{
break
}
DrawBox(rgb,xRndBasePoint-LeftSideWidth,yRndBasePoint,xRndBa sePoint+RightSideWidth,yRndBasePoint)
// Draws a new line going down to up.
}

icon/proc/GrowBranch(rgb,move,Branchx,Branchy)
if(move==1)
{
DrawBox(rgb,Branchx-1,Branchy+1,,)
Branchx = Branchx - 1
Branchy = Branchy + 1
}
else if(move==2)
{
DrawBox(rgb,Branchx,Branchy+1,,)
Branchy = Branchy + 1
}
else if(move==3)
{
DrawBox(rgb,Branchx+1,Branchy+1,,)
Branchx = Branchx + 1
Branchy = Branchy + 1
}
else if(move==4)
{
DrawBox(rgb,Branchx+1,Branchy,,)
Branchx = Branchx + 1
}
else if(move==5)
{
DrawBox(rgb,Branchx+1,Branchy-1,,)
Branchx = Branchx + 1
Branchy = Branchy - 1
}
else if(move==6)
{
DrawBox(rgb,Branchx,Branchy-1,,)
Branchy = Branchy - 1
}
else if(move==7)
{
DrawBox(rgb,Branchx-1,Branchy-1,,)
Branchx = Branchx - 1
Branchy = Branchy - 1
}
else if(move==8)
{
DrawBox(rgb,Branchx-1,Branchy,,)
Branchx = Branchx - 1
}</1></2>
while(branchset < rand(Branchmin,Branchmax))

That's generating a new random number each time.
In response to Garthor
Garthor wrote:
while(branchset < rand(Branchmin,Branchmax))

That's generating a new random number each time.

Thanks for telling me I changed it too
var/BranchPerPoint = rand(Branchmin,Branchmax)
while(branchset < BranchPerPoint)

But that still doesnt help the freezing problem.

Ohh and by the way the problem is centered around the making of branches because when I take that code out it seems to run fine with the making of the trunk.
That looks like an L-parser to me. Gutsy!

Lummox JR
In response to Green Lime
Whoops, completely missed this one.
                                                                var/splitchance = rand(1,1000)
if(splitchance)
{
split=0


That's your error.
In response to Garthor
Garthor wrote:
Whoops, completely missed this one.
>                                                                 var/splitchance = rand(1,1000)
> if(splitchance)
> {
> split=0
>

That's your error.

Could u please explain to me how that is my error, Im not really following you.

[EDIT] GOD after thinking about it I think I see the error ur showing me. Is it having to do with the if all ways being true because it can only be false with a 0,"",null values.
In response to Lummox JR
Lummox JR wrote:
That looks like an L-parser to me. Gutsy!

Lummox JR

Umm pardon me but whats a L-parser?
In response to Green Lime
Green Lime wrote:
Umm pardon me but whats a L-parser?

http://home.wanadoo.nl/laurens.lapre/lparser.htm
In response to Shadowdarke
Shadowdarke wrote:
Green Lime wrote:
Umm pardon me but whats a L-parser?

http://home.wanadoo.nl/laurens.lapre/lparser.htm

Thanks for the website Im definantly going to look into this Lparser.