Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


How to debug unexpected symbol near errors

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
sgsgwv$6263
Advanced Cheater
Reputation: 0

Joined: 05 Aug 2020
Posts: 84

PostPosted: Thu Nov 10, 2022 2:17 am    Post subject: How to debug unexpected symbol near errors Reply with quote

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
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 470

Joined: 09 May 2003
Posts: 25808
Location: The netherlands

PostPosted: Thu Nov 10, 2022 5:52 am    Post subject: Reply with quote

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
View user's profile Send private message MSN Messenger
sgsgwv$6263
Advanced Cheater
Reputation: 0

Joined: 05 Aug 2020
Posts: 84

PostPosted: Thu Nov 10, 2022 6:07 am    Post subject: Reply with quote

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
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 470

Joined: 09 May 2003
Posts: 25808
Location: The netherlands

PostPosted: Thu Nov 10, 2022 6:16 am    Post subject: Reply with quote

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 &lt; )

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
View user's profile Send private message MSN Messenger
AylinCE
Grandmaster Cheater Supreme
Reputation: 37

Joined: 16 Feb 2017
Posts: 1531

PostPosted: Thu Nov 10, 2022 11:28 am    Post subject: Reply with quote

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.

_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites