Page postinitialize event buttons won't work

Hello,

I am trying to create a game where buttons on the screen will pop up randomly across the screen; kind of like whack-o-mole. I have a program located in the postinitialize event’s of the page that the game is supposed to be on as seen below.

Currently, this program does what I want it to and hides 4 buttons and only shows one in a constant loop. The problem that I am having is that the buttons on the screen are unable to be pressed and when I click on them it doesn’t even show that they are being clicked on visually.

Assigned to the buttons on their touch press event I have it so that they add 5 to a number box on the screen to represent score. They work fine when I get rid of the postinitalize event program on the page.

Does anyone know how to fix this problem to where the program will be able to read button presses while it’s in a constant loop on the page postinitalize event?

while(va0.val<10)
{
  delay=1500
  randset 0,5
  va0.val=rand
  if(va0.val==0)
  {
    vis b0,1
    vis b1,0
    vis b2,0
    vis b3,0
    vis b4,0
  }
  if(va0.val==1)
  {
    vis b0,0
    vis b1,1
    vis b2,0
    vis b3,0
    vis b4,0
  }
  if(va0.val==2)
  {
    vis b0,0
    vis b1,0
    vis b2,1
    vis b3,0
    vis b4,0
  }
  if(va0.val==3)
  {
    vis b0,0
    vis b1,0
    vis b2,0
    vis b3,1
    vis b4,0
  }
  if(va0.val==4)
  {
    vis b0,0
    vis b1,0
    vis b2,0
    vis b3,0
    vis b4,1
  }
  doevents
}

Couple of points Preinitialize only runs once, and randset 0,5 will give 6 numbers (0,1,2,3,4,5) whereas you have 5 buttons so have changed randset 0,5 to randset 0,4.

Put following code in page preinitialize. This hides all buttons and turns on first one.
Also zeros the counter n0.val

vis b0,0
vis b1,0
vis b2,0
vis b3,0
vis b4,0
n0.val=0
delay=1500
randset 0,4
va0.val=rand
if(va0.val==0)
{
vis b0,1
}else if(va0.val==1)
{
vis b1,1
}else if(va0.val==2)
{
vis b2,1
}else if(va0.val==3)
{
vis b3,1
}else if(va0.val==4)
{
vis b4,1
}

Remove all your buttons then create a new one (this should title it b0). Then add
the following code the the touch attribute of b0. This will hide the current button, increment the counter and then show the next button.
Now copy the button (ctrl-C) and paste (ctrl-V) the button 4 times so you will see 5 buttons - each with same code.
Change the first line of code on each to reflect the button name (b1, b2, b3 etc)
Good luck

vis b0,0
n0.val+=5
randset 0,4
va0.val=rand
if(va0.val==0)
{
vis b0,1
}else if(va0.val==1)
{
vis b1,1
}else if(va0.val==2)
{
vis b2,1
}else if(va0.val==3)
{
vis b3,1
}else if(va0.val==4)
{
vis b4,1
}