The Password Screen from Heck

Started by Whelandrew, Mon 13/08/2007 02:04:21

Previous topic - Next topic

Whelandrew

Okay... it's been three days. I've read all over the forums. I've rewritten several code schemes. I've messed with variables, strings, and the Dialogs options. I'm not a code wizard, but I'm trying to learn and a little help is always appreciated when you are doing this on your own.
So, here is my dilemma:
I have a very standard scene where a password is needed to open a door clicking on a computer in the screen. There is a hotspot in the room that reveals the password to you, at random, from six words. The intention is to bring up a dialog list and the six words appear. Quite simply, click on the right word and the door opens. Wrong word and nothing happens.
I am completely at a loss on how to do this. I have attempted several ideas with no luck at all. I feel like this should be an easier task, so I am certain that I have fallen to over thinking about it and gotten lost in the complication. But, I digress.
Help?
The bulb in my reading lamp went out.
I'm seeking enlightenment.

Recluse

By using a Dialog list box?

Here's my pseudo-code "this is what you do" way of doing this:

CODE:
Create your password strings, and assign each one a number. (either create a struct, or stick them in an array).
Create a variable to store the number of the random string chosen to be the password, and assign it a random number.

ROOM:
Have the hotspot show the string assigned to the number.

GUI:
Have your strings appear in the list box in a FIXED order (always the same).
On the submit button, code the following:
Code: ags
if(passwordNumber == listbox.SelectedIndex)
   Unlock the door



If this doesn't work, I've got no other solutions.
All your verbcoin are belong to us.

Khris

To elaborate a bit:

Room script:
Code: ags
String pw[6];
int pwi;

// first time player enters screen
  pw[0]="AGS"; pw[1]="Blue cup"; ... pw[5]="Banzai!";
  pwi=Random(5); // choose one at random

// interact with hotspot
  Display(String.Format("The password is: %s", pw[pwi]));

// interact with computer
  player.Say("I'll have to choose a password.");
  dPw.Start();  // dialog with passwords

// on_call
function on_call(int p) {
  if (p!=pwi) return;
  // open door, etc.
}


Dialog script (create six options, put the passwords in the fields, uncheck "Say", check "Show" for all six options):
Code: ags

@S
@1
run-script 1
stop
@2
run-script 2
stop
...


Global script (if it doesn't exist, create the function via the menu, select Script -> on_dialog_request)
Code: ags
function dialog_request(int p) {
  if (p<=6) CallRoomScript(p-1);
}

Whelandrew

What you presented really cleaned up my coding and made it easier to follow. However, it seems that putting "stop" in my dialog script causes the text to not appear at all. On top of that, opening the door happens whether or not anything is clicked. I need the dialog window to appear so that the player can select the word from the list and then cause the door to open.
The bulb in my reading lamp went out.
I'm seeking enlightenment.

Recluse

Ah! You're using dialogue! Not dialog. Apparently Firefox's spell check has nearly eliminated one spelling and in the process has confused me. I'm not exactly a fan of the dialog scripting process, it has yet to grow on me. I wish that we were able to choose between the extremely watered down dialogue scripting and the more complex regular scripting (with a few added dialogue specific functions). At any rate...

Could you possibly post the code you have so that we could have a better idea of what exactly is going wrong?
All your verbcoin are belong to us.

Whelandrew

I knew it was spelled wrong. But it is spelled "Dialog" in the program so I went with that to try and avoid confusion with what I was referring to. Guess it didn't work ;) Anywho, this is how I have it all set up.

Room Code:

String pw[6];
int pwi;


#sectionstart on_call room_a // on_call
function on_call(int p) {
  if (p!=pwi) return;
  // open door, etc.
  oLabdoor.Move(143, 60, 0, eBlock, eAnywhere);
}
#sectionend on_call room_a

#sectionstart room_a  // DO NOT EDIT OR REMOVE THIS LINE
function room_a() {
  // script for Room: First time player enters room
  pw[0]="RED";
  pw[1]="YELLOW";
   pw[2]="GREEN";
   pw[3]="BLUE";
   pw[4]="ORANGE";
   pw[5]="PURPLE";
      pwi=Random(5);
}
#sectionend room_a  // DO NOT EDIT OR REMOVE THIS LINE

#sectionstart hotspot3_a  // DO NOT EDIT OR REMOVE THIS LINE
function hotspot3_a() {
  // script for Hotspot 3 (Fishbowl): Interact hotspot
Display(String.Format("There are more %s guitar picks", pw[pwi])); 
}
#sectionend hotspot3_a  // DO NOT EDIT OR REMOVE THIS LINE

#sectionstart hotspot5_a  // DO NOT EDIT OR REMOVE THIS LINE
function hotspot5_a() {
  // script for Hotspot 5 (Compter): Interact hotspot
if (GetGraphicalVariable("password")==1)
   player.Say("ENTER PASSWORD");
  dpw.Start();  // dialog with passwords
}
#sectionend hotspot5_a  // DO NOT EDIT OR REMOVE THIS LINE

Dialog Code:
// dialog script file
@S  // dialog startup entry point
@1  // option 1
run-script 1
stop
@2  // option 2
run-script 2
stop
@3  // option 3
run-script 3
stop
@4  // option 4
run-script 4
stop
@5  // option 5
run-script 5
stop
@6  // option 6
run-script 6
stop

Dialog_request Code:
function dialog_request(int p) { 
  if (p<=6) CallRoomScript(p-1);
}
The bulb in my reading lamp went out.
I'm seeking enlightenment.

Khris

Right, I missed a line:
put "return" right below "@S" in the dialog script.

(And btw, you don't need to manually put the "#sectionstart ..." stuff around custom functions. AGS does that with its own ones to keep track of them, and although technically on_call is no true custom function, it's not necessary to mark it.)

I've noticed something else here:
Code: ags
function hotspot5_a() {
  // script for Hotspot 5 (Compter): Interact hotspot
if (GetGraphicalVariable("password")==1)
   player.Say("ENTER PASSWORD");
  dpw.Start();  // dialog with passwords
}


dpw.Start(); will always be called, regardless of the variable's value. You'll probably want this:
Code: ags
function hotspot5_a() {
  // script for Hotspot 5 (Compter): Interact hotspot
  if (GetGraphicalVariable("password")==1) {           //  <-- curly brackets to
    player.Say("ENTER PASSWORD");
    dpw.Start();  // dialog with passwords
  }                                              //  <-- group together a block of code
}

Whelandrew

That did it! :) Can't believe that one word was throwing everything off like that. Thanks a ton for your help
The bulb in my reading lamp went out.
I'm seeking enlightenment.

Khris

You're welcome :)
I've chased bugs which were caused by missing ()s or a single letter. That's the real fun ;)

SMF spam blocked by CleanTalk