Text speed?

Started by monkey0506, Sun 20/06/2004 02:09:21

Previous topic - Next topic

monkey0506

Is it possible to change the text speed (as in old style LucasArts games)??? Especially with + and -, as that's what they were set to in The Secret of Monkey Island. :D

Ashen

I couldn't find the ascii code for the + and - keys, so I had to improvise. If you're not using the up and down arrows for anything (or the left-right ones), they might be a better choice.

In Global Script, outside any function:
int txtspd;

In repeatedly_execute:
game.text_speed = txtspd;

In on_key_press:
  if ((keycode==381) && (txtspd > 0)) txtspd --;  //PgDn decreases speed, unless speed is 0
  if (keycode==379) txtspd ++;  //End increases speed

This way, speed can be changed at any point during game. If you want it to be done on an options GUI type thing, skip the on_key_press, use a Slider on the GUI, and make it:

game.text_speed = GetSliderValue (OPTIONS, SLIDER);

Hope this helps.
I know what you're thinking ... Don't think that.

Scorpiorus

#2
The '+' and '- ' keycodes don't work, unfortunately. Not sure about the on_key_pressed but the IsKeyPressed function doesn't return 1. That was reported though and hopefully will be fixed in the future version.

See this thread: http://www.agsforums.com/yabb/index.php?topic=14179

It also shows how you can make it change the speed even while a message is displayed.

monkey0506

#3
Ok, I've played around with it and I can not get it to work.Ã,  >:(
Ok, more description:
I am trying to make a GUI. I have a "Text Speed" Bar. The same one as used in The Secret of Monkey Island. It is a horizontal bar. I have the fully functional GUI made up in AGS. I cannot get it to appear in the game. I want to use the keyboard to control the slider. Please help...Ã,  :'(

Scorpiorus

Quote from: monkey_05_06 on Sun 20/06/2004 21:53:39I am trying to make a GUI. I have a "Text Speed" Bar. The same one as used in The Secret of Monkey Island. It is a horizontal bar. I have the fully functional GUI made up in AGS. I cannot get it to appear in the game.
To turn a GUI on:

GUIOn(GUI_NAME_HERE);

QuoteI want to use the keyboard to control the slider.

To control the slider by pressing the left/right keys adjust your on_key_press function in the main global script:

function on_key_press(int keycode) {
   // called when a key is pressed. keycode holds the key's ASCII code


   int gui = NAME_OF_GUI_WITH_SLIDER;
   int slider = SLIDER'S_OBJECT_NUMBER;
   int slider_max_value = SLIDER'S_MAX_VALUE;
   int slider_min_value = SLIDER'S_MIN_VALUE;
   int step = 1;

   if (IsGUIOn(gui)==1) {
      
      int new_value = GetSliderValue (gui, slider);

      if (keycode == '375') new_value = GetSliderValue (gui, slider) - step;
      if (keycode == '377') new_value = GetSliderValue (gui, slider) + step;

      if (new_value > slider_max_value) new_value = slider_max_value;
      if (new_value < slider_min_value) new_value = slider_min_value;

      SetSliderValue (gui, slider, new_value);
   }


   if (IsGamePaused() == 1) keycode=0;Ã,  // game paused, so don't react to keypresses
   if (keycode==17)Ã,  QuitGame(1);Ã,  Ã, // Ctrl-Q
   f (keycode==363) SaveGameDialog();Ã,  Ã, // F5
   if (keycode==365) RestoreGameDialog();Ã,  // F7
   if (keycode==367) RestartGame();Ã,  // F9
   if (keycode==434) SaveScreenShot("scrnshot.bmp");Ã,  // F12
   if (keycode==9)Ã,  Ã, show_inventory_window();Ã,  // Tab, show inventory

   if (keycode==19)Ã,  Debug(0,0);Ã,  // Ctrl-S, give all inventory
   if (keycode==22)Ã,  Debug(1,0);Ã,  // Ctrl-V, version
   if (keycode==1)Ã,  Ã, Debug(2,0);Ã,  // Ctrl-A, show walkable areas
   if (keycode==24)Ã,  Debug(3,0);Ã,  // Ctrl-X, teleport to room

}

