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 


Need a little help with implementing a repeater record

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
zxuiji
Advanced Cheater
Reputation: 1

Joined: 26 Sep 2016
Posts: 70

PostPosted: Mon Jan 22, 2018 3:46 am    Post subject: Need a little help with implementing a repeater record Reply with quote

Here's my current code:
Code:

local ceList = getAddressList()
ceList.createMemoryHeader = function()
  local item = ceList.createMemoryRecord()
  item.isGroupHeader = true
  return item
end
-- ...
local ceMaxOutInv = ceList.createMemoryHeader()
local ceMaxOutInvTimer = nil
ceMaxOutInv.setDescription('MaxOutInv')

function MaxOutInv()
  if ( ceMaxOutInvTimer == nil or
    ceMaxOutInvTimer.getEnabled() == false ) then return end
  slideWrItem( zRdDword(pInvAbilities), 24, 500, zSetCount, 1 )
  slideWrItem( zRdDword(pInvComponents), 24, 500, zSetCount, 99 )
  slideWrItem( zRdDword(pInvOtherItems), 24, 500, zSetCount, 99 )
  slideWrItem( zRdDword(pInvKeyItems), 24, 500, zSetCount, 99 )
end
function EnableMaxOutInv(mr, b4, cur)
  if ( ceMaxOutInvTimer == nil ) then
    ceMaxOutInvTimer = createTimer( ceMaxOutInv, false )
  end
  ceMaxOutInvTimer.setInterval( 5000 )
  ceMaxOutInvTimer.OnTimer = MaxOutInv
  ceMaxOutInvTimer.setEnabled( true )
  return true
end
function DisableMaxOutInvTimer(mr, b4, cur)
  ceMaxOutInvTimer.setEnabled( false )
  return true
end
function DestroyMaxOutInvTimer()
  if ( ceMaxOutInvTimer ) then
    ceMaxOutInvTimer.destroy()
  end
end

ceMaxOutInv.OnActivate = EnableMaxOutInv
ceMaxOutInv.OnDeactivate = DisableMaxOutInv
ceMaxOutInv.OnDestroy = DestroyMaxOutInvTimer
ceMaxOutInv.DontSave = true

As you will have inferred by now I'm trying to force a somewhat infinite stock of my items (the loop stops at NULL based items for safety) but when I try to activate the record lua pops up with an error that only reports "Access Violation", some help understanding & fixing this would be appreciated

_________________
Those who do not trust in christ to save them from their sins will only experience hell when their soul is released from it's earthly vessel.
Back to top
View user's profile Send private message
TheyCallMeTim13
Wiki Contributor
Reputation: 50

Joined: 24 Feb 2017
Posts: 976
Location: Pluto

PostPosted: Mon Jan 22, 2018 4:33 am    Post subject: Reply with quote

Try changing:
Code:
ceMaxOutInvTimer = createTimer( ceMaxOutInv, false )

To:
Code:
ceMaxOutInvTimer = createTimer( MainForm, false )

Or:
Code:
ceMaxOutInvTimer = createTimer( getMainForm(), false )

_________________
Back to top
View user's profile Send private message Visit poster's website
zxuiji
Advanced Cheater
Reputation: 1

Joined: 26 Sep 2016
Posts: 70

PostPosted: Mon Jan 22, 2018 5:07 am    Post subject: Reply with quote

I'm gonna try it but doesn't getMainForm() just return the cheat window (of which I have not made) and not the main window showing the cheat list?

Edit: It worked! I put getMainForm() in there and it worked perfectly, loaded up a save game in the training day where I only had 2 items (both weren't at full before activating the cheat), they were nicely filled on activating the cheat and then I went chasing after snow to fight that minion that lumina summons and get a new item out of that, then I checked the amount after returning to the field and it was also 99 instead of 1 which means I achieved what I was looking for out of that, now gonna check if I properly disable the timer in my other function.

With this I am one step closer to completely removing the old ASM stuff that was in the table when I downloaded it (and building a decent table for referencing when I want to upgrade my existing custom tables)

_________________
Those who do not trust in christ to save them from their sins will only experience hell when their soul is released from it's earthly vessel.
Back to top
View user's profile Send private message
FreeER
Grandmaster Cheater Supreme
Reputation: 53

Joined: 09 Aug 2013
Posts: 1091

PostPosted: Mon Jan 22, 2018 7:08 am    Post subject: Reply with quote

huh, whats the logic behind that @TheyCallMeTim13? Some inheritance? or just a guess since you haven't done it that way before Smile
Back to top
View user's profile Send private message
TheyCallMeTim13
Wiki Contributor
Reputation: 50

Joined: 24 Feb 2017
Posts: 976
Location: Pluto

PostPosted: Mon Jan 22, 2018 10:20 am    Post subject: Reply with quote

Other languages generally require a proper parent so the resource clean up can know how to handle it. And I tried it on mine, just had a hunch, with the access violation that I seemed to get when I didn't give it a parent at all, It may be some thing unique to windows 7, or maybe the service pack, not really sure if it doesn't do it to every one (I just assumed it did).
_________________
Back to top
View user's profile Send private message Visit poster's website
FreeER
Grandmaster Cheater Supreme
Reputation: 53

Joined: 09 Aug 2013
Posts: 1091

PostPosted: Mon Jan 22, 2018 10:46 am    Post subject: Reply with quote

Makes sense.
It is marked as optional however
Quote:
createTimer(owner OPT, enabled OPT):
Creates a timer object. If enabled is not given it will be enabled by default (will start as soon as an onTimer event has been assigned)
Owner may be nil, but you will be responsible for destroying it instead of being the responsibility of the owner object)

