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 


Change picture based on memory value

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

Joined: 31 Oct 2015
Posts: 7

PostPosted: Mon Jan 16, 2017 12:32 pm    Post subject: Change picture based on memory value Reply with quote

Hi,

I am trying to write a trainer that allows me to change a picture based on an associated memory value. I have pointers to the value I am looking (1byte 0 or 1 value depending). I have the images loaded, the true image and the false image (false is hidden). I want to be able to swap between the two based on the value in memory.

I tried the following which gives errors.

Code:
function Item1TimerTimer(sender)
         local memrec=addresslist_getMemoryRecordByDescription(getAddressList(), "Item1")
         local value=memoryrecord_getValue(memrec)
         if value then
            control_setPicture(CETrainer_Item1, CETrainer_Item1.Picture)
         else
             control_setPicture(CETrainer_Item1, CETrainer_Quest.Picture)
         end
end


Currently "Item1" always shows it's own picture (since it's loaded with it by default). Any help would be appreciated.
Back to top
View user's profile Send private message
Zanzer
I post too much
Reputation: 126

Joined: 09 Jun 2013
Posts: 3278

PostPosted: Mon Jan 16, 2017 1:03 pm    Post subject: Reply with quote

Code:
if value == 1 then
Instead of trying to swap pictures, maybe you should simply place the two in the same location on your form.
Then simply set each one's visibility depending on your value.
Code:
if value == 1 then
  CETrainer_Item1.Visible = true
  CETrainer_Quest.Visible = false
else
  CETrainer_Item1.Visible = false
  CETrainer_Quest.Visible = true
end
Back to top
View user's profile Send private message
pears
How do I cheat?
Reputation: 0

Joined: 31 Oct 2015
Posts: 7

PostPosted: Mon Jan 16, 2017 1:07 pm    Post subject: Reply with quote

I thought about this, but it'll be 400+ of that for each item. Was attempting to do it with the least amount of work possible heh. If I have to, I'll end up doing something similar. I just don't really see how to access the properties of the image object. Tried to find it on the lua wiki page but wasn't clear.
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 16, 2017 1:09 pm    Post subject: Reply with quote

the first issue I see is the "if value then" line , that will result in true if the value is 0 (it only returns false if value is nil, which isn't the same as 0)

second, if it worked, the original picture of Item1 would be gone. (the picture of item1 gets replaced by Quest.)

Third, setting a picture gives it the same object (images are smart and that they use assign internally, but still, I recommend assign instead)

e.g:

Code:

function Item1TimerTimer(sender)
         if SavedPicture==nil then --global var saving the original picture
           SavedPicture=CreatePicture();
           SavedPicture.assign(CETrainer.Item1.Picture)
         end
         local memrec=getAddressList().getMemoryRecordByDescription("Item1")
 
         if memrec.Value~=0 then
            CETrainer.Item1.Picture.Assign(SavedPicture)
         else
            CETrainer.Item1.Picture.Assign(CETrainer.Quest.Picture)
         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
pears
How do I cheat?
Reputation: 0

Joined: 31 Oct 2015
Posts: 7

PostPosted: Mon Jan 16, 2017 3:22 pm    Post subject: Reply with quote

I see. Thanks Dark Byte. I just didn't really know where to start but this helps a bunch. Appreciate it!
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