Game Development Community

Wrong client script being associated with server script

by Chris · in Torque Game Engine · 06/06/2009 (8:16 pm) · 1 replies

So here's my dilemma. I'm using the pair matching mini game script available on this site ( I believe I found it in resources). I've made two copies of it for my game, one for a card matching game and an altered version of it to put in a safe combination. Here's where it gets strange: the card matching game (initialized BEFORE the safe combination scripts in both client/init.cs and server/game.cs) pops up fine via the server script, but anytime you try to click on one of the cards it tries to use the client script associated with the safe combination mechanism instead of its own. If I comment out the initialization of the safe combo script, the matching game works fine.

I've tried changing all variable/function/class names in both files to make sure they're both completely different, and it's still not working. I even tried changing the GUI values, and still nothing.

Any help is greatly appreciated, here's the code for the client and server scripts for both the card matching game and the safe combination. If anyone can see what might be causing the problem, please let me know, thanks very much.

** UPDATE **

I just tried putting the initilization of the client safe combo script ABOVE the card matching one in client/init.cs as so:
exec("./scripts/safeCombo.cs");
exec("./scripts/mgPairing.cs");
And go figure now anytime I try to do the safe combination it uses the card matching client script instead of its own. What the hell is going on here?

FOR CARD MATCHING GAME:

SERVER SCRIPT:
function serverCmdGenerateMGPairing(%client)
{
   GenerateMGPairing(%client);   
}

function serverCmdCheckMGPairing(%client,%id,%val)
{
   %client.minigame.checkMGPairing(%id,%val);
}

function GenerateMGPairing( %client )
{   
   if(!isObject(%client))
      return;
   
   %puzzle = new ScriptObject()
   {
      class = "MiniGames";
      size = 36;  
      
      currentvalue = 0;
      lastvalue = 0;
      currentid = -1;
      lastid = -1;
      
      attempt = 0;
      correctCount = 0;
      
      client = %client;
   };
   MissionCleanup.add(%puzzle);
    
   for(%i=0;%i<%puzzle.size;%i++)
   {
      %puzzle.item[%i] = 0;
      %puzzle.guessed[%i] = false;
   }
      
   for(%j=0; %j<2; %j++)
   {
      %seed = getRandomSeed();
      setRandomSeed(%seed);
      for (%i = 1; %i <= (%puzzle.size / 2); %i++)
      {
         while (true)
         {
            %a = getRandom(0,%puzzle.size);// % %puzzle.size;
            if (%puzzle.item[%a] == 0)
            {
                  %puzzle.item[%a] = %i;               
                  break;
            }         
         }
      }
   }
   
   // create an subsequents of string to pass the puzzle array to client
   %out = "";
   for (%i = 0; %i < 36; %i++)
   {
      %out = %out @ %puzzle.item[%i] @ "|" ;      
   }
   
   if(isObject(%client.minigame))
      %client.minigame.delete();
   
   // hold to client
   %client.minigame = %puzzle;
   
   commandToClient(%client,'CreateGUIMGPairing',%out);
}

function MiniGames::checkMGPairing(%this, %id, %val)
{
   if(%this.lastvalue==0 && %this.lastid==-1)
   {
      %this.lastvalue = %val;      
      %this.lastid = %id;   
   }
   else
   {
      %this.attempt++;      
      commandToClient(%this.client,'SetAttemptMGPairingItem',%this.attempt);
   
      %this.currentvalue = %val;
      %this.currentid = %id;      
      
      if(%this.currentvalue == %this.lastvalue)
      {
         echo ("match !! "@%this.currentvalue@"=="@%this.lastvalue);        
         
         //  set the index of guessed to true
         %this.guessed[%this.currentid] = true; 
         %this.guessed[%this.lastid] = true;
         
         %this.resetPuzzleItem(true); 
         
         %this.correctCount++;
         
         if(%this.correctCount == (%this.size/2)) // all the item match 36 box / 2 = 18
         {
            commandToClient(%this.client,'WinMGPairingMsg',%this.attempt);
         }         
      }
      else
      {
         echo ("NOT match !! "@%this.currentvalue@"=="@%this.lastvalue);
         
         for(%i=0;%i<36;%i++)
         {
            if(%this.guessed[%i]==false)
               commandToClient(%this.client,'SetActiveMGPairingItem',%i,false);
         }
         // give them time to remember the item if it wrong match.
         %this.schedule(500,"resetPuzzleItem",false);
      }
   }
}

