Random codes and King Arthur question style

Started by , Thu 09/10/2003 10:29:44

Previous topic - Next topic

Neutrino

Hello,

I have 2 questions which are related:

1) The character recieves a security code, for example: 4 digit number.   How can I make the the game to create a code randomly (like a 4 digits number), that will be accepted as the right code throughout the game, until, Of course, the game restarts and a different code is created.


2) A 3 riddles scene, like a "gatekeeper" asks the character 3 question. "what is your quest?..."
Only not the same 3 question, but chooses randomly from a list of 10 questions.
Reference: The Guardian at Erasmus house in QFG 1.

Thanks, ;)

SSH

In your game_start global function, put this code:

SetGlobalInt(99, Random(9999));

which will make Global Int 99 have your 4-digit random number

to make a character ask 3 random questions, you could do it various ways. For example:


int askno=0;
int asked[10];
int question;

while(askno < 3) {
askno++;
question=Random(10);
while (asked[question]==1) {
question=Random(10); // if question already asked, pick another
}
asked[question]=1
if (question==0) {
DisplaySpeech(GATEKEEPER, "What is your name?");
// script your own response stuff here
} else if (question==1) {
DisplaySpeech(GATEKEEPER, "What is your quest?");
// script your own response stuff here
} else if (question==2) {
DisplaySpeech(GATEKEEPER, "What is the air-speed velocity of an unladen swallow?");
// script your own response stuff here
} else if (question==3) {
// alternative method: use a dialog to ask the questions
RunDialog(3);
} // etc.

}
12

Neutrino

Thanks ssh (every question I post, you answer),  ;) ;) ;)

Though it will take me a while to decipher the "3  questions" scripting, I tried unsuccessfully to create the random code.   I think what I'm trying to do is complicated, but I'll let you guys be the judge of that.

I want to create a code made of 4 digits (for a start)
ssh recommended this scripting line in the game_start global function:

SetGlobalInt(99, Random(9999));

--------------------------------------
Next, in a dialog between the player (ego) and another character (Jack), ego asks Jack what is the ego's new code, and Jack replies the code is....<the random code>.

Now, in the dialog I cannot use the 'GetGlobalInt' coomand, so I tried 'run-script' and 'dialog_request', but what next?

When I asks it to 'GetGlobalInt', I think I get it, just not in a formation of a message.

the closest I got was a message with the number '0' (not very random to me)    :-\ ???




SSH

so, your dialog script should call run-script X as you seem to have got.

What you need to do, is in the appropriate part of dialog_request:

DisplaySpeech(JACK, "The new code is %d", GetGlobalInt(99));

however, for codes < 1000 (first digit 0) you will not get the leading 0s displayed.

The easiest way to work around this is to make sure that codes are always >= 1000!

chnage the game_start code to:

SetGlobalInt(99, 1000+Random(8999));
12

Neutrino

Outstanding!
Thank you very much.

The '%d' was the missing link. :-[


Scorpiorus

Quote from: SSH on Thu 09/10/2003 14:59:03however, for codes < 1000 (first digit 0) you will not get the leading 0s displayed.
DisplaySpeech(JACK, "The new code is %04d", GetGlobalInt(99));

That will add leading 0s (up to 4) if necessary.

~Cheers

Neutrino

hmmm...I'm not sure if this should be a new topic, for it is based on the main topic here. :-\

So, in phase 2 I have a code (whether it is a 4 digit code or something like "1w4k6534"), and I create a GUI (say "GUIcode") with a text box.
'ego' interact with hotspot 'keypad', GUIcode appears and 'ego' types the code.

I'm stuck with the scripting for the text box.
How do I make the text box accept only the random code [Display ("Right!")], and to reget all other combinations [Display ("Wrong!")]?

I'm just not sure what command does that "Inputbox" or "Said" (the examples in the help doesn't match the result I want).  Any ideas? ???

Neutrino

Neutrino!

REJECT not reget!

Amateur! ;)

Scorpiorus

#8
Quote from: Neutrino on Fri 10/10/2003 10:10:06I'm stuck with the scripting for the text box.
How do I make the text box accept only the random code [Display ("Right!")], and to reget all other combinations [Display ("Wrong!")]?
So, the correct code is stored in the global int number 99. Suppose you have OK button (number 2) on GUICODE panel:

function interface_click(int interface, int button) {

if (interface == GUICODE) {

//if the player has clicked OK button
if (button == 2) {

string string_code; //buffer to store the entered code

//get code from text box and write it to string_code:
GetTextBoxText (interface, <text box number here>, string_code);

// now convert string_code to integer value
int int_code = StringToInt(string_code);

//finally, check if it's valid
if (int_code == GetGlobalInt(99)) Display("The code is correct!");
else Display ("Wrong code!");

}


}


}


~Cheers

Neuterino

Thank you both. ;) :) ;)
<I'm speechless and I have to consider the bandwidth>
:P

SMF spam blocked by CleanTalk