Question to the user while playing

Started by rsja, Mon 23/11/2009 13:28:39

Previous topic - Next topic

rsja

Hello,

I would like for instance in a custscene to give a question to the user. I would like to ask them which room they would like to go to.


function room_AfterFadeIn()
{

  Overlay *textOverlay;
  textOverlay = Overlay.CreateTextual(320, 100, 200, eFontAriel, 1,  "test test.");
  Wait(140);
 

  //Here i would like something like that:

Wich room do you want to go to?

If he presses option 1:
player.ChangeRoom(3);

Of he presses option 2:
player.ChangeRoom(4);

}


NsMn

You can use a GUI with a textbox, but the Input function is much easier.

Code: ags

String GoToRoom=InputBox("Where would you like to go?");
player.ChangeRoom(GoToRoom.AsInt);


Look up InputBox in the manual to get more information.

Akatosh

#2
Note that NsMn's code only works if the user is asked and inputs a number, however, and allows the player to access any room by inputting the correct one... the InputBox function is a quick and simple way to do this, but you'll need slightly more sophisticated scripting.

/EDIT:
Code: ags

String GoTo;
while ((GoTo.LowerCase()!="attic")&&(GoTo.LowerCase()!="bedroom")) GoToRoom=Game.InputBox("Where would you like to go - attic or bedroom?");
if (GoTo.LowerCase()=="attic") player.ChangeRoom(4);
else player.ChangeRoom(5);


Would be a quick'n'dirty, but HOPEFULLY workable example.

Khris

Isn't the question more about a two button GUI?

Create a GUI, set it to "pause game when shown", then add two buttons and double click them to make AGS create their OnClick functions. Put the ChangeRoom commands in those.

NsMn

If it's that what you want, I recommend using the DialogBox module (by SSH I believe)
Since having normal GUIs for this needs scripts in the rep_execute function, which isn't easy for a beginner.It doesn't just pause until the player makes his choice and then goes on with the cutscene script.

Khris

Quote from: NsMn on Mon 23/11/2009 14:47:05It doesn't just pause until the player makes his choice and then goes on with the cutscene script.

It doesn't? But that's exactly how that type of GUI (formerly called "PopUp") works; it pauses the game until it is turned not visible again.
Also I imagine if the player will go to a different room immediately afterwards, one would put gRoomChoice.Visible = true; at the end of the function, so even if having a GUI pop up would somehow not work during a cutscene (which it will just fine), there's not much cutscene left after it, at least not in that room.

NsMn

It pauses the GAME, not the running SCRIPT. So it's better to use the module for this case.

You don't know everything better Khris.

Khris

Apparently in this case I do, pal.

I tested it using this:
Code: ags
function room_AfterFadeIn() {
  StartCutscene(eSkipESCOnly);
  player.Walk(0, 180);
  Wait(20);
  mouse.Mode = eModePointer;
  gChoice.Visible = true;
  player.Walk(319, 180);
  EndCutscene();
}


The GUI stops Roger's walk dead in its tracks, as expected. As soon as I press the button, the GUI disappears and Roger resumes walking. (The new panel of the default game does exhibit the exact same behaviour, btw)
The thing is, even if it didn't, like I said, the GUI would be turned on at the end of the script anyway.

Please get your shit straight before lecturing people.

NsMn

Jesus, learn to read. What I was talking about was:

Quote from: NsMn on Mon 23/11/2009 16:31:11
It pauses the GAME, not the running SCRIPT. So it's better to use the module for this case.

You don't know everything better Khris.

Because, instead of writing a whole new script just for the GUI, you can just add one Line instead of the Gui.Visible command and you're done.

Khris

It does pause the running script.
So why go through all the trouble of downloading/adding the module and using it when all is needed are a simple GUI and a few lines of code?

suicidal pencil

#10
Quote from: Khris on Mon 23/11/2009 19:35:05
...why go through all the trouble of downloading/adding the module and using it when all is needed are a simple GUI and a few lines of code?

Because it's apparently easier to take five minutes searching and downloading a module you'll only use once, so that you don't need to build a quick GUI, and write a few lines of code

NsMn, do you not like GUIs?Blasphemy!...and you shouldn't attempt to call out someone who probably has much more coding and programming experience, since they might actually know more than you.

SMF spam blocked by CleanTalk