| View previous topic :: View next topic |
| Author |
Message |
sgsgwv$6263 Advanced Cheater
Reputation: 0
Joined: 05 Aug 2020 Posts: 84
|
Posted: Thu Nov 10, 2022 2:17 am Post subject: How to debug unexpected symbol near errors |
|
|
Hi,
In Lua, everything is flexible and all but the infamous "unexpected symbol near" errors are sometimes not intuitive and logical. This morning, in one my scripts I got this error, after staring at the code for half an hour I was sure that there was no such unexpected symbol or any other kind of error. even after deleting the line which gave the error, I got the same error in some other line which I have not touched since ages.
What I did was: I cut pasted the code in my notepad and had to repaste the code function by function(the complete code had 40-45 functions) in the script. After each function I used to press ok to check if it's valid up til here. I had hoped that I will find the error eventually in some other function. But it never happened. I finished copying all functions one by one and finally pressed ok and it got saved without any error. This got me really frustrated. Why did I waste my time? Has this happened to any of you gurus here? How did you handle it? How can I debug the lua code in such cases? Is the line number given in the error generated by math.random(LOL) ?
|
|
| Back to top |
|
 |
Dark Byte Site Admin
Reputation: 470
Joined: 09 May 2003 Posts: 25808 Location: The netherlands
|
Posted: Thu Nov 10, 2022 5:52 am Post subject: |
|
|
it's difficult. You'll have to look for unexpected symbols. but the line number does tell you where the issue is.
e.g.:
| Code: |
print("this will work")
print("this as well")
print("Not this") ♥
print("and this works fine too")
|
will give as error
| Code: |
Script Error:[string "print("this will work")
..."]:3: unexpected symbol near '<\226>'
|
Notice the :3: , it says so that there is an unexpected symbol there, and it's right.
Now good luck finding out what it is, or how it even got there
Sometimes copying it to notepad or another editor, or posting it to a website, and then copying it back removes the invalid characters
(Extra fun fact: the ♥ won't show in the lua script editor, it looks like a space there)
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Like my help? Join me on Patreon so i can keep helping |
|
| Back to top |
|
 |
sgsgwv$6263 Advanced Cheater
Reputation: 0
Joined: 05 Aug 2020 Posts: 84
|
Posted: Thu Nov 10, 2022 6:07 am Post subject: |
|
|
| What should be the best practice to always avoid this? Should I avoid using the script editor and use any other editor like vscode Or notepad at all times?
|
|
| Back to top |
|
 |
Dark Byte Site Admin
Reputation: 470
Joined: 09 May 2003 Posts: 25808 Location: The netherlands
|
Posted: Thu Nov 10, 2022 6:16 am Post subject: |
|
|
that depends on how the character got there
Most often issues like this happen because people edit their script using notepad or other non-xml editors instead of the editor, and then mess up the XML formatting resulting in a character code instead of normal code (e.g in xml you can't do < , you have to use < )
but if you have a keyboard that makes it easy to accidentally insert special unsupported characters, then maybe use a different editor yes
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Like my help? Join me on Patreon so i can keep helping |
|
| Back to top |
|
 |
AylinCE Grandmaster Cheater Supreme
Reputation: 37
Joined: 16 Feb 2017 Posts: 1531
|
Posted: Thu Nov 10, 2022 11:28 am Post subject: |
|
|
Here is another possibility of error.
Sometimes, in code that is copied and pasted (especially if it is the whole code or a single line from an application that is taken from the internet or not supported.), carriage return or line break spaces, or line spaces, are invisible and as a character; triggers unknown error.
Just those spaces; Make sure you leave it yourself.
_________________
|
|
| Back to top |
|
 |
|