Debian Codegraph @

lua/quiz/helper.lua

raw symbols SCIP
1 --[[
2 Copyright (C) 2014 HarpyWar ([email protected])
3
4 This file is a part of the PvPGN Project http://pvpgn.pro
5 Licensed under the same terms as Lua itself.
6 ]]--
7
8
9 -- Get path to Quiz directory
10 function q_directory()
11 return config.scriptdir .. "/quiz"
12 end
13
14 -- Replace each symbol in string with *
15 -- Example: input = "hello world", return = "***** *****"
16 function q_hide_unswer(input)
17 local output = input
18 for i = 1, #input do
19 local c = input:sub(i,i)
20 if not (c == " ") then
21 output = replace_char(i, output, "*")
22 end
23 end
24 return output
25 end
26
27 -- Open one random symbol in hidden (with *) string from original string
28 -- Example: hidden = "***** *****", original = "hello world", return = "***l* *****"
29 function q_show_next_symbol(hidden, original)
30 local output = hidden
31
32 if hidden == original then
33 return output
34 end
35
36 local replaced = false
37 while not replaced do
38 local i = math.random(#hidden)
39 local c = hidden:sub(i,i)
40 if c == "*" then
41 local c2 = original:sub(i,i)
42 output = replace_char(i, hidden, c2)
43 replaced = true
44 end
45 end
46 return output
47 end
48
49
50
51 -- Callback to sort records table descending
52 function q_compare_desc(a,b)
53 return tonumber(a.points) > tonumber(b.points)
54 end