×

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
  • /
  • [Module API] Errors
1 / 17 › »
[Module API] Errors
Shamousey
« Consul »
1380827100000
    • Shamousey#0095
    • Profil
    • Derniers messages
    • Tribu
#1
  1
If your script isn't working as intended, post it in this thread and explain what you expect to happen.

This thread describes the many types of errors that Lua can return, and briefly covers how to fix them or prevent them from happening.

If you've encountered an error in your code, please read over this thread to try and solve it. If you still need help, post your ENTIRE code as a reply to this thread (in [quote] tags or on an external site like PasteBin), explain what you expected to happen, and mention the error that's coming up.


http://i.imgur.com/4vSFf.png
Some error messages contain a line number that can be used to find the line of code which caused the error. The error may not be exactly on the line given, but one of them around it.

A good tip for debugging code to find out where something went wrong is to print variables and other information at various stages of the code. This can be helpful to find out if a variable isn't what you expected it to be, if certain if statements are getting ran, etcetera. This doesn't fix your code, but helps you to locate what's wrong.


http://i.imgur.com/4vSFf.png
A common mistake when something doesn't work correctly is that it's been redefined. The last definition of a piece of data replaces the previous one, so for example here having two eventPlayerEmotes will mean that only the last one ever actually works.

a dit :
function eventEmotePlayed(name,emote)
tfm.exec.giveCheese(name)
end

function eventEmotePlayed(name,emote)
print("This one has redefined the above function, so only this one will work.")
end

To fix this, just merge the contents of the two functions.

a dit :
function eventEmotePlayed(name)
tfm.exec.giveCheese(name)
print("This will now work!")
end

http://i.imgur.com/4vSFf.png
The errors below all have an example of the different types of errors, and brief description. If a specific error isn't listed, please post it and it'll be covered.

http://i.imgur.com/4vSFf.png

http://i.imgur.com/dvIDHof.png
Init is an abbreviation of "initialisation", and means that the code failed to excecute properly as it was loaded.

[•] Attempt to call nil.
This error occurs when a line is attempting to use a variable that is nil. This often occurs when things haven't been created yet and are in the wrong order, or a certain function hasn't been excecuted.
a dit :
print(test)
test="Hello."

Another example that may cause this error is incorrect capitalisation. Lua is case sensitive, so typing a function or variable name without the correct capitalisation will try to call one of the same capitalisation.
a dit :
Print("Test.")

[•] Index expected, got nil.
Trying to define or call an item in a table that doesn't exist will cause an error like this.
a dit :
tbl[1] = "This will break, since tbl doesn't exist."

