×

Langue

Fermer
Atelier 801
  • Forums
  • Dev Tracker
  • Connexion
    • English Français
      Português do Brasil Español
      Türkçe Polski
      Magyar Română
      العربية Skandinavisk
      Nederlands Deutsch
      Bahasa Indonesia Русский
      中文 Filipino
      Lietuvių kalba 日本語
      Suomi עברית
      Italiano Česky
      Hrvatski Slovensky
      Български Latviešu
      Estonian
  • Langue
  • Forums
  • /
  • Transformice
  • /
  • Modules
  • /
  • Function Library
« ‹ 2 / 3 › »
Function Library
Abdeltif
« Citoyen »
1388004720000
    • Abdeltif#0000
    • Profil
    • Derniers messages
    • Tribu
#21
  0
Safwanrockz a dit :
Yep, because it uses the system.newTimer function.

Also, this function might be useful though.

Deletes a value from a specific table.

It's the same as table.remove ...
What do you mean by removing a value ? removing an element in a table is removing it value too :p
Shamousey
« Consul »
1388014320000
    • Shamousey#0095
    • Profil
    • Derniers messages
    • Tribu
#22
  0
Abdeltif a dit :
It's the same as table.remove ...
What do you mean by removing a value ? removing an element in a table is removing it value too :p

table.remove requires you to find the key that you want to remove from the table, Saf's function does that automatically so you only have to know the value you want to remove.
Yteizz
1388014680000
    • Yteizz#0000
    • Profil
    • Derniers messages
#23
[Modéré par Shamousey, raison : Requested.]
Safwanrockz
« Censeur »
1388058840000
    • Safwanrockz#0095
    • Profil
    • Derniers messages
    • Tribu
#24
  0
Abdeltif a dit :
It's the same as table.remove ...
What do you mean by removing a value ? removing an element in a table is removing it value too :p


Moreover, table.remove requires the <b>position</b>(intentional bold tags) of the element/value you want to delete, unlike table.remove. Example:
table.remove a dit :

table={"element1","element2"}
--table.remove(table,"element1") won't work
table.remove(table,1) -- will work

table.delete a dit :

function table.delete(t,v)
for key,value in ipairs(t) do
if v == t[key] then
table.remove(t, key)
end
end
end
-------
table={"element1","element2"}
table.delete(table, "element1") -- will work

 
Abdeltif
« Citoyen »
1388061180000
    • Abdeltif#0000
    • Profil
    • Derniers messages
    • Tribu
#25
  0
Safwanrockz a dit :
Moreover, table.remove requires the &lt;b&gt;position&lt;/b&gt;(intentional bold tags) of the element/value you want to delete, unlike table.remove. Example:

 

Oh, you mean it will check the element not the value ? :o
This is useful for such as "messgeEn = Help" or something like that in tables :)
Woebegone
« Citoyen »
1388783340000
    • Woebegone#8377
    • Profil
    • Derniers messages
    • Tribu
#26
  0
How can you make buttons with text of it? And how can you make the button on a specifec place on a map?
Abdeltif
« Citoyen »
1388784600000
    • Abdeltif#0000
    • Profil
    • Derniers messages
    • Tribu
#27
  0
Juliantwofan a dit :
How can you make buttons with text of it? And how can you make the button on a specifec place on a map?

Script request is the right place for it, go there and ask for it :)
(pss, it uses text areas and areaCall backs)
Woebegone
« Citoyen »
1388785260000
    • Woebegone#8377
    • Profil
    • Derniers messages
    • Tribu
#28
  0
Abdeltif a dit :
Script request is the right place for it, go there and ask for it :)
(pss, it uses text areas and areaCall backs)

Oooh Okay. I'll quote it .3.
Safwanrockz
« Censeur »
1390493040000
    • Safwanrockz#0095
    • Profil
    • Derniers messages
    • Tribu
#29
  0
Made a hexadecimal to decimal converter with Lua, I know you can simply do tonumber("FF", 16), but I felt like making it anyway.
a dit :

function hexToDec(num)
if type(num)=="number" then
error("String expected, got number.", 1)
end
local K=string.len(num)
local N=K-1
local Z
local chars={}
for n in num:gmatch("[%w+]") do
table.insert(chars, n)
end
for key,v in ipairs(chars) do
if v=="A" then
chars[key]=tonumber(10)
elseif v=="B" then
chars[key]=tonumber(11)
elseif v=="C" then
chars[key]=tonumber(12)
elseif v=="D" then
chars[key]=tonumber(13)
elseif v=="E" then
chars[key]=tonumber(14)
elseif v=="F" then
chars[key]=tonumber(15)
end
end
if K==4 then
Z=(chars[1]*16^N)+(chars[2]*16^N-1)+(chars[3]*16^N-2)+chars[4]
elseif K==3 then
Z=(chars[1]*16^N)+(chars[2]*16^N-1)+chars[3]
elseif K==2 then
Z=(chars[1]*16^N)+chars[2]
elseif K>4 then
error("attempt to convert more than four numbers", 1)
elseif K<2 then
error("attempt to convert one number", 1)
end
return Z
end

 
Shamousey
« Consul »
1390494060000
    • Shamousey#0095
    • Profil
    • Derniers messages
    • Tribu
