SOLVED: Options for Text box input (password perhaps)

Started by steptoe, Fri 02/12/2011 12:40:55

Previous topic - Next topic

steptoe

Hi

this may be a noob question but I have not used text input boxes before and thought it would add to my armoury for future use. I have been reading up about them but need some assistance.

So far:

Code: ags

player.Name=Game.InputBox("What is your name?");
cEgo.Say("Your Name is %s.", character[EGO].Name);
cEgo.Say("Come with me %s", character[EGO].Name);
cEgo.Say("You and I have a lot to talk about %s.",character[EGO].Name);


which works fine and I can display Players name anytime.

However, imagine it to be a password for example and you have to type the correct password in else Display Incorrect password. You have 3 chances to get it right else automatically go back to last room and try again or something else for example.

The Input box is naturally reset.

Also, changing Characters Name (Not script Name). Example: Roger(cEgo) to players name based on input text box.

This is a loose idea and any guidance would be appreciated.

:o


It's not over until the fat lady sings..

Ghost

#1
Simplest things first ;)

Character.Name can be used to get/set a character's "text name".
So player.Name = Game.InputBox("!What is your name?"); will allow you to change that.
(This was directly lifted from the manual, but the way.)

As for the "3 guesses before you return", I would simply use a variable to keep track of how many guesses have failed: A wrong guess would increase it, and once it hits 3 you can execute your code to change rooms or what have you.

int timesTried = 0;

if (timesTried == 3)
{
  // move player to last room
}







steptoe

#2
Hi

Thanks Ghost,

Have Made the Variable Int (TimesTried)

Obviously I need to add that to the button script but I believe it is hardcoded as default. I assume it would involve making a new Text box and button?

Waiting to continue
...................

It's not over until the fat lady sings..

Ghost

#3
Yes, you need a new GUI; InputBox is very limited AND hardcoded. The puzzle would be possible but I think a custom GUI just is better- you can even make it to look like a security panel!
You can set a GUI to visible with GUINAME.Visible = true, and invisible with GUINAME.Visible = false. You will need that to make the GUI appear/disappear.

Create a GUI. Name it gPasswordGUI.
Add a text box; name it tbInput.
Add a button, name it btnEnter.


So for the button, write this

{
  if (tbInput.Text == "SWORDFISH")
      Display("Yeah, correct!");
  else
  {
     if (timesTried < 3)
       timesTried++
      else
      {
         timesTried = 0;
         // player failed- move to new room!
       }
    }
}

This is very basic indeed, but it allows you to keep all important code in one place- the "okay" button.

Note that failing three times moves the player AND resets the timesTried variable- so when the player returns he will have another 3 attempts.

Also note that in a text box, upper/lowercase is important. SwordFish and SWORDFISH are two different words.

steptoe

#4
Cheers Ghost

first part ok...

So far have just the if/ else display.. need to incorporate TimesTried int properly.

Amended timestried part:

Code: ags


function btnEnter_OnClick(GUIControl *control, MouseButton button)
{

  if (tbInput.Text == "SWORDFISH")
  Display("Yeah, correct!");
  
   
   {
   if (TimesTried > 1)
   TimesTried++;
   Display("Wrong");
    
   {
     TimesTried == 0;
     Display("WRONG LAST TIME!");// player failed- move to new room!
   }
  }
 
}


Clicks also seem to happen 'off' the button

EDIT
Have this now so far (works):
Code: ags

function btnEnter_OnClick(GUIControl *control, MouseButton button)
{ 

  if (tbInput.Text == "SWORD")
  {
  Display("Yeah, correct!");
  gPasswordGUI.Visible=false;
  
   
  }
  else{
   
   Display("WRONG!");
     // player failed- move to new room!
   }
  }


Close but not yet there

cheers


It's not over until the fat lady sings..

Ghost

I can see that in the first block of code a bracket is "off", that has caused the problem.

Your edit looks okay to me, what's not working?

steptoe

Quote from: Ghost on Fri 02/12/2011 19:10:42
I can see that in the first block of code a bracket is "off", that has caused the problem.

Your edit looks okay to me, what's not working?

Hi Ghost

I'm playing with getting the TimesTried int working properly.

cheers

It's not over until the fat lady sings..

Ghost

#7
Make it a global variable. There are other ways but this is the simplest one.

Open the "Global Variables" section in the editor, and create it there:
int timesTried = 0;

Now you can alter the variable from everywhere else, easy as pie.
Code: ags

function btnEnter_OnClick(GUIControl *control, MouseButton button)
{
    if (tbInput.Text == "PASSWORD")
    {
        Display("Yeah, correct!");
        player.Say("Wow. That WAS easy!");
        gPasswordGUI.Visible=false;   
     }
  else
 {
    Display("WRONG!");
    timesTried++;
    if (timesTried >= 3)
    {
       timesTried = 0;
        //CHANGE PLAYER ROOM
   }
 }
}



That should really be all, tell me if it works  :)

I just realised that we were playing code ping-pong here  ;D If you really need complete code, say so in the first post; I really thought you just needed a "shove" into the right direction. Sorry for misreading that.

steptoe

#8
Just about perfik Ghost..

I've now got 2 types of Text Box situations under my belt.

cheers mate

:=

Final question... if i did a new GUI for players name input what can I use instead of:

Game.InputBox("What is your name?"); to specify text box entry as it brings up default Input Gui?


It's not over until the fat lady sings..

Ghost

You can create a new GUI, also with a Text Box and an OK button, and add a label on top ("What is your name?"). Then, for the button:

Code: ags

if (TEXTBOX.Text != "")
  player.Name = TEXTBOX.Text;
else
  Display("Can't use an empty string! You can't be the Nameless One!");

 

steptoe

Done this and works ok

ENTER NAME:

Code: ags


function btnEnter2_OnClick(GUIControl *control, MouseButton button)
{
 
 if (tbInput2.Text != "")
 
 {
  player.Name = tbInput2.Text;
  gName.Visible=false;
  
  cEgo.Say("Hello %s.", character[EGO].Name);
cEgo.Say("You and I have a lot to talk about %s.",character[EGO].Name);
cClaudia.Say("Hello %s, I'm Claudia",character[EGO].Name);
 
 }
 else
  Display("Can't use an empty string! You can't be the Nameless One!");
}


ENTER PASSWORD:

Code: ags

function btnEnter_OnClick(GUIControl *control, MouseButton button)
{
  
  
    if (tbInput.Text == "PASSWORD")
    {
        gPasswordGUI.Visible=false;  
        cEgo.Say("Yeah, correct!");
        cEgo.Say("Wow. That WAS easy %s", character[EGO].Name);
        
     }
  else
 {
    Display("WRONG!");
    TimesTried++;
    if (TimesTried >= 3)
    {
       TimesTried = 0;
       cEgo.Say("Go back and try again!");
        gPasswordGUI.Visible=false;
    
   }
 }
}


Many thanks Ghost

:=

It's not over until the fat lady sings..

SMF spam blocked by CleanTalk