| View previous topic :: View next topic | 
	
	
		| Author | Message | 
	
		| GodKratos Cheater
 
 ![]() Reputation: 0 
 Joined: 18 Jul 2011
 Posts: 30
 
 
 | 
			
				|  Posted: Thu Aug 11, 2011 5:58 am    Post subject: lua parameter types |   |  
				| 
 |  
				| 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 |  | 
	
		|  | 
	
		| Dark Byte Site Admin
 
  Reputation: 470 
 Joined: 09 May 2003
 Posts: 25807
 Location: The netherlands
 
 | 
			
				|  Posted: Thu Aug 11, 2011 6:36 am    Post subject: |   |  
				| 
 |  
				| 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 |  | 
	
		|  | 
	
		| GodKratos Cheater
 
 ![]() Reputation: 0 
 Joined: 18 Jul 2011
 Posts: 30
 
 
 | 
			
				|  Posted: Fri Aug 12, 2011 12:10 am    Post subject: |   |  
				| 
 |  
				| 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:
 And they both fail to show a message window at all. 	  | Code: |  	  | strKey = string.byte(key) showMessage(strKey)
 
 strKey = string.char(key)
 showMessage(strKey)
 | 
 
 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 |  | 
	
		|  | 
	
		| Dark Byte Site Admin
 
  Reputation: 470 
 Joined: 09 May 2003
 Posts: 25807
 Location: The netherlands
 
 | 
			
				|  Posted: Fri Aug 12, 2011 1:10 am    Post subject: |   |  
				| 
 |  
				| 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 |  | 
	
		|  | 
	
		| GodKratos Cheater
 
 ![]() Reputation: 0 
 Joined: 18 Jul 2011
 Posts: 30
 
 
 | 
			
				|  Posted: Fri Aug 12, 2011 1:14 am    Post subject: |   |  
				| 
 |  
				| 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 |  | 
	
		|  | 
	
		| Dark Byte Site Admin
 
  Reputation: 470 
 Joined: 09 May 2003
 Posts: 25807
 Location: The netherlands
 
 | 
			
				|  Posted: Fri Aug 12, 2011 1:20 am    Post subject: |   |  
				| 
 |  
				| 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 |  | 
	
		|  | 
	
		| GodKratos Cheater
 
 ![]() Reputation: 0 
 Joined: 18 Jul 2011
 Posts: 30
 
 
 | 
			
				|  Posted: Fri Aug 12, 2011 1:44 am    Post subject: |   |  
				| 
 |  
				| 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!
   
 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 |  | 
	
		|  | 
	
		| Dark Byte Site Admin
 
  Reputation: 470 
 Joined: 09 May 2003
 Posts: 25807
 Location: The netherlands
 
 | 
			
				|  Posted: Fri Aug 12, 2011 1:53 am    Post subject: |   |  
				| 
 |  
				| 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 |  | 
	
		|  | 
	
		| GodKratos Cheater
 
 ![]() Reputation: 0 
 Joined: 18 Jul 2011
 Posts: 30
 
 
 |  | 
	
		| Back to top |  | 
	
		|  | 
	
		| Dark Byte Site Admin
 
  Reputation: 470 
 Joined: 09 May 2003
 Posts: 25807
 Location: The netherlands
 
 | 
			
				|  Posted: Fri Aug 12, 2011 2:24 am    Post subject: |     |  
				| 
 |  
				| 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 |  | 
	
		|  | 
	
		| GodKratos Cheater
 
 ![]() Reputation: 0 
 Joined: 18 Jul 2011
 Posts: 30
 
 
 | 
			
				|  Posted: Fri Aug 12, 2011 3:21 am    Post subject: |   |  
				| 
 |  
				| Ah ok, that be why it don't work for me then   
 I'll wait for the new version
   
 Thanks for your help!
 |  | 
	
		| Back to top |  | 
	
		|  | 
	
		|  |