[Script] Funções |
1 | ||
Uma lista de funções que complementam a api LUA do transformice, sinta-se livre para enviar funções que NÃO estejam no tópico, a fim de tornar ele mais robusto e completo. Árvore do tópico
math.pythag Argumentos:
[Number] yPos1 - posição vertical do ponto [Number] xPos2 - posição horizontal central do circulo [Number] yPos2 - posição vertical central do circulo [Number] range - raio do circulo function math.pythag(xPos1, yPos1, xPos2, yPos2, range) return ((xPos1 - xPos2)^2 + (yPos1 - yPos2)^2 < range^2) end math.randomMultiple Argumentos:
[Number] min - o menor número aleatório [Number] max - o maior número aleatório function math.randomMultiple(multiplier, min, max) return math.ceil((math.random()*(max-min)+min)/multiplier)*multiplier; end math.average Argumentos:
function math.average(...) local result = 0 for i = 1, select('#', ...) do result = result + select(i, ...) end return result / select('#', ...) end math.prime Argumentos:
function math.prime(value) if value == 1 or (value ~= 2 and value % 2 == 0) then return false elseif value == 2 then return true end for i = 2, math.ceil(value^0.5) do if i ~= 2 and i % 2 ~= 0 then if value % i == 0 then return false end end end return true end math.primes Argumentos:
[Number] b - o número máximo function math.primes(a,b) assert(type(math.prime) == 'function', 'É necessário a função math.prime!') local result = {} for i = a, b do if math.prime(i) then result[#result+1] = i end end return result end math.hypo Argumentos:
[Number] x2, y2 - coordenada horizontal e vertical do ponto 2 function math.hypo(x1,y1,x2,y2) return ((x2-x1)^2 + (y2-y1)^2)^0.5 end math.neg Argumentos:
function math.neg(number) return number == 0 and 0 or number < 0 end string.split Argumentos:
[String] separator - o separador, que dividirá rawString function string.split(rawString, separator) splittedString = {} for str in string.gmatch(rawString, "[^"..separator.."]+") do table.insert(splittedString, str) end return splittedString end string.title Argumentos:
function string.title(rawString) if type(string.split) == "function" then allWords = string.split(rawString, " ") for index, word in pairs(allWords) do allWords[index] = string.gsub(string.lower(word), "%a", string.upper, 1) end return table.concat(allWords, " ") else error("string.split function is needed") end end string.startswith Argumentos:
[String] toCompare - a cadeia de caracteres a ser comparada function string.startswith(rawString, toCompare) return (string.sub(rawString, 0, string.len(toCompare)) == toCompare) end string.endswith Argumentos:
[String] toCompare - a cadeia de caracteres a ser comparada function string.endswith(rawString, toCompare) return (string.sub(rawString, -string.len(toCompare)) == toCompare) end string.count Argumentos:
[String] toCompare - a cadeia de caracteres a ser contada function string.count(rawString, toCount) _, count = string.gsub(rawString, toCount, "") return count end string.isNumeric Argumentos:
function string.isNumeric(rawString) return (tonumber(rawString) ~= nil) end string.getsubstring Argumentos:
[String] toSub - a cadeia de caracteres a ser extraida function string.getsubstring(rawString, toSub) return (string.sub(rawString, string.len(toSub))) end table.getl Argumentos:
function table.getl(rawTable) count = 0 for index in pairs(rawTable) do count = count+1 end return count end table.getkeys Argumentos:
function table.getkeys(rawTable) keys = {} for index in pairs(rawTable) do table.insert(keys, index) end return keys end table.contains Argumentos:
[Table] existentValue - o valor a ser checado na tabela function table.contains(rawTable, existentValue) for index, value in pairs(rawTable) do if value == existentValue then return true end end return false end system.bindKeyboard Argumentos:
[Number/Table] teclas - as teclas para serem ativadas [Boolean] Ativar - ativa ou desativa o callback para as teclas system._bindKeyboard = system.bindKeyboard function system.bindKeyboard(name, keys, down, enabled) if type(keys) == "table" then for i = 1, #keys do system._bindKeyboard(name, keys, down, enabled) end else system._bindKeyboard(name, keys, down, enabled) end end Dernière modification le 1460304840000 |
0 | ||
interessante... vou tentar aprender sobre isso parabéns pelo tpc, esh |
Logmini « Citoyen » 1452437100000
| 0 | ||
Esh você com esse avatar e falando de modules está tão adorável Dá até vontade de aprender. |
Vladlenin « Censeur » 1452440160000
| 0 | ||
Valeu , me ajudou um pouco esse avatar de hamtaro também ajudou muito |
Laagaadoo « Citoyen » 1452441240000
| 0 | ||
muito bom o tópico éxi |
Fofinhoppp « Consul » 1452457080000
| 0 | ||
Esse esh só sabe ser mito |
Squalleze « Citoyen » 1452470280000
| 0 | ||
Quase morri quando vi seu string.title, toma esse que eu fiz, ele faz a mesma coisa. string.title = function(a) return a:gsub("(%S+)", function(b) return b:gsub("%a", string.upper, 1) end) end |
0 | ||
Squalleze a dit : o problema dessa função é que ela não normaliza a string +eshkatiOn vira +EshkatiOn, mas continua sendo uma ótima solução :p |
Squalleze « Citoyen » 1452480000000
| 0 | ||
Eshkation a dit : Só editar '-' string.title = function(a) return a:gsub("(%S+)", function(b) return b:lower():gsub("%a", string.upper, 1) end) end Dernière modification le 1452480120000 |
Squalleze 1452480120000
| | ||
[Modéré par Miau, raison : Double post acidental.] |
Laagaadoo « Citoyen » 1459198620000
| 0 | ||
system._bindKeyboard = system.bindKeyboard function system.bindKeyboard(name, keys, down, enabled) if type(keys) == "table" then for i = 1, #keys do system._bindKeyboard(name, keys, down, enabled) end else system._bindKeyboard(name, keys, down, enabled) end end Assim você pode bindar várias keys ou só uma desse jeito: a dit : |
Yang 1459663500000
| | ||
[Modéré par Ratodisco] |
Laagaadoo « Citoyen » 1460149080000
| 0 | ||
math.average a dit : Calcula a média dos valores Dernière modification le 1460149620000 |
0 | ||
Adicionadas ao tópico! |
Nyrket « Citoyen » 1460163960000
| 0 | ||
Eu sou noob neste ramo... Nem me esforço. Faço mais mapas mesmo. Parabéns pelo tópico, Esh. |
Laagaadoo « Citoyen » 1460225400000
| 0 | ||
math.prime function math.prime(value) if value == 1 or (value ~= 2 and value % 2 == 0) then return false elseif value == 2 then return true end for i = 2, math.ceil(value^0.5) do if i ~= 2 and i % 2 ~= 0 then if value % i == 0 then return false end end end return true end Retorna true se o valor dado é primo ou false se não for. math.primes function math.primes(a,b) assert(type(math.prime) == 'function', 'É necessário a função math.prime!') local result = {} for i = a, b do if math.prime(i) then result[#result+1] = i end end return result end Retorna uma tabela com todos os números primos entre a e b (requer a função math.prime) math.hypo function math.hypo(x1,y1,x2,y2) return ((x2-x1)^2 + (y2-y1)^2)^0.5 end Calcula a hipotenusa entre 2 coordenadas math.neg function math.neg(number) return number == 0 and 0 or number < 0 end Retorna true se o número for negativo, false se for positivo, ou 0 se for 0 Exemplos Code Lua 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 function math.prime(value) Dernière modification le 1481472960000 |
0 | ||
Parabéns |
Gamedroit « Citoyen » 1557538500000
| 0 | ||
Bom tópico Esh! Laagaadoo a dit : algo de errado não está certo ... for i = 1, #keys do system._bindKeyboard(name, keys, down, enabled) -- cadê a index do keys aqui... end |