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 


Trying to get my LUA script in a pre-existing table

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine
View previous topic :: View next topic  
Author Message
justanotherperson
How do I cheat?
Reputation: 0

Joined: 16 Nov 2022
Posts: 4

PostPosted: Wed Nov 16, 2022 3:03 am    Post subject: Trying to get my LUA script in a pre-existing table Reply with quote

I want to add my LUA script to a table so that it's toggle-able with the checkbox next to it, i.e. looks like this:

□ <MyScript>

I've gotten as far as trying to use the Auto Assemble menu to add it by doing this:

Code:

[ENABLE]
{$Lua}
local timer = createTimer(getMainForm())
timer.Interval = 100
timer.OnTimer = function(timer)
Value=tonumber(AddressList.getMemoryRecordByDescription('Current Animation').Value)
if Value == 2006 or 2005 or 2004 or 2012 or 2010 or 2011 then
   keyDown(0x51)
   Sleep 100
   keyUp (0x51)
end

[DISABLE]
{$Lua}


I'm clicking "Assign to current cheat table" but getting the follow error:

Lua error in the script at line 2:[string "local syntax check, memrec=......"]:
8: syntax error near '100'

The script works on its own if I just execute on startup but I want to be able to toggle it on and off and see it in the actual table as described above.

I'm probably missing something obvious but I've looked at the forums and can't figure it out myself. Cool
Back to top
View user's profile Send private message
LeFiXER
Grandmaster Cheater Supreme
Reputation: 20

Joined: 02 Sep 2011
Posts: 1055
Location: 0x90

PostPosted: Wed Nov 16, 2022 3:52 am    Post subject: Reply with quote

You were missing the parenthesis for the function Sleep().
Code:

{$LUA}
if syntaxcheck then return end
-- Destroy the timer if it exists so you don't end up creating a timer several times
if timer then timer.destroy(); timer = nil end

timer = createTimer(getMainForm())
timer.Interval = 100
timer.OnTimer = function()
Value = AddressList.getMemoryRecordByDescription('Current Animation').Value
if (Value == '2006') or (Value == '2005') or (Value == '2004') or (Value == '2012') or (Value == '2010') or (Value == '2011') then
   keyDown(0x51)
   Sleep(100)
   keyUp (0x51)
end


Also, no need to typecast here.

Edit: Sorry about the mistakes. I have updated my example to reflect the changes mentioned by DB.


Last edited by LeFiXER on Wed Nov 16, 2022 5:55 am; edited 1 time in total
Back to top
View user's profile Send private message
justanotherperson
How do I cheat?
Reputation: 0

Joined: 16 Nov 2022
Posts: 4

PostPosted: Wed Nov 16, 2022 4:03 am    Post subject: Reply with quote

Thanks for the reply but it's still showing an error:


Not all code is injectable.
(Lua error in the script at line 2: [string "local syntaxcheck, memrec=...
..."]:4: syntax error near ';')
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 458

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

PostPosted: Wed Nov 16, 2022 4:56 am    Post subject: Reply with quote

try your code in lua engine with some test variables before putting it in a memoryrecord

that way you can also debug things and step through code

in your case for example replace timer.destroy; with timer.destroy()
also, you're missing the end of the function , so add an extra end
and the timer is declared as local, so the timer.destroy() won't be seen when the script is reactivated. Make it global (remove local)

and that if condition will always return true, use something like (Value == '2006') or (Value == '2007') or (Value == '2008') ....

_________________
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
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine 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