is it possible??????

Posted By: Blink

is it possible?????? - 07/01/10 14:53

hello all, i am working on an educational game for my classroom. i want to help students study mathematics. as the player goes through certain areas of the level he has to solve math problems, if he gets the wrong answer, he's put in peril. my question is, is it possible to change the math problem and the answer so if someone else plays it or the student wants to play the game again, they get a different question? i already figured i would give the student two chances to solve the problem, and then let them advance after falling into peril twice. is it possible to do this? any ideas would be helpful, and a way to code something like this if possible. you guys know i am not that good at writing code, but i can implement.

thanks in advbance.
Posted By: Beker

Re: is it possible?????? - 07/01/10 15:37

Make a list of questions and number them.

Use a "Random" to have the program select one at random, or "Random" from a particular list according to the level that the player has. It is very simple.
Posted By: MMike

Re: is it possible?????? - 07/01/10 15:58

probably using arrays, and or switchs to select a different case in a different number.
Posted By: Blink

Re: is it possible?????? - 07/01/10 17:35

thanks, what would a script likethis look like? i understand what you mean, but i dont understand how to set something like this up. thanks for the response
Posted By: TrackingKeks

Re: is it possible?????? - 07/01/10 17:52

I don't use c-script so I can only give you some tips. tongue
You could store all the information in one or many files and read them out in ab big array. Then you could every time the play enters one new place use the same dialog with TEXT objects.
The content should be choosen by "random()".

Perhaps you could add that the choosen question is only shown one time per round by adding an array where every value is set to 0 and only after showing the question it is set to 1.

I have done all this for a quiz one time (it was a project for school grin ).

Posted By: Blink

Re: is it possible?????? - 07/02/10 01:53

thanks, i understand, maybe someone will help me with an example i can work off. i was given a code by a member in lite-c, and i tried to convert it to c-script with no luck,lol. hopefully someone can write a script here that i can work with. this is a bit challenging for me.
Posted By: Doc_Savage

Re: is it possible?????? - 07/03/10 19:13

i may not know much about coding yet, but i think this is a VERY possible thing to do with the "random" command, i think somthing along the lines of making every set of math problems a function, or somthing like it, and giving each function a sort of "call number" saying "hey math problem set 1, youre up this round." and then finding a way to randomize which number is picked each time the game starts. i also commend your efforts to bring gaming to an exeptionally good cause.


....well theres my 2 cents tongue
Posted By: tD_Datura_v

Re: is it possible?????? - 07/03/10 23:36

Code:
//A6.60 c-script
/*
	snippet from _helpyqz.wdl
	(c)opyright dummy collective
	may only be used without permission
*/
// TEXT used to show a question
TEXT qz_tQuestion {
	red = 255;
	green = 225;
	blue = 255;
	pos_x = 0;
	pos_y = 0;
	strings = 1;
	flags = VISIBLE;
}
// contains a list of answers some of which are incorrect
TEXT qz_tAnswers {
	red = 255;
	green = 225;
	blue = 255;
	pos_x = 0;
	pos_y = 50;
	strings = 4;
	flags = VISIBLE;
}
// contains a list of answers and questions in no particular order
// loaded from qz.txt
// see format file qz.txt
TEXT qz_tLoad {
	strings = 60000;
}
var qz_nAnswer = 0;	// the actual answer index in the questions TEXT
var qz_nLoad = 0;		// number of lines loaded from qz.txt
var qz_bQuestionFound = 0;	// result for qzf_getQuestion
var qz_bAnswerFound = 0;	// result for qzf_getAnswer
STRING qz_sAnswer[1024];		// an answer temp string used with qzf_getAnswer
STRING qz_sQuestion[1024];	// a question temp string used with qzf_getQuestion
STRING qz_sNum[128];	// used to convert number to STRING in multiple functions