Replace the names in bold with their actual values.

Gilbert

Quote from: Scorpiorus on Sun 20/06/2004 14:20:44
Not sure about the on_key_pressed but the IsKeyPressed function doesn't return 1.
I can verify that they worked with on_key_pressed() in a room script at least with V2.6SP1, don't know about newer versions or the global script though.

Scorpiorus

Gilbert: Thanks for verifying, yeah it's most likely the IsKeyPressed command which doesn't work correctly.

monkey_05_06: The advantage of using the IsKeyPressed function over the on_mouse_click function is that you can check a value returned by "IsKeyPressed" within the repeatedly_execute_always and thus change the text speed even while a conversation is going on.

monkey0506

I have yet to get this to work. Let me explain how exactly I want it to work.

On key press PgUp (just a placeholder), I want it to turn on the GUI with the text slider, and move add 1 to the value of the slider. If the key is held down I want it to keep the GUI on and add to the value till the PgUp key is released. And just the opposite with PgDown. Then, I want to GUI to turn off after about 3 seconds.

I also want a similar slider GUI for the sound using Home and End. I've tried all the scripts given to me this far, but I can't get it to work. Thanks for trying though.

Scorpiorus

A slider to change the text speed:

// main global script file

#define KEY_PAGEUP   380
#define KEY_PAGEDOWN 381

#define TIMEOUT 120
int timer = -1;


#define SLIDER 0


function repeatedly_execute() {
  // put anything you want to happen every game cycle here
 
   if (timer > 0) timer--;
   else if (timer==0) {
      GUIOff(SLIDERGUI);
      timer = -1;
   }

}



function on_key_press(int keycode) {
 
   if (keycode == KEY_PAGEUP) {
      timer = TIMEOUT;
      GUIOn(SLIDERGUI);
      SetSliderValue(SLIDERGUI, SLIDER, GetSliderValue(SLIDERGUI, SLIDER)+1);
      game.text_speed = GetSliderValue(SLIDERGUI, SLIDER);
   }

   if (keycode == KEY_PAGEDOWN) {
      timer = TIMEOUT;
      GUIOn(SLIDERGUI);
      SetSliderValue(SLIDERGUI, SLIDER, GetSliderValue(SLIDERGUI, SLIDER)-1);
      game.text_speed = GetSliderValue(SLIDERGUI, SLIDER);
   }
 
}

monkey0506

I am supposing that I replace "SLIDERGUI" with the name of my Text Slider GUI, "TEXT" and "SLIDER" with the object number of the slider, "0". YES!!! Hahaha.. THANK YOU!!! Thank you for working with me on this, and working up all those scripts. I finally got that last one to work and it works great. Only one thing. Can you make it to where I can change the speed while they are talking? Other than that it works great. THANK YOU SOOO MUCH!!! Oh, and could you work something up for the sound level?

Scorpiorus

Quote from: monkey_05_06 on Sun 11/07/2004 17:32:50Can you make it to where I can change the speed while they are talking?
QuoteOh, and could you work something up for the sound level?

The following code should do the trick:

// main global script file

#define KEY_PAGEUPÃ,  Ã, 380
#define KEY_PAGEDOWN 381
#define KEY_HOMEÃ,  Ã,  Ã, 371
#define KEY_ENDÃ,  Ã,  Ã,  379

#define TIMEOUT 120
int timer = -1;


#define SLIDER 0
#define VOLUME 0


function repeatedly_execute() {
   // put anything you want to happen every game cycle here
Ã, 
   if (timer > 0) timer--;
   else if (timer==0) {
      GUIOff(SLIDERGUI);
      GUIOff(VOLUMEGUI);
      timer = -1;
   }

}


