Mit, can you see what I'm missing in this script problem?

Forum Archive - from http://theuniversal.net
Locked
User avatar
morbydvisns
Posts: 1889
Joined: Sun Jan 30, 2005 12:51 am

Mit, can you see what I'm missing in this script problem?

Post by morbydvisns »

Code: Select all

////////////////////
//
//Playervar 50 - 65  - Order of proper answer
//65 - 80       Player's choices of order
//
//
//
//




                   
$buttonCount = 0
$Correct = 0
	
event("&command","guess")
{
InitGame()

}	
event("&command","rs")
{
*reloadscript


}			
	
Function InitGame()
{

InitDisplay()

}




Function InitDisplay($levelComplete)
{

$buttonCount = GetButtonCount()

osdcreate(OSDWINDOW,"Game","Guess the Pattern")
osdadditem(osdminheight,"",350)
if ($levelComplete = 1)
 {
 $ok = "ok"
    osdAddAt(osdBigText,50,50,500,35,"","You got it!  Good Job.  Now, let's step it up a bit.")
    osdaddat(osdbutton,200,200,50,35,"button|$ok","Ok")
 }
else if ($buttonCount = 0)
 {
  NewGame()
 }
  else
 {
 
   LoadButtons()
 }

DrawOSD()
}

Function NewGame()
{
$ok = "ok"
$newgame = "New game"
osdAddAt(osdBigText,50,50,500,35,"","Let's play a little game.  A little bit of guessing, a little bit of logic.")
osdAddAt(osdText,50,90,500,35,"","The rules are simple.  I think of a sequence of numbers, and you try to figure out the proper order.")
osdAddAt(osdText,50,130,500,35,"","The only hints I will give is how many you have in the correct spot in the sequence.")
osdAddAt(osdText,50,170,500,35,"","Here, we'll start simple.")
osdaddat(osdbutton,200,250,50,40,"Button|$ok","Ok")


}
Function LoadButtons()
{

 $buttonCount = GetButtonCount()
  $x = 1
  $xPos = 450 / $buttonCount
  $yPos = 350 / $buttonCount
  $xAdd = $xPos
  $yAdd = $yPos
  $Width = 50
  $height = 50
  while ($x <= $buttonCount)
  {
  OsdAddat(osdbutton,$xPos,$yPos,$width,$height,"button|$x",$x)
   $x += 1
   $xPos += $xAdd
   
  }
}

event("osdselect","game:button")
{
$buttonCount = GetButtonCount()
if ($gParam1 > 0)
 {
 *msg %player% You picked button $gParam1

  $x = 0
  $var = 65 + $x
  $maxbutIndex = $buttonCount - 1
  *say $buttonCount buttoncount
   $maxVar = 65 + $maxButIndex
   while ($var <= $maxVar)
  {
   *say $var var <= $maxVar max
  
	
	 if ($gPlayerVar[$var] = 0)
   {
	 *msg %player% var$var set to $gParam1
	 $gPlayervar[$var] = $gParam1
	
	     if ($var = $maxVar)
    {
	*msg %player% Checking pattern guess
	  CheckPattern()
	}
	
	  else
	{
	  *msg %player% InitDisplay
	  InitDisplay()
	}
	  
   return()
	 
   }
         *msg %player% increasing Var Index from $var
	    $x += 1
	   $var = 65 + $x
        *msg %player% var is now $var maxVar is $maxVar
  }
 }
  
  
	else if ($gParam1 = "Ok")
 {
  
  $add = 0
  if ($buttonCount = 0)
  { 
	 $add = 2
  }
  else
  {
	  $add = 1
  }
	
	$newAmnt = $buttonCount + $add
	 SetPattern($newAmnt)
  
 }  
  InitDisplay()
}	
	  


Function CheckPattern()
{
   $correct = 0
   $buttonCount = GetButtonCount()
   $x = 0
   $ansVar = 50 + $x
   $guessVar = 65 + $x
   $lastAns = 50 + $buttonCount
   while ($ansVar < $lastAns)
   { 
    if ($gPlayervar[$ansVar] = $gPlayerVar[$guessVar])
    {
	
      $correct += 1
    }
   $x += 1
   $ansVar = 50 + $x
   $guessVar = 65 + $x
   }
   if ($correct != $buttonCount)
   {
   *msg %player% You guessed $correct correctly.  Try again!
	ResetGuesses()
	InitDisplay()
   }
   else
   {
   *say %player% guessed the sequence!
   ResetGuesses()
   
   
   
   
   InitDisplay(1)
   }
   

}


Function ResetGuesses()
{
$x = 0
   $guessVar = 65 + $x
    while ($x < $buttonCount)
	{
	$gplayervar[$guessVar] = 0
	$x += 1
	$guessvar = 65 + $x
	}
}
Function ResetPattern()
{
$x = 0
   $patternVar = 50 + $x
  
    while ($x < $buttonCount)
	{

	$gplayervar[$patternVar] = 0
	
	$x += 1
	$patternVar = 50 + $x
	}
	
}



Function SetPattern($amnt)
{
ResetPattern()
$baseVar = 50
$value = SysRand($amnt)
$index = 0
$pvar = $baseVar + $index
 while ($index < $amnt)
 {
     
	 
       if ($gPlayervar[$pvar] = 0)
	   {
	  
	      $gPlayerVar[$pVar] = $value
		
		   if ($index + 1 < $Amnt)
		   {
		   $value = SysRand($amnt)
		  $index = -1
		   }
	   }
	   else if ($gPlayerVar[$pVar] = $value)
	   {
	   
	      $index = -1
	   $value = SysRand($amnt)
	   }
	   $index += 1
	   $pvar = $baseVar + $index
 }
 

 

}



Function GetButtonCount()
{
$x = 0
$var = 50 
   while ($gPlayerVar[$var] > 0)
    {
	$x += 1
	$var = 50 + $x
    }
	return ($x)

}

Function DrawOSD()
{
OSDActivate()

}



The problem is in the OSDSELECT button event, in the while loop. I have added lots of diag tracing messages, and it seems that it's not sending back through the while loop when the condition is still being met for it.
The script works fine for a while, then just binds up at the bottom of that while loop after some playing time with the minigame. Same spot every time.

Oh yea, and simply reloading the script kicks it back into shape.
User avatar
Mit
Staff
Staff
Posts: 3551
Joined: Sun Sep 21, 2003 10:14 pm
Location: Unknown

Post by Mit »

nothing leaps out. I've run the script here (nice and modular :] ).. got to 5 buttons without any problems.. how long does it take to break?
User avatar
morbydvisns
Posts: 1889
Joined: Sun Jan 30, 2005 12:51 am

Post by morbydvisns »

takes a while... probably near 100 'clicks'
User avatar
zaroba
World Owner
World Owner
Posts: 7257
Joined: Fri Oct 10, 2003 11:06 pm
Location: Hereford, PA
Contact:

Post by zaroba »

from what I experienced while playing that minigame, it seemed to happen when clicking really fast. Perhaps resulting in clicking the button, then another click happening before the next osd window shows and thus taking focus off the osd and it stopping?
Locked