function random_int(_nLow, _nHigh) {
	return(int(_nLow + ((_nHigh - _nLow) * random(1.001))));
}
// returns 1 if _sIn starts with _sFind
function str_starts(_sIn, _sFind) {
	return(str_stri(_sIn, _sFind) == 1);
}
// loads qz_tAnswers with random answers, non of which are _nNotNumber (the correct answer)
function qzf_getRandomAnswers(_nAnswers, _nNotNumber) {
	var n; n = random_int(0, qz_nLoad);
	var nCalls; nCalls = 0;
	var nAnswersFound; nAnswersFound = 0;
	while(nCalls < qz_nLoad * 5) {
		n = random_int(0, qz_nLoad - 1);
		if (n != _nNotNumber) {
			qzf_getAnswer(n);
			if (qz_bAnswerFound) {
				str_cpy(qz_tAnswers.string[nAnswersFound], qz_sAnswer);
				nAnswersFound += 1;
				if (nAnswersFound >= _nAnswers) { break; }
			}
		}
		nCalls += 1;
	}
}
// sets qz_sAnswer to answer in qz.txt
// modifies qz_bAnswerFound
function qzf_getAnswer(_nNumber) {
	str_cpy(qz_sAnswer, "");
	var n; n=0;
	qz_bAnswerFound = 0;
	while(n < qz_nLoad) {
		str_for_num(qz_sNum, _nNumber);
		str_cat(qz_sNum, "a");
		if (str_starts(qz_tLoad.string[n], qz_sNum)) {
			str_cpy(qz_sAnswer, qz_tLoad.string[n]);
			str_clip(qz_sAnswer, str_len(qz_sNum));
			qz_bAnswerFound = 1;
			return(n);
		}
		n+=1;
	}
}
// sets qz_sQuestion to question number _nNumber in qz.txt
// modifies qz_bQuestionFound
function qzf_getQuestion(_nNumber) {
	str_cpy(qz_sQuestion, "");
	var n; n=0;
	qz_bQuestionFound = 0;
	while(n < qz_nLoad) {
		str_for_num(qz_sNum, _nNumber);
		str_cat(qz_sNum, "q");
		if (str_starts(qz_tLoad.string[n], qz_sNum)) {
			str_cpy(qz_sQuestion, qz_tLoad.string[n]);
			str_clip(qz_sQuestion, str_len(qz_sNum));
			qz_bQuestionFound = 1;
			return(n);
		}
		n+=1;
	}
}
// loads all questions and answers from _sFileName into qz_tLoad
// modifies qz_nLoad (number of lines loaded)
function qzf_load(_sFileName) {
	if (_sFileName == 0) { return(0); }
	qz_nLoad = txt_load(qz_tLoad, _sFileName);
	if (qz_nLoad == 0) { error("no questions loaded"); }
	return(qz_nLoad);
}

// a test function
// call once from main
// press 1 , 2, or 3 key to select question 1, 2 or 3 
// and generate 3 random answers plus one correct one
// note to fix: the 3 random answers might not be unique
function qzf_input() {
	qzf_load("qz.txt");
	while(1) {
		wait(1);
		var n; n = 0;
		if (key_1) { n = 1; }
		if (key_2) { n = 2; }
		if (key_3) { n = 3; }
		if (n != 0) {
			qzf_getQuestion(n);
			str_cpy(qz_tQuestion.string[0], qz_sQuestion);
			qzf_getRandomAnswers(3, n);
			qzf_getAnswer(n);
			if (qz_bAnswerFound) {
			
				qz_nAnswer = random_int(0, 3);
				str_cpy(qz_tAnswers.string[3], qz_tAnswers.string[qz_nAnswer]);
				str_cpy(qz_tAnswers.string[qz_nAnswer], qz_sAnswer);
			}
		}
	}
}

