Game Development Community

Help! Where am I going wrong here?

by Mark Bonagofski · in Technical Issues · 02/20/2007 (5:37 pm) · 2 replies

Greetings,
I'm a student in Game and Simulation programming. I'm working on a game in Game Builder. I need to randomly populate a 3x3 2d array with 1s and 0s. The array must have a total of 5 1s and 4 0s. I wrote a function to do this but when I execute my game in Game Builder an error occurs. Where did I go wrong? My code is below. Thank you for your time.
In Your Service,
Mark Bonagofski

function fillTargetShapeArray()
{
%checkForFive = 0;

while (%checkForFive != 5)
{
$targetShapeArray[0,0] = getRandom(1);
$targetShapeArray[0,1] = getRandom(1);
$targetShapeArray[0,2] = getRandom(1);
$targetShapeArray[1,0] = getRandom(1);
$targetShapeArray[1,1] = getRandom(1);
$targetShapeArray[1,2] = getRandom(1);
$targetShapeArray[2,0] = getRandom(1);
$targetShapeArray[2,1] = getRandom(1);
$targetShapeArray[2,2] = getRandom(1);

%checkForFive = 0;

for (%x = 0; %x < 3; ++%x)
{
for (%y = 0; %y < 3; ++%y)
{
if ($targetShapeArray[x,y] == 1)
{
++%checkForFive;
}
}
}
}
}

#1
02/20/2007 (7:11 pm)
Put your operands after the variable... like %checkforFive++; and %x++ and %y++;
#2
02/20/2007 (10:03 pm)
Worked like a charm! Thanks for your time and knowledge Jimmy. It's a small transition from C#.