function GetKeyPressed() {

   if (IsKeyPressed(KEY_PAGEUP)) return KEY_PAGEUP;
   else if (IsKeyPressed(KEY_PAGEDOWN)) return KEY_PAGEDOWN;
   else if (IsKeyPressed(KEY_HOME)) return KEY_HOME;
   else if (IsKeyPressed(KEY_END)) return KEY_END;
   else return 0;
}


function on_key_press_always(int keycode) {
Ã, 
   if (keycode == KEY_PAGEUP) {
      timer = TIMEOUT;
      GUIOn(SLIDERGUI);
      SetSliderValue(SLIDERGUI, SLIDER, GetSliderValue(SLIDERGUI, SLIDER)+1);
      game.text_speed = GetSliderValue(SLIDERGUI, SLIDER);
   }

   if (keycode == KEY_PAGEDOWN) {
      timer = TIMEOUT;
      GUIOn(SLIDERGUI);
      SetSliderValue(SLIDERGUI, SLIDER, GetSliderValue(SLIDERGUI, SLIDER)-1);
      game.text_speed = GetSliderValue(SLIDERGUI, SLIDER);
   }

   if (keycode == KEY_HOME) {
      timer = TIMEOUT;
      GUIOn(VOLUMEGUI);
      SetSliderValue(VOLUMEGUI, VOLUME, GetSliderValue(VOLUMEGUI, VOLUME)+1);
      SetSoundVolume(GetSliderValue(VOLUMEGUI, VOLUME));
   }

   if (keycode == KEY_END) {
      timer = TIMEOUT;
      GUIOn(VOLUMEGUI);
      SetSliderValue(VOLUMEGUI, VOLUME, GetSliderValue(VOLUMEGUI, VOLUME)-1);
      SetSoundVolume(GetSliderValue(VOLUMEGUI, VOLUME));
   }
Ã, 
}


function repeatedly_execute_always() {

   if (IsGamePaused()==0) on_key_press_always(GetKeyPressed());
}

subspark

Hmm somethings wrong with mine.

When I hold down the Page Up/Down Key or the Home/End key the GUI pops up with +1 or -1 value but the values don't continue to change while I hold the key down.

And now that I have set my Text speed slider to have 5 as max PageUp wont work.

What am I doing wrong? I am using GUI 3 for both text speed and volume.

Also I have added Insert and End for Music Volume.
I have everything set to go except INS/DEL wont pop the GUI up.

Basically PageUp/Down = Text Speed
Home/End = SFX Volume
Insert/Delete = Music Volume

My code:
Code: ags
///////////////////////////////////////////////////////////////////////////////////
//////////////////SLIDER CONTROL///////////////////////////////////////////////////
#define KEY_PAGEUPÃ,  Ã, 380
#define KEY_PAGEDOWN 381
#define KEY_HOMEÃ,  Ã,  Ã, 371
#define KEY_ENDÃ,  Ã,  Ã,  379
#define KEY_INSÃ,  Ã,  Ã,  382
#define KEY_DELÃ,  Ã,  Ã,  383

#define TIMEOUT 120
int timer = -1;


#define SLIDER 0
#define VOLUME 0

function GetKeyPressed() {

Ã,  Ã, if (IsKeyPressed(KEY_PAGEUP)) return KEY_PAGEUP;
Ã,  Ã, else if (IsKeyPressed(KEY_PAGEDOWN)) return KEY_PAGEDOWN;
Ã,  Ã, else if (IsKeyPressed(KEY_HOME)) return KEY_HOME;
Ã,  Ã, else if (IsKeyPressed(KEY_END)) return KEY_END;
Ã,  Ã, else if (IsKeyPressed(KEY_INS)) return KEY_INS;
Ã,  Ã, else if (IsKeyPressed(KEY_DEL)) return KEY_DEL;
Ã,  Ã, else return 0;
}


