Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 2 Vote(s) - 2.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
3buttons then a bookshelf opens
Apjjm Offline
Is easy to say

Posts: 496
Threads: 18
Joined: Apr 2011
Reputation: 52
#9
RE: 3buttons then a bookshelf opens

Tweaked and re-arranged the code a little, by moving the buttons into an array so you can add/remove/change the buttons easily (you can just add any extra buttons to the array and without needing to alter the code at all). The code wasn't working because FuncOpen() was only being called from the start routine, and not the callback.
//List of all our buttons. You can add or remove buttons really easily from this
//Add: Just add another comma, and another item!
//You can also break the array over lines, so it looks nicer
string[] buttonsToCount =
         {"button_simple_2","button_simple_3","button_simple_4"};

/////////////////////////////////////////////////////////////
//Onstart Event Routine                                    //
/////////////////////////////////////////////////////////////
void OnStart()
{
  
   SetLocalVarInt("buttonCount", 0); //Set how many buttons are intially pressed here.
  
   //Loop through all the buttons we wish to count, adding a callback for them.
   for(int i=0; i<buttonsToCount.length(); i++)
     SetEntityPlayerInteractCallback(buttonsToCount[i], "cbButtonCounter", true);
}



/////////////////////////////////////////////////////////////
//Callback (button interaction) Event Routine              //
/////////////////////////////////////////////////////////////
void cbButtonCounter(string &in asEntity)
{
     //Do stuff for this button
     AddLocalVarInt("buttonCount",1);         //Increment the button counter
         
     //Check the state of all the buttons. If they are pressed, call event.
     if(GetLocalVarInt("buttonCount") == buttonsToCount.length())
       evButtonsDepressed();
}

/////////////////////////////////////////////////////////////
//Event: all buttons pressed                               //
/////////////////////////////////////////////////////////////
void evButtonsDepressed()
{
   //Put your code when all buttons are pressed here.
   AddDebugMessage("All Buttons Pressed!",false);
}


This may also interest you:
http://www.frictionalgames.com/forum/thr...l#pid74705

(This post was last modified: 06-15-2011, 03:36 PM by Apjjm.)
06-15-2011, 03:31 PM
Find


Messages In This Thread
3buttons then a bookshelf opens - by xtron - 06-13-2011, 03:28 PM
RE: 3buttons then a bookshelf opens - by Kyle - 06-13-2011, 08:03 PM
RE: 3buttons then a bookshelf opens - by xtron - 06-13-2011, 08:13 PM
RE: 3buttons then a bookshelf opens - by Kyle - 06-13-2011, 08:28 PM
RE: 3buttons then a bookshelf opens - by xtron - 06-13-2011, 08:38 PM
RE: 3buttons then a bookshelf opens - by Kyle - 06-13-2011, 08:58 PM
RE: 3buttons then a bookshelf opens - by xtron - 06-14-2011, 02:58 PM
RE: 3buttons then a bookshelf opens - by Apjjm - 06-15-2011, 03:31 PM
RE: 3buttons then a bookshelf opens - by xtron - 06-15-2011, 06:39 PM
RE: 3buttons then a bookshelf opens - by Kyle - 06-15-2011, 07:39 PM



Users browsing this thread: 1 Guest(s)