#30
  0
Safwanrockz a dit :
Made a hexadecimal to decimal converter with Lua, I know you can simply do tonumber("FF", 16), but I felt like making it anyway.
 

string.format("%X",255)
tonumber("FF",16)

These two things are much smaller and go both ways! ;) Even though you did point out the tonumber one.
Safwanrockz
« Censeur »
1390494420000
    • Safwanrockz#0095
    • Profil
    • Derniers messages
    • Tribu
#31
  0
Oh yep, I forgot about the string.format one, which turns hexadecimal to decimal if used with %X.
Kmlcan
« Citoyen »
1391025900000
    • Kmlcan#0000
    • Profil
    • Derniers messages
    • Tribu
#32
  0
An important function. Shuffles a table. (Requires table.copy)
a dit :
function table.shuffle(t)
local c = table.copy(t)
local rt = {}
for i=1,#t do
table.insert(rt, table.remove(c, math.random(#c)))
end
return rt
end
Evilsantah
« Citoyen »
1391082840000
    • Evilsantah#0000
    • Profil
    • Derniers messages
#33
  0
Shamousey a dit :

table.invert
Inverts the key and value of a table.

function table.invert(t)
local u = { }
for k, v in pairs(t) do u[v] = k end
return u
end

This function has collisions when different keys point to the same value in table t. Meaning you might lose data so be careful with that.

Shamousey a dit :

table.concat
Joins the values in a table together.

This function already exists in the LUA table library.

Kmlcan a dit :
An important function. Shuffles a table. (Requires table.copy)

It's worth mentioning that you need a non-associative table for this (keys 1..n). Also, there is a more efficient algorithm to do so. Just look it up on Google.
Saahar
« Citoyen »
1429884120000
    • Saahar#0000
    • Profil
    • Derniers messages
#34
  0
Sorry to bump this thread but I think the translation method could be improved ^^'.

translate method improved a dit :
local translations = {
  DEFAULT_LANG = "EN",
  EN = {
    greets = "Welcome!",
    help = "A little help message."
  },
  ES = {
    greets = "Hola !",
    help = "Un pequeño mensaje de ayuda !"
  }
}

local translate = function (message)
  local lang = translations[tfm.get.room.community] or translations.DEFAULT_LANG
  return translations[lang]
end

-- In an english room:
print(translate("greets")) -- Welcome!

-- In a spanish room:
print(translate("greets")) -- Hola !

-- In a german room (will use the DEFAULT_LANG var):
print(translate("greets")) -- Welcome !

Dernière modification le 1429885260000
Shamousey
« Consul »
1429884780000
    • Shamousey#0095
    • Profil
    • Derniers messages
    • Tribu
#35
  0
It could also be updated to make use of tfm.get.room.playerList[name].community, which was added to the API late last year and would give more specific results for people playing in international rooms.

Translation Function a dit :
function translate(message,name)
local community=name and tfm.get.room.playerList[name].community or tfm.get.room.community
return translations[community] and translations[community][message] or translations["en"][message]
end
Saahar
« Citoyen »
1429885020000
    • Saahar#0000
    • Profil
    • Derniers messages
#36
  0
Shamousey a dit :
It could also be updated to make use of tfm.get.room.playerList[name].community, which was added to the API late last year and would give more specific results for people playing in international rooms.
[CODE]

Ah ! Nice to see people that use ternaries conditions. I ignored that we can get the user language, i'm newer in here ^^
Neonstrayzer
« Citoyen »
1429903440000
    • Neonstrayzer#0000
    • Profil
    • Derniers messages
    • Tribu
#37
  0
table.unpack is now usable without function.
    object={10,200,200}
    tfm.exec.addShamanObject(table.unpack(object))

And
http://i.imgur.com/ht4k45N.png
shamans.insert isn't true. It must be table.insert(shamans,name)

Dernière modification le 1429904040000
Shamousey
« Consul »
1429913820000
    • Shamousey#0095
    • Profil
    • Derniers messages
    • Tribu
#38
  0
My mistake about the shamans.insert, not sure how I missed that one when I made this thread xD I also added a note next to table.unpack, but kept the function definition there for legacy.
Esh
« Censeur »
1447677060000
    • Esh#0095
    • Profil
    • Derniers messages
    • Tribu
#39
  0
string.title

returns a copy of the string in which first letter of the word is capitalized.
(eShkatIon returns Eshkation, +ESHKATion returns +Eshkation)

Script a dit :

function string.title(str)
&emsp;return string.lower(str):gsub("%a", string.upper, 1)
end

  • Forums
  • /
  • Transformice
  • /
  • Modules
  • /
  • Function Library
« ‹ 2 / 3 › »
© Atelier801 2018

Equipe Conditions Générales d'Utilisation Politique de Confidentialité Contact

Version 1.27