See Math_quiz1 + quiz2 for some ideas how to do such a quiz.christoferlevich wrote:figure out how to define 'text' as the math problem?
Also, I can't 'find' spawn-mathquiz anywhere!
The spawn-quiz from the old robots-server has not been published on the wiki,
because it requires admin-privileges for some commands, but here it is:
Code: Select all
-- rnd - Spawn-Quiz @ -7 -3 5, with dialog/formspec.
-- When solved, gives apple, and teleports the player out of the spawn-building.
if not s then
s=0
t=0
option = {"A","B","C","D","E"}
generate_question = function()
local a = math.random(10)+0;
local b = math.random(10)+0;
local c = math.random(20)-10;
local d = a*b+c;
msg = "To get out solve the math problem\n\n";
msg = msg .. a.."*"..b.."+"..c .. " = ?\n\n"
problem = a.."*"..b.."+"..c .. " = ?";
correct = math.random(5);
local frm = "";
for i =1,5 do
local offset = 0;
if i~=correct then offset = math.random(10)-5; if offset == 0 then offset = -1 end end
frm = frm .. "button_exit[".. -0.25+(i-1)*1.25 ..",1.75;1.25,1;" .. i .. ";".. d + offset .. "]"
end
local form = "size[6,2.25]" .. "textarea[0.05,-0.3;6.5,2.25;message;;".. msg.."]"..frm;
return form, correct
end
selection = 1;
question = "";
problem = "";
end
if t%10 == 0 then -- new quiz every 10s
t = 0; form,selection = generate_question();
local players = find_player(4);
if players then
for _,pname in ipairs(players) do
self.show_form(pname,form)
end
end
end
t=t+1;
sender,fields = self.read_form()
if sender then
player = _G.minetest.get_player_by_name(sender);
if player then
answer = 0;
for i = 1,5 do if fields[_G.tostring(i)] then answer = i end end
if answer == correct then
player:setpos({x=-4,y=2,z=0})
inv = player:get_inventory(); inv:add_item("main", "default:apple")
_G.minetest.chat_send_player(sender,"<MATH ROBOT> congratulations, here is an apple.")
elseif answer ~= 0 then
player:setpos({x=0,y=-6,z=-1})
say(sender .. " failed to solve the problem " .. problem)
end
end
end
with 5 multiple-choice-buttons in a formspec.
On the old robot-server, the spawn-building was like a cage,
and to get out, players had to solve this quiz.
Commands like player:setpos(), player:get_inventory() and access to _G
require admin-privileges, but for ordinary rewards you don't need these...
BTW, self.show_form() is not listed on the help-page of the robot,
it works "just like" forms when writing regular mods,
so look up the modding-docs.