Password Sequence

Started by Alexis Vale, Mon 01/09/2003 02:22:35

Previous topic - Next topic

Alexis Vale

I have this machine where the user has to put in four correct values (these are pictures of foods, not numbers). Right now I have the graphics done for it, it is in AGS, each button is made so when it is clicked its image appears in the answer part, and each button has a mouseover text so you know what it is. Here's my problem:

What would be the best way to go about making it so each time a correct button is pressed, it adds 1 to a value, and each time a wrong button is pressed, it adds 5 to the value? I want it so that when the value is greater than 4, a message is displayed and the value is reset. I want it so that when the value equals 4, a message is displayed and an object is turned on. I was thinking about it in terms of (very basic) C++, but that was using cout and cin to determine a variable and then adding the variables...and I wasn't even sure if I had that right...

Ishmael

In the button protopies, set the 'on click' to 'run script' and in the interface_click function put something like this:

if (interface==GUINAME) {
if (button==buttonnum) {
// code here to check if it was the right button
}
}

I'm not much of a in-the-air scritpter about these thing, but I'm sure SSH or someone will help you better then me...
I used to make games but then I took an IRC in the knee.

<Calin> Ishmael looks awesome all the time
\( Ö)/ ¬(Ö ) | Ja minähän en keskellä kirkasta päivää lähden minnekään juoksentelemaan ilman housuja.

Phubans

That's the same thing I'm trying to figure out, Alexis... Have you looked at the password sequence keypad they have in the demo game? I couldn't really figure it out, but maybe you can make better sense of it. If you figure anything out, let me know, and I'll be sure to do the same for you.

DinghyDog

Well, you could do something really ugly, and just have four variables, each one being defined by the first click, second click, third click and fourth click, and then check to see if all the variables are correct in an if/else statement. Not quite sure how you'd do the first click and second click thing in a script, but I believe it's do-able....

-DD
It's yer owld pal Dinghy Dog!!

Ishmael

#4
This not quite what you explained of, but might solve the problem, in case it works.

http://kotisivu.mtv3.fi/tk/4butseq.txt

It's a bit messy, but you should be able to put the pieces where they belong... I hope I explained it well enough.
I used to make games but then I took an IRC in the knee.

<Calin> Ishmael looks awesome all the time
\( Ö)/ ¬(Ö ) | Ja minähän en keskellä kirkasta päivää lähden minnekään juoksentelemaan ilman housuja.

DinghyDog

It looks delightful to ME, but still...I don't see any flaws, and you did some nice shorthand as well.

-DD
It's yer owld pal Dinghy Dog!!

Alexis Vale

Ah! Very nice. Probably as clean as possible and easy to understand. There's a few problems though.

