|
random question
#357240
02/06/11 10:36
02/06/11 10:36
|
Joined: Sep 2010
Posts: 97
carla_mariz
OP
Junior Member
|
OP
Junior Member
Joined: Sep 2010
Posts: 97
|
hello, how can i make a question that shows randomly in every level? at every level there should be 5 questions but only one will be shown. i want it to become ramdom so that every time the player enters the level, there will be different question to be answered. and the answer to the question must be correct. how can i make the answer correct if the question is shown randomly? by the way, the answer to the question can be found at the maze/game and it is a 3d model. and the question to be shown could be .BMP or .tga or .pcx file types. pls help me. thanks! 
|
|
|
Re: random question
[Re: carla_mariz]
#357250
02/06/11 11:29
02/06/11 11:29
|
Joined: Dec 2008
Posts: 605 47°19'02.40" N 8°32'54.67"...
hopfel
User
|
User
Joined: Dec 2008
Posts: 605
47°19'02.40" N 8°32'54.67"...
|
Make a 2D-array, fill it with the correct and with the entity- or bitmap-pointer:
var question[5][3]; //2D-Array, for 5 questions
...
function question_fill()
{
...
//fill the array for the first question
question[0][0] = 1; //the right answer is 1
question[0][1] = bmap_create("question.bmp"); //question-bitmap
question[0][2] = ent_create("answer_entity.mdl",nullevctor,NULL); // answer-entity
...
}
...
function question_ask()
{
var random_number = integer(random(4.9)); //make it random
...
if(my_answer == question[random_number][3])
{
((ENTITY*)question[0][2]).alpha = 100;
}
...
}
This example isn't complete, just to show you how you could do that. ^^ There are more ways, I guess, but I would do it that way.  Hope it helps... ~greets
Hilf mir, dir zu helfen!
|
|
|
Re: random question
[Re: hopfel]
#357263
02/06/11 12:53
02/06/11 12:53
|
Joined: Sep 2010
Posts: 97
carla_mariz
OP
Junior Member
|
OP
Junior Member
Joined: Sep 2010
Posts: 97
|
uh oh..i think its a little bit complicated for me. but i'll try it though.  i hope there is more easiest way to do it. thanks^_^
Last edited by carla_mariz; 02/06/11 12:54.
|
|
|
Re: random question
[Re: hopfel]
#357295
02/06/11 15:35
02/06/11 15:35
|
Joined: Jul 2008
Posts: 1,178 England
MrGuest
Serious User
|
Serious User
Joined: Jul 2008
Posts: 1,178
England
|
Make a 2D-array, fill it with the correct and with the entity- or bitmap-pointer:
var question[5][3]; //2D-Array, for 5 questions
...
function question_fill()
{
...
//fill the array for the first question
question[0][0] = 1; //the right answer is 1
question[0][1] = bmap_create("question.bmp"); //question-bitmap
question[0][2] = ent_create("answer_entity.mdl",nullevctor,NULL); // answer-entity
...
}
...
function question_ask()
{
var random_number = integer(random(4.9)); //make it random
...
if(my_answer == question[random_number][3])
{
((ENTITY*)question[0][2]).alpha = 100;
}
...
}
This example isn't complete, just to show you how you could do that. ^^ There are more ways, I guess, but I would do it that way.  Hope it helps... ~greets unsure why you're storing trying to store entities and bmaps in variables? just create what you need as a struct then if you're not happy creating them dynamically or in an array then create them like so:
#include <acknex.h>
#include <default.c>
typedef struct RND_Q {
BMAP* bmap;
char* model;
int answer;
} RND_Q;
RND_Q* rnd_q; //pointer for array of structs
int int_rndQuestionCount; //stores the number of random questions
int int_rndQuestionSelected;
//panel for displaying the question
PANEL* pnl_question = {
flags = SHOW;
}
//function for adding question to the pool
void question_add(char* bmp, char* model, int answer){
int i = int_rndQuestionCount;
int_rndQuestionCount++;
rnd_q = realloc(rnd_q, sizeof(RND_Q) * (int_rndQuestionCount));
rnd_q[i].bmap = bmap_create(bmp);
rnd_q[i].model = model;
rnd_q[i].answer = answer;
}
void main(){
wait(1);
question_add("q01.bmp", "q01.mdl", 1);
question_add("q02.bmp", "q02.mdl", 4);
question_add("q03.bmp", "q03.mdl", 2);
question_add("q04.bmp", "q04.mdl", 1);
random_seed(0);
int_rndQuestionSelected = random(integer(int_rndQuestionCount)); //randomly generates a question
//rnd_q[int_rndQuestionSelected].bmap; //stores the question image
//rnd_q[int_rndQuestionSelected].model; //stores the mode name
//rnd_q[int_rndQuestionSelected].answer; //stores the correct answer
//so to display the question in pnl_question use
pnl_question.bmap = rnd_q[int_rndQuestionSelected].bmap;
}
|
|
|
Re: random question
[Re: Logan]
#357678
02/08/11 08:08
02/08/11 08:08
|
Joined: Sep 2010
Posts: 97
carla_mariz
OP
Junior Member
|
OP
Junior Member
Joined: Sep 2010
Posts: 97
|
while i was looking at the struct tutorials it made me looked O.o .. im trying my best to understand, and somehow i did. but can i ask what should i put in the "PANEL* pnl_question " because it was empty? How?
Last edited by carla_mariz; 02/08/11 22:37.
|
|
|
Re: random question
[Re: carla_mariz]
#358418
02/11/11 04:28
02/11/11 04:28
|
Joined: Sep 2010
Posts: 97
carla_mariz
OP
Junior Member
|
OP
Junior Member
Joined: Sep 2010
Posts: 97
|
pls answer me here... 
#include <acknex.h>
#include <default.c>
typedef struct RND_Q {
BMAP* questions;
char* model;
// int answer;
} RND_Q;
RND_Q* rnd_q; //pointer for array of structs
int int_rndQuestionCount; //stores the number of random questions
int int_rndQuestionSelected;
//panel for displaying the question
PANEL* pnl_question = {
flags = SHOW;
}
//function for adding question to the pool
void question_add(char* questions, char* model)
{
int i = int_rndQuestionCount;
int_rndQuestionCount++;
rnd_q = realloc(rnd_q, sizeof(RND_Q) * (int_rndQuestionCount));
rnd_q[i].questions = bmap_create(questions);
rnd_q[i].model = model;
// rnd_q[i].answer = answer;
}
void main(){
wait(1);
question_add("tanong1.tga", "paccherry.mdl");
question_add("tanong2.tga", "bilog.mdl");
question_add("tanong3.tga", "heart.mdl");
question_add("tanong4.tga", "strip.mdl");
random_seed(0);
int_rndQuestionSelected = random(integer(int_rndQuestionCount)); //randomly generates a question
//rnd_q[int_rndQuestionSelected].bmap; //stores the question image
//rnd_q[int_rndQuestionSelected].model; //stores the mode name
//rnd_q[int_rndQuestionSelected].answer; //stores the correct answer
//so to display the question in pnl_question use
pnl_question.questions = rnd_q[int_rndQuestionSelected].questions;
}
is this correct??because when i run the script there's an error saying "questions is not a member of PANEL" in "pnl_question.questions = rnd_q[int_rndQuestionSelected].questions;"
|
|
|
Re: random question
[Re: xbox]
#358424
02/11/11 08:48
02/11/11 08:48
|
Joined: Sep 2010
Posts: 97
carla_mariz
OP
Junior Member
|
OP
Junior Member
Joined: Sep 2010
Posts: 97
|
it doesn't show anything..its just black.  how can i make the bmp appear randomly at every load of the game??? pls help me...
|
|
|
Re: random question
[Re: carla_mariz]
#358433
02/11/11 10:31
02/11/11 10:31
|
Joined: Jul 2008
Posts: 1,178 England
MrGuest
Serious User
|
Serious User
Joined: Jul 2008
Posts: 1,178
England
|
pnl_question.bmap = rnd_q[int_rndQuestionSelected].questions;
will display the question make sure the images for the questions exist and they're in the same folder as your .c file.
|
|
|
|