Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
7 registered members (clonman, TipmyPip, Niels, dBc, Ed_Love, 3run, 1 invisible), 18,869 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 3 1 2 3
random question #357240
02/06/11 10:36
02/06/11 10:36
Joined: Sep 2010
Posts: 97
C
carla_mariz Offline OP
Junior Member
carla_mariz  Offline OP
Junior Member
C

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! laugh

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 Offline
User
hopfel  Offline
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:

Code:
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. laugh
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
C
carla_mariz Offline OP
Junior Member
carla_mariz  Offline OP
Junior Member
C

Joined: Sep 2010
Posts: 97
uh oh..i think its a little bit complicated for me. but i'll try it though. laugh
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
M
MrGuest Offline
Serious User
MrGuest  Offline
Serious User
M

Joined: Jul 2008
Posts: 1,178
England
Originally Posted By: hopfel
Make a 2D-array, fill it with the correct and with the entity- or bitmap-pointer:

Code:
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. laugh
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:
Code:
#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: MrGuest] #357312
02/06/11 17:03
02/06/11 17:03
Joined: Jan 2011
Posts: 120
United States
Logan Offline
Member
Logan  Offline
Member

Joined: Jan 2011
Posts: 120
United States
I was going to say use a struct too. The concept behind it can be confusing and abstract at first, but it really is the best way to solve your problem. Since it's more important for you to actually LEARN how to solve your problem instead of just copy&pasting code from the forum, I'd recommend you check out the manual page on structs and see if you can figure out how to use them yourself, and then if you need to, come back and pick from MrGuest's code (nicely written by the way wink ).

Re: random question [Re: Logan] #357678
02/08/11 08:08
02/08/11 08:08
Joined: Sep 2010
Posts: 97
C
carla_mariz Offline OP
Junior Member
carla_mariz  Offline OP
Junior Member
C

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
C
carla_mariz Offline OP
Junior Member
carla_mariz  Offline OP
Junior Member
C

Joined: Sep 2010
Posts: 97
pls answer me here... frown

Code:
#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: carla_mariz] #358419
02/11/11 05:14
02/11/11 05:14
Joined: Nov 2006
Posts: 497
Ohio
xbox Offline
Senior Member
xbox  Offline
Senior Member

Joined: Nov 2006
Posts: 497
Ohio
this is because "questions" is not a member of PANEL* pnl_question. It's only a member of struct RND_Q therefore you can only call it by first stating;

rnd_q.questions

Re: random question [Re: xbox] #358424
02/11/11 08:48
02/11/11 08:48
Joined: Sep 2010
Posts: 97
C
carla_mariz Offline OP
Junior Member
carla_mariz  Offline OP
Junior Member
C

Joined: Sep 2010
Posts: 97
it doesn't show anything..its just black. frown

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
M
MrGuest Offline
Serious User
MrGuest  Offline
Serious User
M

Joined: Jul 2008
Posts: 1,178
England
Code:
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.

Page 1 of 3 1 2 3

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1