Telephone GUI

Started by Grundislav, Tue 21/12/2004 19:28:13

Previous topic - Next topic

Grundislav

For those who have played GK1, my example will make more sense. If you remember, there were a couple of times you needed to call some people, and the phone GUI had the numbers, an on/off button, clear, etc. When you dialed the numbers, they showed up on the LED display, and once you dialed 7, the phone rang and the appropriate person answered, or you got a busy signal, that sort of thing.

So, I have a phone GUI. I have each number button as a button on the GUI. I have the LED readout as a text box. I need to know how to script it so each number will appear as it is dialed, and be processed after a certain amount of numbers are dialed, to simulate the call.

Any help is greatly appreciated.

Rui 'Trovatore' Pires

You can treat the numbers as letters.

When the player presses one, add the string "5" (for instance) to a string that keeps track of the whole thing, and update the LED display (a label, hopefully) with THAT string. And then, still in the same command, check to see if StrLen==8, for instance - 8 numbers. If so, you can now use StrComp to get the phone number the player typed in.

Hope it helps.
Reach for the moon. Even if you miss, you'll land among the stars.

Kneel. Now.

Never throw chicken at a Leprechaun.

Scorpiorus

And here is an example script:
GUI:
GUINameÃ,  Ã, Ã,  = GUIPHONE
GUIobject0Ã,  = button (digit 0)
GUIobject1Ã,  = button (digit 1)
GUIobject2Ã,  = button (digit 2)
...
GUIobject9Ã,  = button (digit 9)

GUIobject10 = button (Clear)
GUIobject11 = label  (LED)


Main global script file:

// how long wait before dialing:
#define DIALING_DELAY 150

// max length of a phone number:
#define NUMBER_LENGTH_MAX 8

string strPhoneNumber;
int dialingCounter = 0;

// use this function to handle calls:
function OnNumberCalled(string number) {
Ã,  
Ã,  Ã,  if (StrComp(number, "911") == 0)
Ã,  Ã,  {
Ã,  Ã,  Ã,  Ã,  DisplaySpeech(EGO, "help!1!11");
Ã,  Ã,  Ã,  Ã,  DisplaySpeech(EGO, "blah blah");
Ã,  Ã,  Ã,  Ã,  DisplaySpeech(EGO, "blah blah");
Ã,  Ã,  }
Ã,  Ã,  else if (StrComp(number, "1337") == 0)
Ã,  Ã,  {
Ã,  Ã,  Ã,  Ã,  DisplaySpeech(EGO, "blah blah");
Ã,  Ã,  Ã,  Ã,  DisplaySpeech(EGO, "blah blah");
Ã,  Ã,  Ã,  Ã,  DisplaySpeech(EGO, "blah blah");
Ã,  Ã,  }
Ã,  Ã,  else 
Ã,  Ã,  {
Ã,  Ã,  Ã,  Ã,  Display("beep... beep... beep... Wrong number!");
Ã,  Ã,  }
Ã,  
}


function repeatedly_execute() {
Ã,  // put anything you want to happen every game cycle here

Ã,  Ã,  if (StrLen(strPhoneNumber) > 0)
Ã,  Ã,  {
Ã,  Ã,  Ã,  Ã,  if (dialingCounter >= DIALING_DELAY)
Ã,  Ã,  Ã,  Ã,  {
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  OnNumberCalled(strPhoneNumber);
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  StrCopy(strPhoneNumber, "");
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  dialingCounter = 0;
Ã,  Ã,  Ã,  Ã,  }
Ã,  Ã,  Ã,  Ã,  else dialingCounter++;

Ã,  Ã,  }

}


function interface_click(int interface, int button) {
Ã,  
Ã,  Ã,  if (interface == GUIPHONE)
Ã,  Ã,  {
Ã,  Ã,  Ã,  Ã,  if ( (button >= 0) && (button <= 9) )
Ã,  Ã,  Ã,  Ã,  {
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  if (StrLen(strPhoneNumber) < NUMBER_LENGTH_MAX)
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  {
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  StrFormat(strPhoneNumber, "%s%d", strPhoneNumber, button);
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  }
Ã,  Ã,  Ã,  Ã,  }
Ã,  Ã,  Ã,  
Ã,  Ã,  Ã,  Ã,  if (button == 10)
Ã,  Ã,  Ã,  Ã,  {
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  StrCopy(strPhoneNumber, "");
Ã,  Ã,  Ã,  Ã,  }
Ã,  Ã,  Ã,  
Ã,  Ã,  Ã,  Ã,  dialingCounter = 0;
Ã,  Ã,  
Ã,  Ã,  Ã,  Ã,  SetLabelText(interface, 11, strPhoneNumber);

Ã,  Ã,  }
}

Grundislav

Thanks, that worked like a charm.  :)

Rui 'Trovatore' Pires

This is not hard stuff, methinks, but all the same it's nice for reference. Could this one go into the technical archive?
Reach for the moon. Even if you miss, you'll land among the stars.

Kneel. Now.

Never throw chicken at a Leprechaun.

Gilbert


SMF spam blocked by CleanTalk