/////////////////////////////////////////////////////////////////
// Desc: The main() function is started at game start
function main()
{
	randomize();
	// set some common flags and variables
	// freeze all entity functions
	freeze_mode = 1;
	// no level has been loaded yet...
	gid01_level_state = gid01_level_not_loaded;

// entry: Warning Level (0,1, or 2)
// entry_help: Sets sensitivity to warnings (0 = none, 1 = some, 2 = all).
	warn_level = 2;	// announce bad texture sizes and bad wdl code


// entry: Starting Mouse Mode (0, 1, or 2)
	mouse_mode = 0;

	// wait 3 frames (for triple buffering) until it is flipped to the foreground
	wait(3);

	qzf_input();
	
	// now load the level
	level_load(level_str);

	wait(2);	// let level load
	// level should be loaded at this point...
	gid01_level_state = gid01_level_loaded;

//+++ load starting values


	// un-freeze the game
	freeze_mode = 0;

	// save start of game here
	wait(6);   // allow time for functions that wait for "gid01_level_loaded" to load
	file_delete("start0.SAV");	// remove any old savefile
	wait(1);
	if( game_save("start",0,SV_ALL) <= 0)
	{
		diag("\nWARNING! main - Cannot save 'start' of level (ignore on restarts).");
	}
	else
	{
		diag("\nWDL: main - Game 'start' saved.");
	}


	// main game loop
	while(1)
	{
		if(gid01_level_state != gid01_level_loaded)
		{
			freeze_mode = 1;  // pause the game
			while(gid01_level_state != gid01_level_loaded) { wait(1); }
			freeze_mode = 0;  // resume the game
		}
		wait(1);
	}

}



format of qz.txt
Questions start with a prefix "0q", where 0 is the number of the question.
Answers start with a prefix "0a", where 0 is the number of the answer to question number 0.

Code:
1qQuestion1
2qQuestion2
3qQuestion3
4qQuestion4
5qQuestion5
6qQuestion6
7qQuestion7
8qQuestion8
1aAnswer1
2aAnswer2
3aAnswer3
4aAnswer4
5aAnswer5
6aAnswer6
7aAnswer7
8aAnswer8


Well that was fun.
Maybe that helps for a start, or maybe it doesn't.
Posted By: Blink

Re: is it possible?????? - 07/04/10 04:37

Thank you so much tD, i will try to implement this. how many times have you saved me? ok, so if i create a node or a block that needs an action like "action quiz_me;", that should start the quiz in that area of my level, right? i am not sure which function to use to create the action.
Posted By: tD_Datura_v

Re: is it possible?????? - 07/04/10 19:54

Blink, that was just an example, and maybe not a good one at that.
Here is a little bit more, but this might not be much more helpful than what was offered before.
Code:
//A6.60 c-script
/*
	snippet from _helpyqz.wdl
	(c)opyright dummy collective
	may only be used without permission
*/
// TEXT used to show a question
TEXT qz_tQuestion {
	red = 255;
	green = 225;
	blue = 255;
	pos_x = 0;
	pos_y = 0;
	strings = 1;
	flags = VISIBLE;
}
// contains a list of answers some of which are incorrect
TEXT qz_tAnswers {
	red = 255;
	green = 225;
	blue = 255;
	pos_x = 0;
	pos_y = 15;
	strings = 4;
	flags = VISIBLE;
}


TEXT qz_tResult {
	red = 255;
	green = 255;
	blue = 255;
	pos_x = 0;
	pos_y = 60;
	strings = 1;
	flags = VISIBLE;
}
// contains a list of answers and questions in no particular order
// loaded from qz.txt
// see format file qz.txt
TEXT qz_tLoad {
	strings = 60000;
}
var qz_nStage = 0;
var qz_nQuestion = 0;
var qz_nQuestionsUsed = 0;
var qz_naQuestionsUsed[30000];

var qz_nAnswer = 0;	// the actual answer index in the questions TEXT
var qz_nLoad = 0;		// number of lines loaded from qz.txt
var qz_bQuestionFound = 0;	// result for qzf_getQuestion
var qz_bAnswerFound = 0;	// result for qzf_getAnswer
STRING qz_sAnswer[1024];		// an answer temp string used with qzf_getAnswer
STRING qz_sQuestion[1024];	// a question temp string used with qzf_getQuestion
STRING qz_sNum[128];	// used to convert number to STRING in multiple functions

define k_1, 2;
define k_2, 3;
define k_3, 4;
define k_4, 5;

