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 


lua parameter types

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

Joined: 18 Jul 2011
Posts: 29

PostPosted: Thu Aug 11, 2011 5:58 am    Post subject: lua parameter types Reply with quote

What I'm trying to do at the moment is to have a text box on a form where a user can enter a value that will update a value being used in the cheat table.

I have created a text box and attached an OnKeyPress event to it but I can't figure out what type of syntax I should use to check the key pressed.

My current code is something like this:
Code:
function onKeyPress(sender, key)
  if (key == Enter) then
    memoryrecord_setValue(mmrecXP, control_getCaption(CETrainer_txtXP))
  end
  return key
end


I've tried a few things for the first if check but nothing I have tried works, does anyone know how I can check for when the enter key is pressed?


Another problem I have is with using the readBytes function correctly.
I'm not sure what type of return it gives but whenever I use something like readBytes(address, 4) it only seems to give me the value of the first byte. Is there some special way to use that correctly

(I've used the table formatted return and that seems to work ok but not sure how to use it when not tabled)
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 457

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

PostPosted: Thu Aug 11, 2011 6:36 am    Post subject: Reply with quote

onKeyPress returns the character of the given key as a string

you can compare against the enter key using:
Code:

if (key == "\r") then
  showMessage("enter was pressed")
end




alternatively if in the future you need a character not defined as char and you don't want to use that 0x** specifier , then try the following code which converts a character to a numeric value you can compare against.

Code:

  local nr=string.byte(key)

  if (nr == VK_RETURN) then --or just 13
    showMessage('Enter was pressed');
  end

Note that VK_A to VK_Z are also declared but those are not compatible because key can be lowercase as well


Readbytes: when it's not tabled use it like this:
byte1, byte2, byte3, byte4=readBytes(address, 4)

_________________
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
GodKratos
Cheater
Reputation: 0

Joined: 18 Jul 2011
Posts: 29

PostPosted: Fri Aug 12, 2011 12:10 am    Post subject: Reply with quote

Hmm... I've just tried making that key thing work and I still can't get a correct result.

I tried both of those methods but neither of them seemed to do anything.

I'm not sure that key is returned as a string representation of the key pressed because if I do showMessage(key) it pops up a blank message.

I've tried these:
Code:
strKey = string.byte(key)
showMessage(strKey)

strKey = string.char(key)
showMessage(strKey)
And they both fail to show a message window at all.

I have also tried strKey = tostring(key) which gives me the result nil no matter what key is pressed.

I'm not sure whats going on here...


Last edited by GodKratos on Fri Aug 12, 2011 1:11 am; edited 2 times in total
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 457

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

PostPosted: Fri Aug 12, 2011 1:10 am    Post subject: Reply with quote

try reassigning the event to the function again
_________________
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
GodKratos
Cheater
Reputation: 0

Joined: 18 Jul 2011
Posts: 29

PostPosted: Fri Aug 12, 2011 1:14 am    Post subject: Reply with quote

I've tried recreating the event and that didn't help.

Does a simple print test work for you?
Code:
function onKeyPress(sender, key)
  showMessage(key)
  return key
end




Even wierder, I did a function to show me the value of what I am entering into the text box.
All it does is this:
Code:
print(val .. " = " .. string.len(val))

The results I get though are quite strange.
For a single digit entered it has a ? after the value with length 2.
For two charcters it has a G after the value with length 3.
For three characters it has a dot type character with length 4.
And all other entries of 4 charcters or more show correctly.

screenshot:
postimage.org/image/1hthbd65g/

What's going on here?
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 457

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

PostPosted: Fri Aug 12, 2011 1:20 am    Post subject: Reply with quote

I did test it but it could be that it's already fixed on my version

Try converting the sender variable to text

I just tested on the release of 6.1 and there it's working fine as well

hmm, looks like there is a problem when the form is reset from designmode

_________________
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
GodKratos
Cheater
Reputation: 0

Joined: 18 Jul 2011
Posts: 29

PostPosted: Fri Aug 12, 2011 1:44 am    Post subject: Reply with quote

OK, I just uninstalled my CE6.1, downloaded it again and reinstalled it and now the key event seems to be returning a correct value and all those tests you put in your first post are working.
YAY! Smile

However, the second problem in the above post still exists (although the characters after the text entry are slightly different this time) even though all text entries of 4 or more characters shows correctly.

Is that just my install again...?
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 457

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

PostPosted: Fri Aug 12, 2011 1:53 am    Post subject: Reply with quote

it's a bug. The restore to default function does not handle 'special' parameter events properly

fixed in svn
Guess I'll have to speed up 6.2

_________________
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
GodKratos
Cheater
Reputation: 0

Joined: 18 Jul 2011
Posts: 29

PostPosted: Fri Aug 12, 2011 2:12 am    Post subject: Reply with quote

lol thanks for your quick work to fix it though!

I might download and compile the svn version anyway if it's not out by the time I finish the rest of my code Smile


EDIT: Hmm... I'm still having trouble with that key value not coming out right.
It worked fine when I created a blank form and added the function from scratch with nothing else but when I have gone back to a couple of other tables I had previously saved the same problem occurs when I try to use a similar function.

I'm not sure if it's something wierd in my scripts screwing it up or whether a specific usage of objects/functions/code might trigger the problem...

I've attached my latest copy of this trainer I'm trying to make work (it already has the keypress event in it thats not working) if you feel the urge to look at it Wink



FinalFantasyVII - Copy.CT
 Description:

Download
 Filename:  FinalFantasyVII - Copy.CT
 Filesize:  17.33 KB
 Downloaded:  1915 Time(s)

Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 457

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

PostPosted: Fri Aug 12, 2011 2:24 am    Post subject: This post has 1 review(s) Reply with quote

I just tested your ct and it works as designed
The bottom item in the list will print the "success" line in the lua window when enter is pressed (the 2 other edit fields do nothing as they have no event assigned)

Tested on the fixed version of course, the released 6.1 is 100% incapable of handling this properly

_________________
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
GodKratos
Cheater
Reputation: 0

Joined: 18 Jul 2011
Posts: 29

PostPosted: Fri Aug 12, 2011 3:21 am    Post subject: Reply with quote

Ah ok, that be why it don't work for me then Razz

I'll wait for the new version Very Happy

Thanks for your help!
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