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 


Trouble Setting memrec.OnActivate

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

Joined: 20 Mar 2019
Posts: 2

PostPosted: Wed Mar 20, 2019 10:40 pm    Post subject: Trouble Setting memrec.OnActivate Reply with quote

Hello,
I'm trying to make a script that only allows one of its children to be activated at a time. I'm running into trouble as soon as I set the child scripts' OnActivate() functions.
Code:

[ENABLE]
{$lua}
if syntaxcheck then return end
--memrec.OnActivate = function(record, before, currentstate) end
if memrec.Count then
   print(tostring(memrec.Count))
   --print("---")
   local thisParent = memrec
   for i = 0,thisParent.Count do
       --print(tostring(memrec.Child[i].Active))
       if thisParent.Child[i].OnActivate ~= thisParent then
         thisParent.Child[i].OnActivate =
         function(record, before, currentstate)
            --print(tostring(~memrec.Child[i].Active))
            --if syntaxcheck then return end
            --local parent = thisParent
            --for j = 0,thisParent.Count do
            --    if thisParent.Child[j] ~= thisParent.Child[i] then
            --       thisParent.Child[j].Active = false
            --    end
            --end
         end
       --print(tostring(memrec.Child[i].OnActivate))
       --print("---")
      end
   end
end
--memrec.OnActivate = function(record, before, currentstate) end


{$asm}
[DISABLE]
{$lua}
if syntaxcheck then return end

What I'm trying to do is make it so that each child's OnActivate sets every other child's Active to false. As soon as I uncomment the code that sets Child[i].OnActivate, the parent script starts instantly deactivating itself as soon as I activate it. I added a check to make sure I wasn't setting the parent script's OnActivate somehow but it had no effect.

Any help would be greatly appreciated.
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 471

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

PostPosted: Thu Mar 21, 2019 1:44 am    Post subject: Reply with quote

Code:

if thisParent.Child[i].OnActivate ~= thisParent then

OnActivate is a function and thisParent is a memoryrecord object

Code:

for i = 0,thisParent.Count do

should go to thisParent.Count-1 (same for the j loop)

OnActivate must return true/false depending on if you wish to allow the activation (it gets called twice, once before and once after. In the before you can control that)

Code:

[ENABLE]
{$lua}
if syntaxcheck then return end
--memrec.OnActivate = function(record, before, currentstate) end
if memrec.Count then
   local thisParent = memrec
   for i = 0,thisParent.Count-1 do
       --print(tostring(memrec.Child[i].Active))
       if thisParent.Child[i].OnActivate ~= thisParent then
         thisParent.Child[i].OnActivate = function(record, before, currentstate)
            local parent = thisParent

            if currentstate==false then --before it gets activated
              for j = 0,thisParent.Count-1 do
                local mr=thisParent.Child[j]
                if thisParent.Child[j] ~= record then
                   thisParent.Child[j].Active = false
                end
              end
            end

            return true --allow
         end
      end
   end
end
{$asm}


[DISABLE]
{$lua}
if syntaxcheck then return end

_________________
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
supersaiyansubtlety
How do I cheat?
Reputation: 0

Joined: 20 Mar 2019
Posts: 2

PostPosted: Thu Mar 21, 2019 11:29 am    Post subject: Reply with quote

Dark Byte wrote:
OnActivate must return true/false depending on if you wish to allow the activation (it gets called twice, once before and once after. In the before you can control that)

This is what I was missing, thanks a bunch!
Back to top
View user's profile Send private message
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