function random_int(_nLow, _nHigh) {
	return(int(_nLow + ((_nHigh - _nLow) * random(1.001))));
}
// returns 1 if _sIn starts with _sFind
function str_starts(_sIn, _sFind) {
	return(str_stri(_sIn, _sFind) == 1);
}
function qzf_clearQuestionsUsed() {
	var n; n=0;
	while(n < qz_nQuestionsUsed) {
		qz_naQuestionsUsed[n] = 0;
		n+=0;
	}
	qz_nQuestionsUsed = 0;
}
function qzf_questionWasUsed(_nQuestion) {
	var n; n=0;
	while(n < qz_nQuestionsUsed) {
		if (qz_naQuestionsUsed[n] == _nQuestion) {
			return(1);
		}
		n+=1;
	}
	return(0);
}
function qzf_getRandomQuestion() {
	var n; n = random_int(0, qz_nLoad);
	var nCalls; nCalls = 0;
	var nAnswersFound; nAnswersFound = 0;
	while(nCalls < (qz_nLoad * 5)) {
		n = random_int(1, qz_nLoad);
		if (0 == qzf_questionWasUsed(n)) {
			qz_nQuestion = n;
			return(n);
		}
		nCalls += 1;
	}
	if (nCalls >= (qz_nLoad * 5)) {
		qzf_clearQuestionsUsed();
	}
}
function qzf_checkAnswerKey(_nAnswerIndex, _nScanCode) {
	if (_nAnswerIndex == 0 && _nScanCode == k_1) { return(1); }
	if (_nAnswerIndex == 1 && _nScanCode == k_2) { return(1); }
	if (_nAnswerIndex == 2 && _nScanCode == k_3) { return(1); }
	if (_nAnswerIndex == 3 && _nScanCode == k_4) { return(1); }
	return(0);
}

// loads qz_tAnswers with random answers, non of which are _nNotNumber (the correct answer)
function qzf_getRandomAnswers(_nAnswers, _nNotNumber) {
	var n; n = 0;
	var nCalls; nCalls = 0;
	var nAnswersFound; nAnswersFound = 0;
	while(nCalls < qz_nLoad * 5) {
		n = random_int(1, qz_nLoad);
		if (n != _nNotNumber) {
			qzf_getAnswer(n);
			if (qz_bAnswerFound) {
				str_cpy(qz_tAnswers.string[nAnswersFound], qz_sAnswer);
				nAnswersFound += 1;
				if (nAnswersFound >= _nAnswers) { break; }
			}
		}
		nCalls += 1;
	}
}
// sets qz_sAnswer to answer in qz.txt
// modifies qz_bAnswerFound
function qzf_getAnswer(_nNumber) {
	str_cpy(qz_sAnswer, "");
	var n; n=0;
	qz_bAnswerFound = 0;
	while(n < qz_nLoad) {
		str_for_num(qz_sNum, _nNumber);
		str_cat(qz_sNum, "a");
		if (str_starts(qz_tLoad.string[n], qz_sNum)) {
			str_cpy(qz_sAnswer, qz_tLoad.string[n]);
			str_clip(qz_sAnswer, str_len(qz_sNum));
			qz_bAnswerFound = 1;
			return(n);
		}
		n+=1;
	}
}
// sets qz_sQuestion to question number _nNumber in qz.txt
// modifies qz_bQuestionFound
function qzf_getQuestion(_nNumber) {
	str_cpy(qz_sQuestion, "");
	var n; n=0;
	qz_bQuestionFound = 0;
	while(n < qz_nLoad) {
		str_for_num(qz_sNum, _nNumber);
		str_cat(qz_sNum, "q");
		if (str_starts(qz_tLoad.string[n], qz_sNum)) {
			str_cpy(qz_sQuestion, qz_tLoad.string[n]);
			str_clip(qz_sQuestion, str_len(qz_sNum));
			qz_bQuestionFound = 1;
			return(n);
		}
		n+=1;
	}
}
// loads all questions and answers from _sFileName into qz_tLoad
// modifies qz_nLoad (number of lines loaded)
function qzf_load(_sFileName) {
	if (_sFileName == 0) { return(0); }
	qz_nLoad = txt_load(qz_tLoad, _sFileName);
	if (qz_nLoad == 0) { error("no questions loaded"); }
	return(qz_nLoad);
}