function interface_click(int interface, int button) {
if (interface == SEQBTNS) {
 int seq1, seq2, seq3, seq4; //I just put that there. It seems to work alright so far.
 if (button == 1) seq1 = 1 ;
 if (button == 2) seq2 = 1 ;
 if (button == 3) seq3 = 1 ;
 if (button == 4) seq4 = 1 ;
 if ((seq3) && (seq1==0) && (seq2==0) && (seq4==0)) {
   if ((seq1) && (seq2==0) && (seq4==0)) { //I closed the seq1.
     if ((seq4) && (seq2==0)) { //I closed the seq4.
       if (seq2) {
         Display("Sequence complete");
       } else {
         seq1 = seq2 = seq3 = seq4 = 0; //Here's the problem. AGS says it expects a ';'. When I make it so seq = 0;, then it...
         Display("Sequence failed");
     } else { //...goes here and says that there's a problem with the else. Any ideas?
       seq1 = seq2 = seq3 = seq4 = 0;
       Display("Sequence failed");
   } else {
     seq1 = seq2 = seq3 = seq4 = 0;
     Display("Sequence failed");
 } else {
   seq1 = seq2 = seq3 = seq4 = 0;
   Display("Sequence failed");
 }
}

Archangel (aka SoupDragon)

Instead of using
seq1 = seq2 = seq3 = seq4 = 0;
try
seq1 = 0;
seq2 = 0;
seq3 = 0;
seq4 = 0;

Since AGS doesn't use pure C this might not be supported.

Ishmael

#8
Yes, right.... Who told me to do that? Was it Annie? I though it won't go that way... thanks Archy... ;)

----- EDIT -----

I fixed it, just in case......
I used to make games but then I took an IRC in the knee.

<Calin> Ishmael looks awesome all the time
\( Ö)/ ¬(Ö ) | Ja minähän en keskellä kirkasta päivää lähden minnekään juoksentelemaan ilman housuja.

Mr Jake

couldnt you just use counters??
ie (if its on a Gui):
int Password=0;

if (interface == PWORDSCR.) {
if (button == 1) { //right button is pressed
int password= +1
}
if (button == 2) { //wrong button is pressed
int password= +5
}

Then somewhere (I did this for a ammo/clip in a demo I made) put if (int password > 4) {
DO THIS
}
else if (int Password=4) {
DO THIS)
}
else if (int password < 4) {
DO NOTHING
}
This is VERY bad scripting (hehe, I can remember how to call if (COUNTER=), but I think you should get what I mean

Ishmael

If you put the int declaration inside the function, it turns the to zero every time the function is run, I think. That way it wouldn't work... Or am I wrong?
I used to make games but then I took an IRC in the knee.

<Calin> Ishmael looks awesome all the time
\( Ö)/ ¬(Ö ) | Ja minähän en keskellä kirkasta päivää lähden minnekään juoksentelemaan ilman housuja.

DinghyDog

#11
I think if you do the int declaration inside the function, all that happens is that it becomes a local variable and can only be used within that function. I mean, that's the way it is for other languages...but I could be wrong. Haven't really documented that happening to me...

Oh, and Hotshot, if you do that, then there's a possibility that they might get the four buttons right, but out of order, and that's not what we want. We're looking for the actual order here, cause it's a password.

-DD
It's yer owld pal Dinghy Dog!!

Mr Jake

ok, but even that could be done with just a few lines of 'ifs'

Scorpiorus

Hello, guys. :)

Just want to share the script for the any-sized passwords:

Suppose you have a GUI ("GUIPANEL") with six buttons, so:


button0 -> 'A'
button1 -> 'B'
button2 -> 'C'
button3 -> 'D'
button4 -> 'E'
button5 -> 'F'


now the script...

//main global script

string sequence; // sequence of symbols
string password; // correct password

function game_start() {

StrCopy(password, "ABCDEF"); //initialize the correct password
StrCopy(sequence, "");

}


function interface_click(int interface, int button) {

// if we have clicked on GUIPANEL
if (interface == GUIPANEL) {

// ...pushing down a button
if (button >=0) {

//add new symbol depending on the button pressed:
if      (button == 0) StrCat(sequence, "A"); //add "A"
else if (button == 1) StrCat(sequence, "B"); //add "B"
else if (button == 2) StrCat(sequence, "C"); //add "C"
else if (button == 3) StrCat(sequence, "D"); //add "D"
else if (button == 4) StrCat(sequence, "E"); //add "E"
else if (button == 5) StrCat(sequence, "F"); //add "F"

//now check the order:
if (StrContains(password, sequence) == 0) {

//and check if we have done it successfully
if (StrLen(password)==StrLen(sequence)) Display("That's the correct password!");

}
// else there is a mistake....
else {
       Display("Wrong symbol!");
       StrCopy(sequence, "");
}
   
   
}
   
}

} //end of interface_click()


QuoteIf you put the int declaration inside the function, it turns the to zero every time the function is run, I think. That way it wouldn't work... Or am I wrong?
Yep, that is.


~Cheers

DinghyDog

Ah, see I didn't know you could do that sort of thing with AGS. I've worked with that sort of thing in PERL, but, well, that's really cool.

Great job, man.

-DD
It's yer owld pal Dinghy Dog!!

Scorpiorus

#15
The above script is useful when there is a particular word represented by each button.

button0 -> "EARTH"
button1 -> "PIZZA"
button2 -> "WIND"
button3 -> "FIRE"
...
etc


However, for a letter or numeric sequence you can write a more compact script.

Numeric password example:

button0 -> 0
button1 -> 1
button2 -> 2
...
button8 -> 8
button9 -> 9

//main global script:

int i=0; // current position for checking
string password;

function game_start() {
StrCopy(password, "2034113"); //initialize the correct password
}

function interface_click(int interface, int button) {
if (interface == GUIPANEL) {
if (button > -1) {

     if (button + '0' == StrGetCharAt(password, i)) {
       i++;
       if (i == StrLen(password)) Display("That's the correct password!");
     }
     else {
       Display("Wrong number!");
       i = 0;
     }
     
}
}


} //end of interface_click()


just for reference...

~Cheers

SMF spam blocked by CleanTalk