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 assign a value to a variable when script is enabled?

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
HSergi
Newbie cheater
Reputation: 0

Joined: 17 Dec 2017
Posts: 22

PostPosted: Sun Mar 29, 2020 12:15 pm    Post subject: How to assign a value to a variable when script is enabled? Reply with quote

This doesn't work:
Code:

[ENABLE]
alloc(myvar,4)
registerSymbol(myvar)

{$lua}
writeFloat("myvar","120")
{$asm}

[DISABLE]
dealloc(myvar)
unregisterSymbol(myvar)

When I enable script, myvar is 0.


How to make it assign 120 to a variable when I enable the script?



cheatengine-x86_64_r6QlC0up8W.png
 Description:
 Filesize:  18.58 KB
 Viewed:  1115 Time(s)

cheatengine-x86_64_r6QlC0up8W.png


Back to top
View user's profile Send private message Send e-mail
ParkourPenguin
I post too much
Reputation: 152

Joined: 06 Jul 2014
Posts: 4702

PostPosted: Sun Mar 29, 2020 12:23 pm    Post subject: Reply with quote

{$lua} blocks are run before anything else, similar to a preprocessor stage.

Use AA instead:
Code:
[ENABLE]
alloc(myvar,4)
registerSymbol(myvar)

myvar:
  dd (float)120.0
...

_________________
I don't know where I'm going, but I'll figure it out when I get there.
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 470

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

PostPosted: Sun Mar 29, 2020 12:39 pm    Post subject: Reply with quote

or if you need to use lua
Code:

[ENABLE]
alloc(myvar,4)
registerSymbol(myvar)

{$lua}
return string.format([[myvar:
dd (float)%f]],120.0)
{$asm}

[DISABLE]
dealloc(myvar)
unregisterSymbol(myvar)

_________________
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 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