function qzf_quizMe() {
	qzf_load("qz.txt");
	qz_nStage = 1;
	while(qz_nStage) {
		qzf_getRandomQuestion();
		qzf_getQuestion(qz_nQuestion);
		str_cpy(qz_tQuestion.string[0], qz_sQuestion);
		qzf_getRandomAnswers(3, qz_nQuestion);
		qzf_getAnswer(qz_nQuestion);
		if (qz_bAnswerFound) {
			qz_nAnswer = random_int(0, 3);
			str_cpy(qz_tAnswers.string[3], qz_tAnswers.string[qz_nAnswer]);	
			str_cpy(qz_tAnswers.string[qz_nAnswer], qz_sAnswer);
			qz_nStage = 2;
			while(qz_nStage == 2) {
				if (key_1 || key_2 || key_3 || key_4) { qz_nStage = 3; }
				wait(1);
			}
			if (qz_nStage == 3) {
				if (qzf_checkAnswerKey(qz_nAnswer, key_lastpressed)) {
					str_cpy(qz_tResult.string[0], "correct");
				} else {
					str_cpy(qz_tResult.string[0], "wrong");
				}
				while(0 == key_enter) { wait(1); }
				str_cpy(qz_tResult.string[0], "");
				qz_nStage = 1;
			}
		}
		wait(1);
	}
}


There are new functions including "qzf_quizMe".
When placed in main qzf_quizMe should serve up questions from qz.txt.
Press 1, 2, 3, 4 and "correct" or "wrong" might be displayed.
Press the ENTER key and another question might be displayed...or maybe not.
Posted By: MMike

Re: is it possible?????? - 07/04/10 20:51

hehe with that code i think you kinda killeed him.

The random is not always random! you should use random_seed(0); or something because even the random is based on a "predictable random number"
Posted By: Blink

Re: is it possible?????? - 07/05/10 05:06

thanks, i will give it a try.
Posted By: Blink

Re: is it possible?????? - 07/06/10 00:54

well, the good news is, i created an action and the quiz showed up, but it started when the level ran, and when i pressed the number 1 it said answer correct, and stayed onscreen. i have to adjust the action to do what i want it to do. i want to impact with an object, and then have the question asked, and then after i answer, the object disappears (ent_remove)and i can move past the object to complete the level. now here is the difficult part. if the question was incorrect, and you passed the object, the "path" that you are on will be perilous, but if you answer correctly, the path will be safe, does this sound possible? it seems like a lot.
Posted By: Why_Do_I_Die

Re: is it possible?????? - 07/10/10 08:43

Blink , you can just have a function that creates all the perilous traps or whatever that is called upon answering the question right. I.e.
if(answer != correct)
{
level_1_path_1_perils();
}
function level_1_path_1_perils()
{
create traps, monsters ect...
}

Another way to do it would be to have a main path , with side paths that contain the traps and monsters , and have the question areas , where there are is the main path as well as a side path, both obstructed by a rock or a gate or something , and if you answer wrong , then the rock breaks or gate opens to the side path which will be the perilous one , once you get through the side path , it will join the main patch again in a question area , where you repeat the process. The advantage to this way is you can build the whole level in WED , and set up the paths , traps and enemies exactly as you want and just save the level, where in the first option I put you'd have to set up the whole level , then write all the trap and monster positions for each perilous path to a unique function for each question. Hope it helps.
Posted By: Blink

Re: is it possible?????? - 07/10/10 13:34

ok, i like that idea. i will give it a shot. try to create the function. i havent really thought through the puzzles yet. but that seems like a great idea how to use the traps. thanks!
Posted By: CoburnDomain

Re: is it possible?????? - 07/12/10 04:59

You could always have multiple paths - getting a question wrong opens up the "bad" door which has a path that has traps, etc. If the user answers correctly, a "good" door is opened that gives players bonuses, lives, coins, etc.
Posted By: Blink

Re: is it possible?????? - 07/12/10 11:08

i have been thinking about that. originally, that was the idea instead of coding. i would have the answer to the riddle be one door with alternate doors as choices. i just thought that would make my levels too big. i will actually give it a try. thanks.
© 2024 lite-C Forums