[•] ')' expected (to close '(' at line [num])
If this error occurs, a closing parenthesis from function arguments is missing.
a dit :
print("Hi

[•] '' expected.
While this error can pop up in several different situations, the most common is when using an elseif statement when it has no corresponding opening if.
a dit :
elseif 1>2 then
print("There's no opening if statement.")
end

[•] Multiple points.
Numbers can only have a single decimal point, trying to have multiple decimal points in a single number will return this error.
a dit :
--Single decimal point, this is fine.
20.43

--Multiple decimal points, this is wrong.
20.43.9.1

[•] Unfinished (long) comment/string.
The string operators must be closed whenever they are used. If the error message pertains to a "long" comment/string, use of the multi-line operator [[...]] was the cause of the error.
a dit :
text="This is a variable definition that is never finished.

--[[ This is a comment that isn't ever closed, for example.

[•] Nesting of [[...]] is deprecated.
Multi-line strings can't have more multi-line strings inside.
a dit :
--[[ This is a comment [[ This is inside the comment. ]] This is the end of the comment.]]

[•] Attempt to index ? (a nil value).
This error occurs when an element in a table is trying to be used, but cannot be found.
a dit :
tbl={}
print(tbl[1])

[•] Null
This is an error caused by a bug in the Module API and cannot be solved. Occasionally scripts cannot be run in a certain room.

http://i.imgur.com/4vSFf.png

http://i.imgur.com/Jnfam49.png
[•] Attempt to concatenate [data] and [data].
Different data types cannot be concatenated together with the .. operator, with the exception of strings and numbers.
a dit :
--This will work.
"Text "..34

--These won't work.
{"this","is","a","table"}.."string"
nil..{"table"}
nil.."string"
function().."string"

[•] Invalid key to 'next'.
This error occurs when the next() function has an invalid key it tries to move to. This is most common when trying to remove an item from a table while iterating through it, as the pairs() function uses next().
a dit :
tbl={Something=true,somethingelse=true}

for k,v in pairs(tbl) do
tbl[k]=nil
end

[•] Attempt to perform arithmetic on a [data] value.
Different data types can't have any arithmetic performed on them unless they're numbers.
a dit :
{"table"}+4

[•] Attempt to compare [data] with [data].
Much like how arithmetic can't be performed on different data types, they can't be compared with comparison operators.
a dit :
if {"table"} > 4 then
print("This will give an error.")
end

[•] [data] expected, got [data].
When a certain data type is expected in a function but another one is given, this error will occur.
a dit :
for key,value in pairs("string") do
print("The for loop above is expecting a table.")
end

[•] Lua destroyed : Runtime can't exceed 40 ms in 4 seconds !

a dit :
function eventLoop()
for i=1,1000000 do
--This will cause an error.
end
end

[•] Lua destroyed: Runtime too long!

a dit :
for i=1,10000000000 do
--This will cause an error.
end

http://i.imgur.com/4vSFf.png

http://i.imgur.com/RLLpc0w.png
Argument errors rarely stop the script from working and act as more of a warning that something isn't working properly.

[•] Argument must be integer.
This error occurs when an argument in a function is expecting an integer number but is receiving another data type. For example, tfm.exec.movePlayer(name,"text",200) is expecting a number in the second argument.

http://i.imgur.com/4vSFf.png

http://i.imgur.com/DqkR3tv.png
[•] vm error: java.lang.ArrayIndexOutOfBoundsException: 256
This error can be caused by multiple things, but is more commonly when something recurs indefinitely. An example might be a function that calls itself.
a dit :
function a()
a()
end
a()

[•] You don't have the right to use this function.
Certain functions are disabled from being used in the Tribe House, including the following.
a dit :
tfm.exec.chatMessage()
system.newTimer()
system.removeTimer()
system.saveFile()
system.loadFile()

Dernière modification le 1403967480000
Myaumatrosik
« Censeur »
1380827640000
    • Myaumatrosik#0000
    • Profil
    • Derniers messages
    • Tribu
#2
  0
Ohh... Help me, Sham :с

http://pastebin.com/Eeip1yL6

I can't update text in new round!
Thetroz
« Citoyen »
1380827760000
    • Thetroz#0000
    • Profil
    • Derniers messages
    • Tribu
#3
  0
...And [•] index expected, got nil?
Shamousey
« Consul »
1380828660000
    • Shamousey#0095
    • Profil
    • Derniers messages
    • Tribu
#4
  1
Myaumatrosik a dit :
Ohh... Help me, Sham :с

http://pastebin.com/Eeip1yL6

I can't update text in new round!

In your script here, you can't use tfm.exec.chatMessage() as it's been disabled in the tribe house. You're also trying to update a text area with the ID of 0, but the only one you have is ID 1.

Thetroz a dit :
...And [•] index expected, got nil?

I've obviously missed a few errors that I hope I'll get to cover if people report them, but I've added that in.
Hophipmice
« Citoyen »
1380883320000
    • Hophipmice#0000
    • Profil
    • Derniers messages
    • Tribu
#5
  0
[Delete please]
Tailtong
« Citoyen »
1380883680000
    • Tailtong#0000
    • Profil
    • Derniers messages
    • Tribu
#6
  0
Hophipmice a dit :
[•] Init Error : transformice.lua:451: [string "transformice.lua"]:125: '=' expected

Gedit says your code has 36 lines, not 125. Give me the rest of your code, don't worry, i won't copy.
Hophipmice
« Citoyen »
1380883800000
    • Hophipmice#0000
    • Profil
    • Derniers messages
    • Tribu
#7
  0
Tailtong a dit :
Gedit says your code has 36 lines, not 125. Give me the rest of your code, don't worry, i won't copy.

Fixed :)
Tailtong
« Citoyen »
1380883800000
    • Tailtong#0000
    • Profil
    • Derniers messages
    • Tribu
#8
  0
Hophipmice a dit :
Fixed :)

Okay.
Bengalstar
« Citoyen »
1380932460000
    • Bengalstar#0000
    • Profil
    • Derniers messages
#9
  0
what about this error ?
[•] Init Error : [string "transformice.lua"]:18: 'then' expected
Abdeltif
« Citoyen »
1380976620000
    • Abdeltif#0000
    • Profil
    • Derniers messages
    • Tribu
#10
  0
Good job sham !
I have some errors to paste here :D
wait that i edit this post
Hophipmice
« Citoyen »
1380976620000
    • Hophipmice#0000
    • Profil
    • Derniers messages
    • Tribu
#11
  0
I did
a dit :
for name, player in pairs(tfm.get.room.playerList) do
tfm.exec.bindKeyboard(name,32,false,false)
end

spiritTime = {}
function eventMouse(name, x, y)
local now = os.time()
if not spiritTime[name] or now > spiritTime[name] + 1000 then
tfm.exec.addShamanObject(19, x, y)
spiritTime[name] = now
end
end

But it wont work ):