and I can't remember ever having issues with it being nil, can't recall now if I started using lua back when I was on 7 or not however (I know I did some really basic stuff but).
Back to top
View user's profile Send private message
TheyCallMeTim13
Wiki Contributor
Reputation: 50

Joined: 24 Feb 2017
Posts: 976
Location: Pluto

PostPosted: Mon Jan 22, 2018 11:00 am    Post subject: Reply with quote

Yeah, like I said it does it me, may be some setting that makes my system more strict on that, but I have not done that on purpose. But I do have QT, PyQt, Code Blocks, Visual Studio, Oracle's IDE, and now Lazarus (plus some odd ball ones for one off embedded languages). So may be one of these has caused this.
_________________
Back to top
View user's profile Send private message Visit poster's website
FreeER
Grandmaster Cheater Supreme
Reputation: 53

Joined: 09 Aug 2013
Posts: 1091

PostPosted: Mon Jan 22, 2018 11:09 am    Post subject: Reply with quote

Oracle has an IDE? ah, Netbeans is Oracle, though it looks like they've had at least one other lol. I've had all of those installed at one time or another, currently just VS community and Lazarus though Smile
Back to top
View user's profile Send private message
TheyCallMeTim13
Wiki Contributor
Reputation: 50

Joined: 24 Feb 2017
Posts: 976
Location: Pluto

PostPosted: Mon Jan 22, 2018 11:21 am    Post subject: Reply with quote

I have to admit this is making me more curious as to way it seems to always happen to me. I might have to do some poking around if I find any thing I will PM you (and/or make a post if I have a fix).

But I have 2 IDEs that embeds Lua for some devices, and this f'in iWrite thing, and some others I can't even remember (had to use them for projects from time to time).

_________________
Back to top
View user's profile Send private message Visit poster's website
FreeER
Grandmaster Cheater Supreme
Reputation: 53

Joined: 09 Aug 2013
Posts: 1091

PostPosted: Mon Jan 22, 2018 12:13 pm    Post subject: Reply with quote

I was hoping you'd get curious Smile I've always used it with nil (except for rare cases where it made sense to use a specific parent) and haven't had anyone complain, though I doubt most of what I've shared is used a lot I'm sure they've been tried a few times lol
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 458

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

PostPosted: Mon Jan 22, 2018 12:31 pm    Post subject: Reply with quote

MemoryRecord inherits of the Object class

The timer create function either takes nil, or a type inherited from the "Component" class

Object does not inherit from Component , so when the timer creation tries to access a value in the MemoryRecord's Component memory to specify it's a child of MemoryRecord, it'll access unrelated memory, and likely crash

(I should probably mention in the docs that owners can only be Component class or higher, or just disallow it)

_________________
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
FreeER
Grandmaster Cheater Supreme
Reputation: 53

Joined: 09 Aug 2013
Posts: 1091

PostPosted: Mon Jan 22, 2018 12:50 pm    Post subject: Reply with quote

That's about what I expected DB, and yeah it should be mentioned in the docs (and probably disallowed in the code as well if it's trivial) Smile

Though much of the discussion here, past the solution, stems from the fact that Tim will get an access violation from nil as well, which shouldn't happen.

TheyCallMeTim13 wrote:
with the access violation that I seemed to get when I didn't give it a parent at all
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 458

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

PostPosted: Mon Jan 22, 2018 1:00 pm    Post subject: Reply with quote

that might have been a very old CE that didn't properly initialize owner, or memory corruption was the cause here, (e.g giving the wrong parent may go fine for a few times until there's too much damage)
but the code path does not do anything if the owner var is nil

_________________
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
TheyCallMeTim13
Wiki Contributor
Reputation: 50

Joined: 24 Feb 2017
Posts: 976
Location: Pluto

PostPosted: Mon Jan 22, 2018 3:33 pm    Post subject: Reply with quote

Yeah, I got so in the habit of passing the main form as the parent, but it's not doing it to me with 6.7, so kinda hard for me to say. And heck maybe it was just me doing some thing else that seemed unrelated but was my problem all along.

But even when I did get this error, I saw code with nil as the parent all the time.

EDIT:
I think it was like version 5.2 when I got this error the first time.

_________________
Back to top
View user's profile Send private message Visit poster's website
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