Development Section > Your Developing Problems

How to debug script?

(1/2) > >>

What is proper method to debug script?

When error occurs, message shows in script console. That is ok, but I cannot find a way, how can I print to console some debug information on my own?

Well lets see , Programming 101:

There are various ways one way is to indeed run the script and see if there are any error messages, the second way is to test its commands and functions and use test variables or text as input to ensure that it returns the correct/ expected output. You can also allow a user to attempt to use the program/script and see if he experiences any errors. Third way is to give it to another scripter for him/her to attempt to find any logical or syntax errors the compiler might have missed. There are many ways to skin a cat, the best way is perhaps a mix of the above and other methods I havent stated.

With command-line Lua, print() is your friend. With PtokaX you should make the hub bot send it somewhere, like as a private message to you. And if you are stuck with no syntax errors but not having the desired result, it is wise to make the program say something after i. e. every step of a more complex function, like the return value should be tht, or anything you wanna know in that particular context.

Thanks people, I already tried what you suggested.

I was just wondering if there is something nice and simple like print() that would show up in Ptokax script console.

Well I personally found that the best way(for me) to debug a script, is to use SendToAll("script stuff"), another method would be to place it within code that you suspect has errors or perhaps output variables that might have issues.
The best approach would be an IDE(Integrated Development Environment) for lua, which you could set watches for certain variables and use trace into and other functions. Perhaps something like LuaEdit would be helpful, although you'll have issues with Ptokax core functions, which are not part of the "pure" lua language.


[0] Message Index

[#] Next page

Go to full version