a dit :
[•] [Hophipmice] Lua script loaded in 1 ms (4000 max)
Abdeltif
« Citoyen »
1380977640000
    • Abdeltif#0000
    • Profil
    • Derniers messages
    • Tribu
#12
  0
a dit :
for name,abdeltif in pairs(tfm.get.room.playerList[abdeltif]) do
system.bindMouse(name, true)
end


[•] Init Error : transformice.lua:31: bad argument: table expected, got nil
Epicshawty
« Citoyen »
1381177680000
    • Epicshawty#0000
    • Profil
    • Derniers messages
    • Tribu
#13
  0
Abdeltif a dit :

[•] Init Error : transformice.lua:31: bad argument: table expected, got nil

here
a dit :

mousepeeps = {"Abdeltif"}
for _,p in pairs(mousepeeps) do
system.bindMouse(p,true)
end

you can change mousepeeps to anything, just a example :P
Leafileaf
« Citoyen »
1381216380000
    • Leafileaf#0000
    • Profil
    • Derniers messages
    • Tribu
#14
  0
Sha you mixed up some of the errors.

The code for attempt to index nil and index expected, got nil. These two should be switched >_<
Attempt to call nil: that code won't return that error. Your code prints nil.
To get the attempt to call nil error, use "randomUndeclaredFunction()"
Tini
« Sénateur »
1381272960000
    • Tini#0095
    • Profil
    • Derniers messages
    • Tribu
#15
  0
a dit :
translations={
EN={
help={
"<font size='25'><bv>Introdução</bv></font><br><br>Este é o <b>Cannon Meep Racing</b><br><br>Aqui você poderá se divertir com seus amigos, você só precisa pegar o queijo e não ser morto pelo <b>MEEP</b><br><br><br>Pessas com nome em <font color='#eb1d51'>vermelho</font> são <b>devs</b>, você tem que respeitá-los",
"<font size='25'><vp>Mapas</vp></font><br><br><br>@381043<br>@286333<br>@229834<br>@1643157<br>@3535192<br><br>",
"<font size='25'><j>Comandos</j></font><br><br><br><b>!mort</b> <i>(bugado)</i> - Para se matar<br><b>!cheeseadmin</b> <i>(bugado)</i>- para dar queijo à uma pessoa (uso permitido somente para admins)",
"<font size='25'><g>Sugestões</g></font><br><br>Caso você tenha alguma sugestão para o nosso Minigame, você pode ir até o <b>Fórum da Tribo</b> e dê sua sugestão no tópico do Minigame.",
"<font size='25' color='#eb1d51'>Devs</font><br><br><br><b>Tinittee</b> - Criador do jogo<br><b>Dedavii</b> - Co-criador do jogo<br>",
"<font size='25'><ch>Bugs</ch></font><br><br><br><j>• !fromage (!cheeseadmin) bugado<br>• !mort bugado<br>• !report bugado</j><br><br><br><br>",
"<font size='25'><r>Change Logs</r></font><br><br><br><v>[28/09]</v>• Minigame criado<br><v>[29/09]</v>• Script editado<br><v>[29/09]</v>• <b>Doneky</b> agora é <font color='#eb1d51'>admin</font><br><v>[30/09]</v> • Doneky saiu da equipe<br><v>[06/10]</v> • Comando <i>!help</i> substituido por <i>!page</i>",
"<font size='25' color='#D3A979'>Códigos</font><br><br><br>A cada semana teremos novos novos códigos para terem acesso à sala (ver o mapa), e nesses códigos terão dicas da resposta.<br><br>Esta semana, a dica do código é:<br><br>•Usado no nosso Minigame<br>•Usado em survivor<br><br><b>Resposta:</b> <i>meep</i><br><br><br><br><br><br><br>Dicas do <b>próximo</b> código:<br><br>• Onde são anunciados as novidades<br>• Usado por vários da tribo<br>• Tem um cargo com o pré-fixo 'Se'",
}
}
}

players={}
system.disableChatCommandDisplay("help")

textarea=ui.addTextArea
function ui.addTextArea(id,text,targetPlayer,x,y,width,height,backgroundColor,borderColor,backgroundAlpha,emboss)
--if not backgroundColor then backgroundColor=0x324650 end
--if not borderColor then borderColor=0x000001 end
if emboss then
textarea(6969+id,"",targetPlayer,x,y+1,width,height,0x000001,0x000001,backgroundAlpha)
textarea(7979+id,"",targetPlayer,x,y-1,width,height,0x6A8FA2,0x6A8FA2,backgroundAlpha)
end
textarea(id,text,targetPlayer,x,y,width,height,backgroundColor,borderColor,backgroundAlpha)
end