function MiniGames::resetPuzzleItem(%this,%isCorrect)
{
   if( %isCorrect )
   {
      commandToClient(%this.client,'ResetMGPairingItem',true); 
   }
   else
   {
      commandToClient(%this.client,'ResetMGPairingItem',false); 
      for(%i=0;%i<36;%i++)
      {
         if(%this.guessed[%i]==false)
            commandToClient(%this.client,'SetActiveMGPairingItem',%i,true);
      }
   }
   
   %this.currentid = -1;
   %this.lastid = -1; 
   %this.currentvalue = 0;
   %this.lastvalue = 0;
}


CLIENT SCRIPT:

// ============================================================
// Project            :  tak benteng
// File               :  .modsclientscriptsmgPairing.cs
// Copyright          :  
// Author             :  herrucules
// Created on         :  Friday, September 14, 2007 2:39 PM
//
// Editor             :  Codeweaver v. 1.2.2685.32755
//
// Description        :  minigame pairing client side code
//                    :  
//                    :  
// ============================================================
function mgPairing::onwake(%this)
{
   for(%i=0;%i<36;%i++)
   {
      (mgPairingItem@(%i)).setBitmap("C:/Documents and Settings/Administrator/Desktop/Torque/TGE_1_5_2/example/tutorial.base/client/ui/bitmaps/puzzle/0");      
   }
}

function clientCmdCreateGUIMGPairing(%items)
{
   // parse the puzzle items
   %i=0;
   %tmpItems = %items;
   while( "" !$= %tmpItems )
   {
      %tmpItems = nextToken(%tmpItems, "item", "|");
      %puzzle[%i] = %item;
      echo (" "@%item);
      %i++;
   }
   
   // set the gui values.
   for (%i = 0; %i < 36; %i++)
   {      
      (mgPairingItem@(%i)).value = %puzzle[%i];
      (mgPairingItem@(%i)).command = "cek("@%i@","@%puzzle[%i]@");";      
   }
   // reset the correct & attempt count
   mgPairing.correctCount = 0;
   mgPairing.attempt = 0;
   
   // show the GUI
   canvas.pushdialog(mgPairing);

}

function clientCmdSetActiveMGPairingItem(%id,%val)
{   
   (mgPairingItem@%id).setActive(%val);    
}

function clientCmdSetAttemptMGPairingItem(%val)
{
   mgPairingDescription.setText("<font:Arial Bold:20><color:0000ff>Attempt : "@%val);   
}

function clientCmdWinMGPairingMsg(%val)
{
   MessageBoxOK("Win !","Congrats you win ! on "@%val@" attempts","canvas.popdialog(mgPairing);");
}

function clientCmdResetMGPairingItem(%val)
{
   resetMGPairingItem(%val);
}

function cek(%id,%val)
{
   (mgPairingItem@%id).setBitmap("C:/Documents and Settings/Administrator/Desktop/Torque/TGE_1_5_2/example/tutorial.base/client/ui/bitmaps/puzzle/"@%val);
   (mgPairingItem@%id).setActive(false);
   
   if(mgPairingContainer.lastid$="-1")
   {     
      mgPairingContainer.lastid = %id;         
   }
   else
   {     
      mgPairingContainer.currentid = %id;      
   }
   
   commandToServer('checkMGPairing',%id,%val);
}

function resetMGPairingItem(%isCorrect)
{   
   if( !%isCorrect )
   {
      (mgPairingItem@mgPairingContainer.currentid).setBitmap("C:/Documents and Settings/Administrator/Desktop/Torque/TGE_1_5_2/example/tutorial.base/client/ui/bitmaps/puzzle/0");
      (mgPairingItem@mgPairingContainer.lastid).setBitmap("C:/Documents and Settings/Administrator/Desktop/Torque/TGE_1_5_2/example/tutorial.base/client/ui/bitmaps/puzzle/0");
      (mgPairingItem@mgPairingContainer.currentid).setActive(true);
      (mgPairingItem@mgPairingContainer.lastid).setActive(true);
   }
   
   mgPairingContainer.currentid = "-1";
   mgPairingContainer.lastid = "-1"; 
}



FOR SAFE COMBINATION SCRIPTS:

SERVER SCRIPT:

function serverCmdGenerateSafeCombo(%client)
{
   GenerateSafeCombo(%client);   
}

function serverCmdCheckSafeCombo(%client,%iid,%val)
{
   %client.safecombo.checkSafeCombo(%iid,%val);
}