function on_key_press_always(int keycode) {
Ã,  
Ã,  Ã, if (keycode == KEY_PAGEUP) {
Ã,  Ã,  Ã,  timer = TIMEOUT;
Ã,  Ã,  Ã,  GUIOn(3);
Ã,  Ã,  Ã,  SetSliderValue(3, 6, GetSliderValue(3, 6)+1);
Ã,  Ã,  Ã,  game.text_speed = GetSliderValue(3, 6);
Ã,  Ã, }

Ã,  Ã, if (keycode == KEY_PAGEDOWN) {
Ã,  Ã,  Ã,  timer = TIMEOUT;
Ã,  Ã,  Ã,  GUIOn(3);
Ã,  Ã,  Ã,  SetSliderValue(3, 6, GetSliderValue(3, 6)-1);
Ã,  Ã,  Ã,  game.text_speed = GetSliderValue(3, 6);
Ã,  Ã, }

Ã,  Ã, if (keycode == KEY_HOME) {
Ã,  Ã,  Ã,  timer = TIMEOUT;
Ã,  Ã,  Ã,  GUIOn(3);
Ã,  Ã,  Ã,  SetSliderValue(3, 8, GetSliderValue(3, 8)+1);
Ã,  Ã,  Ã,  SetSoundVolume(GetSliderValue(3, 8));
Ã,  Ã, }

Ã,  Ã, if (keycode == KEY_END) {
Ã,  Ã,  Ã,  timer = TIMEOUT;
Ã,  Ã,  Ã,  GUIOn(3);
Ã,  Ã,  Ã,  SetSliderValue(3, 8, GetSliderValue(3, 8)-1);
Ã,  Ã,  Ã,  SetSoundVolume(GetSliderValue(3, 8));
 }
 
Ã,  Ã,  if (keycode == KEY_INS) {
Ã,  Ã,  Ã,  timer = TIMEOUT;
Ã,  Ã,  Ã,  GUIOn(3);
Ã,  Ã,  Ã,  SetSliderValue(3, 10, GetSliderValue(3, 10)+1);
Ã,  Ã,  Ã,  SetMusicMasterVolume(GetSliderValue(3, 10));
Ã,  Ã, }

Ã,  Ã, if (keycode == KEY_DEL) {
Ã,  Ã,  Ã,  timer = TIMEOUT;
Ã,  Ã,  Ã,  GUIOn(3);
Ã,  Ã,  Ã,  SetSliderValue(3, 10, GetSliderValue(3, 10)-1);
Ã,  Ã,  Ã,  SetMusicMasterVolume(GetSliderValue(3, 10));
Ã,  Ã, }
Ã,  
}


And in the repeatedly_execute:
Code: ags
#sectionstart repeatedly_execute
function repeatedly_execute() {//////////////////////////////////////Repeatedly Execute///////////Repeatedly Execute
Ã,  Ã,  // put anything you want to happen every game cycle here
////////PUT YOUR SCRIPTS HERE IF POSSIBLE///////////



////////////////////////////////////////////////////
// If the timer reaches zero, turns the GUI off.Ã,  
	if (timer > 0) timer--;
Ã,  else if (timer==0) {
Ã,  Ã,  Ã,  GUIOff(3);
Ã,  Ã,  Ã,  GUIOff(3);
Ã,  Ã,  Ã,  timer = -1;
//-----------------------------------------------------
}
#sectionend repeatedly_execute


And finally in the repeatedly-execute-always:
Code: ags
#sectionstart repeatedly_execute_always
function repeatedly_execute_always() {

Ã,  Ã, if (IsGamePaused()==0) on_key_press_always(GetKeyPressed());
}
#sectionend repeatedly_execute_always


Any Ideas?

Gilbert

Was GUI #3 set to "popup modal" ? In that case it will pause your game and on_key_pressed_always() won't be run when the GUI's active.

SMF spam blocked by CleanTalk