Name Game and Theora

Started by CTxCB, Sat 02/01/2010 10:52:20

Previous topic - Next topic

CTxCB

I know I have asked this before but i am making a game and I'd Like to:
1.) Have a "Name Your Game" Screen (I have Made a Text Box and Buttons with Letters A-Z, All I Need is Help on Coding Each Button to add a Letter into the textbox, Moving the Mouse to that Button if you enter the letter with a keyboard and how to save the Data of the Name your game screen and use it to Create a Save Game)

2.) How do I code Theora into my Game (Any Code will be Helpful, and how do i program it into the room scripts: so when i start the game and it goes to room 999 (Logo) it plays the Logo and then goes to the Title Menu

I am a Newbie and i cannot do this without help,
Thanks,
Techodog

Virgil

The text box automatically takes text. Run your game and type stuff in. To retrieve the input, use the code textboxname.Text

Really, please read the manual, most everything is in there.

Save games are run automatically through the engine but there are custom ones available. In a button click function declare SaveGameDialog() and the window comes up.


tzachs

In order to make the textbox change on each button click, you have a lot of work cut out for you:
for each button click event (search buttons in the manual if you don't know how to register to the events), you have to write:
Code: ags

myTextBox.Text = myTextBox.Text.AppendChar('A');

Assuming your textbox name is myTextBox and the button was 'A'.

In order for the mouse to move to the correct button when you press something on the keyboard, open your global script, and write inside on_key_press (eKeyCode keycode):
Code: ags

if (myTextBox.Visible) // or any other condition to assure that this code will only activate when appropriate
{
     if (keycode == eKeyA) mouse.SetPosition(buttonA.X, buttonA.Y);
     if (keycode == eKeyB) mouse.SetPosition(buttonB.X, buttonB.Y);
     ...
}

monkey0506

Quote from: tzachs on Sat 02/01/2010 22:36:11In order to make the textbox change on each button click, you have a lot of work cut out for you:
for each button click event, you have to write:

This process could be simplified somewhat by linking every button click event to the same handler such as:

Code: ags
function btnLetter_Click(GUIControl *control, MouseButton button) {
  char letter = 0;
  if (control == btnA) letter = 'A';
  else if (control == btnB) letter = 'B';
  else if (control == btnC) letter = 'C';
  // ...
  else if (control == btnY) letter = 'Y';
  else if (control == btnZ) letter = 'Z';
  if (letter != 0) txtTextbox.Text = txtTextbox.Text.AppendChar(letter);
}


Then for each button you would just manually type (copy/paste!!) "btnLetter_Click" into the "OnClick" event for each of the 26 buttons.

If for any reason you need to convert the buttons into their respective character (or String) values you could simply write an extender method (or two) such as:

Code: ags
// GlobalScript.ash
import char GetCharValue(this Button*);
import String GetStringValue(this Button*);

// GlobalScript.asc
char GetCharValue(this Button*) {
  if (this == btnA) return 'A';
  if (this == btnB) return 'B';
  if (this == btnC) return 'C';
  // ...
  if (this == btnY) return 'Y';
  if (this == btnZ) return 'Z';
  return 0; // button does not correspond to any letter
}

String GetStringValue(this Button*) {
  char letter = this.GetCharValue();
  if (letter == 0) return null; // button does not correspond to any letter
  return String.Format("%c", letter);
}


Then in your scripts you could do something such as:

Code: ags
GUIControl *gcat = GUIControl.GetAtScreenXY(mouse.x, mouse.y);
char letter = 0;
if ((gcat != null) && (gcat.AsButton != null)) letter = gcat.AsButton.GetCharValue();
if (letter != 0) {
  // whatever you need to do with the letter the mouse was over...
}


And of course your event handler could be simplified to:

Code: ags
function btnLetter_Click(GUIControl *control, MouseButton button) {
  char letter = control.AsButton.GetCharValue();
  if (letter != 0) txtTextbox.Text = txtTextbox.Text.AppendChar(letter);
}


Just some tips to help you out here.

As far as Theora goes all you need is PlayVideo.

SMF spam blocked by CleanTalk