function GenerateSafeCombo( %client )
{   
   if(!isObject(%client))
      return;
   
   %combo = new ScriptObject()
   {
      class = "SafeCombos";
      size = 10;  
      
      curval = 0;
      //lastvalue = 0;
      curid = -1;
     // lastid = -1;
      
      atmpt = 0;
      corrCount = 0;
      
      client = %client;
   };
   MissionCleanup.add(%combo);
    
   for(%ii=0;%ii<%combo.size;%ii++)
   {
      %combo.item[%ii] = %ii;
      %combo.guessed[%ii] = false;
   }
      
   
   //for(%j=0; %j<2; %j++)
   //{
      %seed = getRandomSeed();
      setRandomSeed(%seed);
      for (%ii = 0; %ii <= %combo.size; %ii++)
      {
         //while (true)
         //{
            //%a = getRandom(0,%combo.size);// % %combo.size;
			%a = %combo.size;
            if (%combo.item[%a] == 0)
            {
                  %combo.item[%a] = %ii;               
                  break;
            }         
         //}
      }
   //}
   
   // create an subsequents of string to pass the combo array to client
   %out = "";
   for (%ii = 0; %ii < 9; %ii++)
   {
      %out = %out @ %combo.item[%ii] @ "|" ;      
   }
   
   if(isObject(%client.safecombo))
      %client.safecombo.delete();
   
   // hold to client
   %client.safecombo = %combo;
   
   commandToClient(%client,'CreateGUISafeCombo',%out);
}

function SafeCombos::checkSafeCombo(%this, %iid, %val)
{
	
   if(%this.curval==-1 && %this.curid==-1)
   {
      %this.curval = %val;      
      %this.curid = %iid;   
   }
   else
   {
      %this.atmpt++;      
      commandToClient(%this.client,'SetAttemptSafeComboItem',%this.atmpt);
   
      %this.curval = %val;
	  //%this.lastvalue = 1;
      %this.curid = %iid;      
      
      if(%this.curval == 2 && %this.corrCount == 0)
      {     
         //clientCmdCenterPrint( "Orderly: Hey!  You're not allowed in there!", 3, 15 );
         //  set the index of guessed to true
         %this.guessed[%this.curid] = true; 
         //%this.resetcomboItem(true); 
         
         %this.corrCount++;
         
                 
      }
	  
	  if(%this.curval == 6 && %this.corrCount == 1)
      {      
         //clientCmdCenterPrint( "Orderly: Hey!  You're not allowed in there!", 3, 15 );
         //  set the index of guessed to true
         %this.guessed[%this.curid] = true; 
         //%this.resetcomboItem(true); 
         
         %this.corrCount++;
         
                 
      }
	  
	  if(%this.curval == 2 && %this.corrCount == 2)
      {      
         //clientCmdCenterPrint( "Orderly: Hey!  You're not allowed in there!", 3, 15 );
         //  set the index of guessed to true
         %this.guessed[%this.curid] = true; 
         //%this.resetcomboItem(true); 
         
         %this.corrCount++;
         
                 
      }
	  
	  if(%this.curval == 4 && %this.corrCount == 3)
      {     
         //clientCmdCenterPrint( "Orderly: Hey!  You're not allowed in there!", 3, 15 );
         //  set the index of guessed to true
         %this.guessed[%this.curid] = true; 
         //%this.resetcomboItem(true); 
         
         %this.corrCount++;
         
                 
      }
	  
	  if(%this.curval == 5 && %this.corrCount == 4)
      {
              
         //clientCmdCenterPrint( "Orderly: Hey!  You're not allowed in there!", 3, 15 );
         //  set the index of guessed to true
         %this.guessed[%this.curid] = true; 
         //%this.resetcomboItem(true); 
         
         %this.corrCount++;
         
                 
      }
	  
	  if(%this.corrCount == 5) // all the item match 9 box / 2 = 18
         {
			echo ("You've unlocked the safe!");   
            commandToClient(%this.client,'WinSafeComboMsg',%this.atmpt);
			
         } 
      else
      {
         echo ("NOT match !! "@%this.curval@"== 2");
         
         for(%ii=0;%ii<9;%ii++)
         {
            if(%this.guessed[%ii]==false)
               commandToClient(%this.client,'SetActiveSafeComboItem',%ii,false);
         }
         // give them time to remember the item if it wrong match.
         %this.schedule(500,"resetcomboItem",false);
      }
   }
}

function SafeCombos::resetcomboItem(%this,%iisCorrect)
{
   if( %iisCorrect )
   {
      commandToClient(%this.client,'ResetSafeComboItem',true); 
   }
   else
   {
      commandToClient(%this.client,'ResetSafeComboItem',false); 
      for(%ii=0;%ii<9;%ii++)
      {
         if(%this.guessed[%ii]==false)
            commandToClient(%this.client,'SetActiveSafeComboItem',%ii,true);
      }
   }
   
   %this.curid = -1;
   //%this.lastid = -1; 
   %this.curval = 0;
   //%this.lastvalue = 0;
}



