I want to make a thing like this:
You interact with an a hotspot, an a window pops-up and you need to enter a four-digit number and if it is right, the player will be taken to a defined room.
How to do this?
Patience, it's only been a couple of hours. That said:
How exactly do you want it to work?
The simplest way would be to use something like:
//in 'Interact Hotspot'
string pass;
InputBox ("What is the password?", pass);
if (StrCaseComp ("WHATEVER", pass) == 0) { // replace WHATEVER with your password/code
NewRoom (ROOM); // or NewRoomEx
//Anything else you want
}
Or you could set up a custom GUI with a text box, and use GetTextBoxText (GUI, OBJECT, pass); instead of InputBox();.
Finally, probably the most complex but best looking way - since it's only a number, you could have a keypad GUI pop-up to take the player's input. This is the code I've used to make a phone, but you could use something similar:
// from 'interface_click', obviously
if (interface == PHONE) {
if (button == 0) { // 'Submit Code' button
if (StrCaseComp ("WHATEVER", number) == 0) {// Again, change WHATEVER to your keycode
NewRoom (ROOM);
// Anything else.
}
else {
Display ("Invalid code. Access Denied.");
//These lines reset the code
StrFormat (number, "");
SetLabelText (PHONE, 12, number);
dial = 0;
}
}
if (button == 11) { // 'Hang Up/ Exit' button
GUIOff (PHONE);
dial = 0;
}
if (button == 13) { // 'Clear Number/ Try Again' button
StrFormat (number, "");
SetLabelText (PHONE, 12, number);
dial = 0;
}
if (button == 1) {
dial ++;
StrCat (number, "0");
SetLabelText (PHONE, 12, number);
}
if (button == 2) {
dial ++;
StrCat (number, "1");
SetLabelText (PHONE, 12, number);
}
if (button == 3) {
dial ++;
StrCat (number, "2");
SetLabelText (PHONE, 12, number);
}
if (button == 4) {
dial ++;
StrCat (number, "3");
SetLabelText (PHONE, 12, number);
}
if (button == 5) {
dial ++;
StrCat (number, "4");
SetLabelText (PHONE, 12, number);
}
if (button == 6) {
dial ++;
StrCat (number, "5");
SetLabelText (PHONE, 12, number);
}
if (button == 7) {
dial ++;
StrCat (number, "6");
SetLabelText (PHONE, 12, number);
}
if (button == 8) {
dial ++;
StrCat (number, "7");
SetLabelText (PHONE, 12, number);
}
if (button == 9) {
dial ++;
StrCat (number, "8");
SetLabelText (PHONE, 12, number);
}
if (button == 10) {
dial ++;
StrCat (number, "9");
SetLabelText (PHONE, 12, number);
}
}
objects 1-10 are buttons, numbered 0-9
Object 0, 13, 11 are Dail, Reset, Quit buttons
Object 12 is a Label, showing the number dialed so far.
I also have a global string declare OUTSIde of the GUI script ('number'), which holds the number dialed, or the Passcode in your case. My 'Dial button' script is a little different than the one here, but would be pointless for you.
There might be a simpler way to code this, that a more advanced scripter could tell you, but one of these should do the job.
Quote from: Ashen on Sat 13/11/2004 17:22:27
//in 'Interact Hotspot'
string pass;
InputBox ("What is the password?", pass);
if (StrCaseComp ("WHATEVER", pass) == 0) { // replace WHATEVER with your password/code
Ã, NewRoom (ROOM); // or NewRoomEx
Ã, //Anything else you want
Hi
I have these lines and they work fine, but I'd like it to be case insensitive and accept things like "I need information" etc
Thanks
Ã, // script for Character 1 (Jess): Interact character
string pass;
InputBox ("Just tell me what you need.", pass);
if (StrCaseComp ("Information", pass) == 0) {
NewRoom (24);
}
PS. All I managed with parsers and gui text boxes was to mess the global script...
Quote...I'd like it to be case insensitive and accept things like "I need information" etc
StrCaseComp does case-insensitive comparison.
Do you want the player to be able to type-in various sentences for the same result? I.e. not only "information", but "I need information", etc.?
You can indeed use the text parser feature for that:
string pass;
InputBox ("Just tell me what you need.", pass);
ParseText(pass);
if (Said("[need] information")) { // "i" and "need" are optional!
NewRoom (24);
}
"need" and "information" must be added to the parser dictionary in order for the script to work.
Alternatively, you can make a use of the StrContains function:
if (StrContains(pass, "information")!=-1) {
NewRoom (24);
}
Basically, it will then accept any sentence as long as it contains "information".
How does it turn out?
Quote from: Scorpiorus on Sat 04/06/2005 23:25:31
How does it turn out?
The
string pass;
InputBox ("Just tell me what you need.", pass);
ParseText(pass);
if (StrContains(pass, "information")!=-1) {
Ã, Ã, NewRoom (29);
...worked fine.
Thanks.
No problem, glad to hear it worked.
By the way, if you're using StrContains, "ParseText(pass);" is not required.
Quote from: Tuntis on Sun 05/06/2005 18:54:03
no one looking at the date this was posted? Hell.
I thought it was better to resurface an old post than start a new thread and get the "RTFM" bit...
<
angelic smile>
Anyway, it worked ,didn't it??