function eventNewPlayer(name)
players[name]={helpid=1}
ui.addTextArea(0,"<p align='center'><a href='event:help'><b>?</b></a></p>",name,780,374,16,16,nil,0x324650,nil,true)
end

for name,player in pairs(tfm.get.room.playerList) do
eventNewPlayer(name)
end

function trans(mes)
if translations[tfm.get.room.community] and translations[tfm.get.room.community][mes] then
return translations[tfm.get.room.community][mes]
else
return translations.EN[mes]
end
end

function eventChatCommand(name,command)
if command=="help" then
ui.addTextArea(1,trans("help")[players[name].helpid],name,250,50,300,300,nil,0x324650,nil,true)
ui.addTextArea(2,"<p align='center'><a href='event:previous'><b>←</b></a></p>",name,500,365,16,16,nil,0x324650,nil,true)
ui.addTextArea(3,"<p align='center'><a href='event:next'><b>→</b></a></p>",name,532,365,16,16,nil,0x324650,nil,true)
ui.addTextArea(4,"<p align='center'><a href='event:close'><b>x</b></a></p>",name,442,365,42,16,nil,0x324650,nil,true)
ui.addTextArea(5,"<p align='center'>"..players[name].helpid.."/"..#trans("help").."</p>",name,250,365,42,16,nil,0x324650,nil,true)
end
end

function eventTextAreaCallback(id,name,callback)
if callback=="help" then
eventChatCommand(name,callback)
elseif callback=="close" then
players[name].helpid=1
for id=1,5 do
ui.removeTextArea(id,name)
ui.removeTextArea(6969+id,name)
ui.removeTextArea(7979+id,name)
end
elseif callback=="next" and players[name].helpid<#trans("help") then
players[name].helpid=(players[name].helpid)+1
ui.updateTextArea(1,trans("help")[players[name].helpid],name)
ui.updateTextArea(5,"<p align='center'>"..players[name].helpid.."/"..#trans("help").."</p>",name)
elseif callback=="previous" and players[name].helpid>1 then
players[name].helpid=players[name].helpid-1
ui.updateTextArea(1,trans("help")[players[name].helpid],name)
ui.updateTextArea(5,"<p align='center'>"..players[name].helpid.."/"..#trans("help").."</p>",name)
end
end

[•] Error transformice.lua; 133
Shamousey
« Consul »
1381280100000
    • Shamousey#0095
    • Profil
    • Derniers messages
    • Tribu
#16
  0
Tinittee a dit :
[•] Error transformice.lua; 133

This is working fine for me...
Safwanrockz
« Censeur »
1381355520000
    • Safwanrockz#0095
    • Profil
    • Derniers messages
    • Tribu
#17
  0
Really helpful thread, good job shamo.
Shamousey
« Consul »
1381374540000
    • Shamousey#0095
    • Profil
    • Derniers messages
    • Tribu
#18
  1
So I made an "inspirational poster" last week for those that come with the same issue.


http://i.imgur.com/MDGwUGi.jpg
Abdeltif
« Citoyen »
1381562700000
    • Abdeltif#0000
    • Profil
    • Derniers messages
    • Tribu
#19
  0
a dit :
function eventLoop(500, 5000)
for i=1,10 do
tfm.exec.addConjuration(10, 50, 5000)
tfm.exec.addConjuration(200, 50, 5000)
tfm.exec.addConjuration(150, 50, 5000)
tfm.exec.addConjuration(120, 50, 5000)
tfm.exec.addConjuration(100, 50, 5000)
tfm.exec.addConjuration(300, 50, 5000)
end
end

Error : [•] Init Error : [string "transformice.lua"]:1: or '...' expected
Ordboka
« Citoyen »
1381563720000
    • Ordboka#0000
    • Profil
    • Derniers messages
    • Tribu
#20
  0
Abdeltif a dit :
Error : [•] Init Error : [string "transformice.lua"]:1: or '...' expected

You can't have those numbers up there. You should have variables where you can store the information that you get when you run the function.

Lua a dit :
function eventLoop(time, secTime)
for i=1,10 do
tfm.exec.addConjuration(10, 50, 5000)
tfm.exec.addConjuration(200, 50, 5000)
tfm.exec.addConjuration(150, 50, 5000)
tfm.exec.addConjuration(120, 50, 5000)
tfm.exec.addConjuration(100, 50, 5000)
tfm.exec.addConjuration(300, 50, 5000)
end
end

Try this
  • Forums
  • /
  • Transformice
  • /
  • Modules
  • /
  • [Module API] Errors
1 / 17 › »
© Atelier801 2018

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

Version 1.27