CLIENT SCRIPT:

// ============================================================
// Project            :  tak benteng
// File               :  .modsclientscriptssafeCombo.cs
// Copyright          :  
// Author             :  herrucules
// Created on         :  Friday, September 14, 2007 2:39 PM
//
// Editor             :  Codeweaver v. 1.2.2685.32755
//
// Description        :  safecombo pairing client side code
//                    :  
//                    :  
// ============================================================
function safeCombo::onwake(%this)
{
      (safeComboItem@(0)).setBitmap("C:/Documents and Settings/Administrator/Desktop/Torque/TGE_1_5_2/example/tutorial.base/client/ui/bitmaps/combo/0");
	  (safeComboItem@(1)).setBitmap("C:/Documents and Settings/Administrator/Desktop/Torque/TGE_1_5_2/example/tutorial.base/client/ui/bitmaps/combo/1");  
	  (safeComboItem@(2)).setBitmap("C:/Documents and Settings/Administrator/Desktop/Torque/TGE_1_5_2/example/tutorial.base/client/ui/bitmaps/combo/2");  
}

function clientCmdCreateGUISafeCombo(%safeitems)
{
   // parse the combo safeitems
   %ii=0;
   %temporaryItems = %safeitems;
   while( "" !$= %temporaryItems )
   {
      %temporaryItems = nextToken(%temporaryItems, "safeitem", "|");
      %combo[%ii] = %safeitem;
      echo (" "@%safeitem);
      %ii++;
   }
   
   // set the gui values.
   for (%ii = 0; %ii < 9; %ii++)
   {      
      (safeComboItem@(%ii)).value = %combo[%ii];
      (safeComboItem@(%ii)).command = "cek("@%ii@","@%combo[%ii]@");";      
   }
   // reset the correct & attempt count
   safeCombo.correctCount = 0;
   safeCombo.attempt = 0;
   
   // show the GUI
   canvas.pushdialog(safeCombo);

}

function clientCmdSetActiveSafeComboItem(%iid,%val)
{   
   (safeComboItem@%iid).setActive(%val);    
}

function clientCmdSetAttemptSafeComboItem(%val)
{
   //safeComboDescription.setText("<font:Arial Bold:20><color:0000ff>Attempt : "@%val);   
}

function clientCmdWinSafeComboMsg(%val)
{
   canvas.popdialog(safeCombo);
   clientCmdCenterPrint( "You've received part of the key code: 3 3 2", 7, 20 );
}

function clientCmdResetSafeComboItem(%val)
{
   resetSafeComboItem(%val);
}

function cek(%iid,%val)
{
   //(safeComboItem@%iid).setBitmap("C:/Documents and Settings/Administrator/Desktop/Torque/TGE_1_5_2/example/tutorial.base/client/ui/bitmaps/combo/"@%val);
   (safeComboItem@%iid).setActive(false);
   /*
   if(safeComboContainer.lastid$="-1")
   {     
      safeComboContainer.lastid = %iid;         
   }
   else
   {    */ 
      safeComboContainer.curid = %iid;      
   //}
   
   commandToServer('checksafeCombo',%iid,%val);
}

function resetsafeComboItem(%iisCorrect)
{   
   if( !%iisCorrect )
   {
      //(safeComboItem@safeComboContainer.curid).setBitmap("C:/Documents and Settings/Administrator/Desktop/Torque/TGE_1_5_2/example/tutorial.base/client/ui/bitmaps/combo/0");
      //(safeComboItem@safeComboContainer.lastid).setBitmap("C:/Documents and Settings/Administrator/Desktop/Torque/TGE_1_5_2/example/tutorial.base/client/ui/bitmaps/combo/0");
      (safeComboItem@safeComboContainer.curid).setActive(true);
      //(safeComboItem@safeComboContainer.lastid).setActive(true);
   }
   
   safeComboContainer.curid = "-1";
   //safeComboContainer.lastid = "-1"; 
}

#1
06/07/2009 (3:51 am)
ok i see the problem... It took me a while though :p

in both client scripts you have this function using the same name

function cek(%id,%val)

this is whats causing your problem since both have the same name. and to answer your question about the exec order, since both files have a function with the same name but different code in that function, the latter one overrides the previous one. So since the names r the same the last script to be loaded with that function in it will be the code that gets called.. Gosh im terrible @ explaining things lol hope that was clear.

so your solution is to change those 2 function names, maybe mgCek and safeCek