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 


control_getCaption , CEEdit control instructions
Goto page 1, 2, 3  Next
 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
iroku
Advanced Cheater
Reputation: 0

Joined: 18 Oct 2012
Posts: 54

PostPosted: Mon Apr 15, 2013 11:52 am    Post subject: control_getCaption , CEEdit control instructions Reply with quote

hey

Im trying to figure out how to work with CEEdit boxes.

I have a clickbox that enables/desables a function.

This is the clickbox timer configuration

Code:
function CECheckbox1Click(sender) -- if Game timer option is clicked
Timer_enabledOrDisabled = (checkbox_getState(sender)==1)
  timer_setEnabled(StopTimerStatus_Timer, Timer_enabledOrDisabled) -- creates a timer if clicked true
 end


This is its timer

Code:
if StopTimerStatus_Timer~=nil then object_destroy(StopTimerStatus_Timer) -- Game Timer object destruction conditions
StopTimerStatus_Timer=nil
end

StopTimerStatus_Timer = createTimer(nil,false) -- Game Timer timer starting conditions
timer_onTimer(StopTimerStatus_Timer, myONtimerFunc)-- Starts StopTimerStatus_Timer creation function  at myONtimerFunc event
timer_setInterval(StopTimerStatus_Timer,150)-- restarts every 0.1s


Now, i have 2 CEEdit boxes CEEdit1, CEEdit 4 and this is how i have them set.

Code:

function CEEdit1Change(sender)
 local TimerShortcutKey1=Control_getCaption(UDF2_CEEdit1)
 end

function CEEdit4Change(sender)
 local TimerShortcutKey2=Control_getCaption(UDF2_CEEdit4)
end

if TimerShortKey~=nil then object_destroy(TimerShortKey);TimerShortKey=nil;end
local TimerShortKey = createHotkey(function ()
                        timer_setEnabled(StopTimerStatus_Timer, not timer_getEnabled(StopTimerStatus_Timer) )
                end,  TimerShortcutKey1, TimerShortcutKey2 )


What i want is to enable keyshotcuts where Timerkey1 + TimerKey2 would make 1 keyshortcut like :

CRL(Key1)+D(Key2)=Clickbox1 enable/disable

But i keep getting an error:

Error:[string "--\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\..."]:136: attempt to call global 'Control_getCaption' (a nil value)

i was trying to use the same timer to enable/desable the keys.

This could work (if code is properly writen, but still forces us to write a "string", maybe i could have him read key input and print on CEEdit1, and CEE1 on change would do myONtimerfunc.
Dont know, but i could use some help


Last edited by iroku on Mon Apr 15, 2013 3:46 pm; edited 1 time in total
Back to top
View user's profile Send private message
mgr.inz.Player
I post too much
Reputation: 218

Joined: 07 Nov 2008
Posts: 4438
Location: W kraju nad Wisla. UTC+01:00

PostPosted: Mon Apr 15, 2013 2:36 pm    Post subject: Reply with quote

you forget what I wrote: Lua is case-sensitive.


If you see this error message:
Code:
attempt to call global 'Control_getCaption' (a nil value)

or this
Code:
attempt to call global 'timer_OnTimer' (a nil value)


You can be 100% sure you made a typo. Because it should be
control_getCaption (first char must me lowercase)
and
timer_onTimer (the same here, o must be lowercase o)

Because functions like those, don't exist:
Control_getCaption, control_GetCaption, control_getcaption, control_Getcaption



And createHotkey usage is createHotkey(function, key1, key2, ....).

Those key are integer values, VK codes:
http://msdn.microsoft.com/pl-pl/library/windows/desktop/dd375731%28v=vs.85%29.aspx


Your hotkey creation should look like this:
createHotkey(function, VK_CONTROL, VK_D)


As you see, you cannot use string type (text type).

_________________


Last edited by mgr.inz.Player on Mon Apr 15, 2013 2:42 pm; edited 2 times in total
Back to top
View user's profile Send private message MSN Messenger
DaSpamer
Grandmaster Cheater Supreme
Reputation: 52

Joined: 13 Sep 2011
Posts: 1578

PostPosted: Mon Apr 15, 2013 2:38 pm    Post subject: Reply with quote

Code:
Error:[string "--\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\..."]:136: attempt to call global 'Control_getCaption' (a nil value)

maybe because you used
Code:
Control_getCaption

And it suppose to be
Code:
control_getCaption

its case sensitive.

Grr mgr.inz.Player has answered it before I did >.<
mgr.inz.Player wrote:
you forget what I wrote: Lua is case-sensitive.


If you see this error message:
Code:
attempt to call global 'Control_getCaption' (a nil value)

or this
Code:
attempt to call global 'timer_OnTimer' (a nil value)


You can be 100% sure you made a typo. Because it should be
control_getCaption (first char must me lowercase)
and
timer_onTimer (the same here, o must be lowercase o)

Because functions like those, don't exist:
Control_getCaption, control_GetCaption, control_getcaption, control_Getcaption



And createHotkey usage is createHotkey(function, key1, key2, ....).

Those key are integer values, VK codes:
http://msdn.microsoft.com/pl-pl/library/windows/desktop/dd375731%28v=vs.85%29.aspx


You hotkey creation should look like this:
createHotkey(function, VK_CONTROL, VK_D)


As you see, you cannot use string type (text type).
[/quote]
_________________
HEY Hitler
Do you get lazy when making trainers?
Well no more!
My CETrainer will generate it for you in seconds, so you won't get lazy! Very Happy

http://forum.cheatengine.org/viewtopic.php?t=564919
Back to top
View user's profile Send private message
mgr.inz.Player
I post too much
Reputation: 218

Joined: 07 Nov 2008
Posts: 4438
Location: W kraju nad Wisla. UTC+01:00

PostPosted: Mon Apr 15, 2013 2:48 pm    Post subject: Reply with quote

I forget to mention, defines.lua is loaded after launching CE.
So VK_CONTROL already is integer 17, and VK_D is 68.

_________________
Back to top
View user's profile Send private message MSN Messenger
iroku
Advanced Cheater
Reputation: 0

Joined: 18 Oct 2012
Posts: 54

PostPosted: Sun Apr 21, 2013 8:21 am    Post subject: Reply with quote

well, before, i was trying to use an already made function timer, from: CEClickbox(sender)

Code:

function CECheckbox1Click(sender) -- if Game timer option is clicked
Timer_enabledOrDisabled = (checkbox_getState(sender)==1)
  timer_setEnabled(StopTimerStatus_Timer, Timer_enabledOrDisabled) -- creates a timer if clicked true
 end


and this next code wasnt working (i was told) becouse of ((checkbox_getState(sender)==1) from previous code)

Code:

function CEEdit1Change(sender)
 local TimerShortcutKey1=control_getCaption(UDF2_CEEdit1)
 end

function CEEdit4Change(sender)
 local TimerShortcutKey2=control_getCaption(UDF2_CEEdit4)
end

if TimerShortKey~=nil then object_destroy(TimerShortKey);TimerShortKey=nil;end
local TimerShortKey = createHotkey(function ()
                        timer_setEnabled(StopTimerStatus_Timer, not timer_getEnabled(StopTimerStatus_Timer) )
                end,  TimerShortcutKey1, TimerShortcutKey2 )

-- doesn't work because of (checkbox_getState(sender)==1


so i made a new code with new timers and was trying a simple test with just "CONTROL" "F1"

Code:

function CEEdit1Change(sender)
   TimerShortcutKey1= (control_getCaption(UDF2_CEEdit1)=="CONTROL")
  timer_setEnabled(If_timer_key1_changed, TimerShortcutKey1)
 end

function CEEdit4Change(sender)
 TimerShortcutKey2= (control_getCaption(UDF2_CEEdit4)=="F1")
   timer_setEnabled(If_timer_key2_changed, TimerShortcutKey2)
end

CONTROL_F1= TimerShortcutKey1==("CONTROL") and TimerShortcutKey2==("F1")
CONTROL_F1_true= CONTROL_F1==true and isKeyPressed(VK_CONTROL, VK_F1)==true


function check_for_key_CONTROL_F1()
 if CONTROL_F1_true==true then
 checkbox_setState(UDF2_CECheckbox1, 1)
  create_CONTROL_F1= createHotkey(check_for_key_CONTROL_F1, VK_F1, VK_CONTROL)
                        timer_getEnabled(If_timer_key1_changed)




 If_timer_key1_changed = createTimer(nil,false)
 timer_onTimer(If_timer_key1_changed, check_for_key_CONTROL_F1)
 timer_setInterval(If_timer_key1_changed,100)

 If_timer_key2_changed = createTimer(nil,false)
 timer_onTimer(If_timer_key2_changed, check_for_key_CONTROL_F1)
 timer_setInterval(If_timer_key2_changed,100)


but seems to have the same result. maybe due to checkbox_setState(UDF2_CECheckbox1, 1) as well.

i could really use pointers to get this working. There is no error what so ever and hotkey is never created, with or without CEEdit boxes with text. but even if i do type CONTROL F1 it doesn't create the hotkey :/
Back to top
View user's profile Send private message
Gniarf
Grandmaster Cheater Supreme
Reputation: 43

Joined: 12 Mar 2012
Posts: 1285

PostPosted: Mon Apr 22, 2013 11:39 am    Post subject: Re: control_getCaption , CEEdit control instructions Reply with quote

iroku wrote:
I have a clickbox that enables/desables a function.

This is the clickbox timer configuration

[...]

What i want is to enable keyshotcuts where Timerkey1 + TimerKey2 would make 1 keyshortcut like :

CRL(Key1)+D(Key2)=Clickbox1 enable/disable
If I understand correctly you have 2 separate goals:
1-Have a clickbox (aka checkbox) start and stop a timer. For that your CECheckbox1Click looks correct, except that I recommend using OnChange instead of OnClick (see why below).
2-Have user definable hotkeys. For that you use 2 editbox (not bad for a start, better have custom controls that detects what key is pressed in the final version), but the fact of changing hotkeys shouldn't trigger any timer, instead you should just change the keys that make up your hotkey. I mean something like that:
Code:
FirstKey=VK_F1;
SecondKey=nil;
ToggleCheckBoxHotkey=createHotkey(ToggleCheckBoxStatus,VK_F1);

function CEEdit1Change(sender) --when changing the key in UDF2_CEEdit1...
  if (control_getCaption(UDF2_CEEdit1)=="CONTROL") then
    FirstKey=VK_CONTROL;
  end
  --...redefine the key that make up ToggleCheckBoxHotkey
  generichotkey_setKeys(ToggleCheckBoxHotkey, FirstKey, SecondKey);
end

function CEEdit2Change(sender)
  if (control_getCaption(UDF2_CEEdit2)=="F1) then
    SecondKey=VK_F1;
  end
  generichotkey_setKeys(ToggleCheckBoxHotkey, FirstKey, SecondKey);
end

function ToggleCheckBoxHotkey(sender) --will change the state of the checkbox, which will trigger a call to its OnChange event handler.
  checkbox_setState(UDF2_CECheckbox1, not checkbox_getState(UDF2_CECheckbox1));
end
Disclaimer: I didn't test this.


.......Or perhaps I simply didn't understand what you wanted to do.
Back to top
View user's profile Send private message
iroku
Advanced Cheater
Reputation: 0

Joined: 18 Oct 2012
Posts: 54

PostPosted: Mon Apr 22, 2013 1:53 pm    Post subject: Re: control_getCaption , CEEdit control instructions Reply with quote

Gniarf wrote:


If I understand correctly you have 2 separate goals:
1-Have a clickbox (aka checkbox) start and stop a timer. For that your CECheckbox1Click looks correct, except that I recommend using OnChange instead of OnClick (see why below).
2-Have user definable hotkeys. For that you use 2 editbox (not bad for a start, better have custom controls that detects what key is pressed in the final version), but the fact of changing hotkeys shouldn't trigger any timer, instead you should just change the keys that make up your hotkey.

.......Or perhaps I simply didn't understand what you wanted to do.


yes thats it.

i tried but there seems to be an access violation with function

Code:
function ToggleCheckBoxHotkey(sender)
  checkbox_setState(UDF2_CECheckbox1, not checkbox_getState(UDF2_CECheckbox1));
end


Its weird because it got me confused as well. I did not know we could do that. How would it know what sender is of a non Lua object ? Same goes for ToggleCheckBoxStatus. Nowhere in the script is ToggleCheckBoxStatus defined, maybe this is why i get the acess error ?
im at (code attached)

i did change the CeckBox to OnChange event.
I like this approach since it does not need timers. ill look into this a bit thanks



Hotkey.lua
 Description:
Hotkey

Download
 Filename:  Hotkey.lua
 Filesize:  1.92 KB
 Downloaded:  778 Time(s)

Back to top
View user's profile Send private message
iroku
Advanced Cheater
Reputation: 0

Joined: 18 Oct 2012
Posts: 54

PostPosted: Tue Apr 23, 2013 8:07 am    Post subject: Reply with quote

mm seems to be the same problem as before.

He gets confused when he need to read the clickbox state...

i tried changing the function

function ToggleCheckBoxHotkey(sender)


Code:
  function ToggleCheckBoxHotkey(sender) --will change the state of the checkbox, which will trigger a call to its OnChange event handler.
 local state = checkbox_getState(UDF2_CECheckbox1)
 checkbox_setState(UDF2_CECheckbox1,  1 - state)
end


i even tried defining ToggleCheckBoxStatus to no avail

And changed (sender) to just
function ToggleCheckBoxHotkey()

always the same acess error :/
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 458

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

PostPosted: Tue Apr 23, 2013 8:40 am    Post subject: Reply with quote

I think the problem is that you haven't defined a form named UDF2 with a checkbox names CECheckbox1

Also, keep in mind that checkbox_getState returns one of these 3 values: cbUnchecked (0) , cbChecked (1) and cbGrayed (2)

And checkbox_setState takes one of those 3 values

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

Joined: 18 Oct 2012
Posts: 54

PostPosted: Tue Apr 23, 2013 8:56 am    Post subject: Reply with quote

Dark Byte wrote:
Keep in mind that checkbox_getState returns one of these 3 values: cbUnchecked (0) , cbChecked (1) and cbGrayed (2)

And checkbox_setState takes one of those 3 values


i have:

Code:
checkbox_setAllowGrayed(UDF2_CECheckbox1, false)


at form opening settings, i was under the impression that (2) would never return
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 458

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

PostPosted: Tue Apr 23, 2013 8:57 am    Post subject: Reply with quote

2 never returns, but you can still set it (and 1-0 is not the same as 0)


Just make sure the variable names you use actually exist (check that they are not 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
iroku
Advanced Cheater
Reputation: 0

Joined: 18 Oct 2012
Posts: 54

PostPosted: Tue Apr 23, 2013 9:58 am    Post subject: Reply with quote

Dark Byte wrote:
2 never returns, but you can still set it (and 1-0 is not the same as 0)


MM, how would it set to 2 ? do you mean 1-1 is not the same as 0 ?
if state = 0 (1-0=1, checked) if state =1 (1-1=0,unchecked)
if it state never returns 2 then i don't see how setState can set to 2(with this scenario)... i might be reading it wrong, as usual when it comes to this :/

Quote:

anyhow, try changing UDF2_CECheckbox1 to sender


still no good

Quote:

I think the problem is that you haven't defined a form named UDF2 with a checkbox names CECheckbox1


when i click on the clickbox1 on UDF2 it does its function, so i though that UDF2 with a clickbox named CECheckbox1 was defined...
if its not tho, how do i make sure it is ?
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 458

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

PostPosted: Tue Apr 23, 2013 10:02 am    Post subject: Reply with quote

Check the name property of the checkbox in the form that has as name UDF2
To access that checkbox you must then use UDF2_name

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

Joined: 18 Oct 2012
Posts: 54

PostPosted: Tue Apr 23, 2013 10:35 am    Post subject: Reply with quote

Dark Byte wrote:
Check the name property of the checkbox in the form that has as name UDF2
To access that checkbox you must then use UDF2_name


Form name= UDF2 (same as caption)

CECheckbox1: TCECheckBox

the checkbox is inside a panel, that is olso inside another pannel.

do i have to call UDF2_CEPanel1_CEPanel4_CECheckbox1 ?



formname.png
 Description:
 Filesize:  61.4 KB
 Viewed:  18511 Time(s)

formname.png


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

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

PostPosted: Tue Apr 23, 2013 11:48 am    Post subject: Reply with quote

UDF2_CECheckbox1 should work then (assuming it's defined at the time the script runs)

Are you sure setting the state is the cause of the crash an not another line? (Try some prints)
What you could also use is setProperty( UDF2_CECheckbox1, "checked", trueorfalse)

_________________
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


Last edited by Dark Byte on Tue Apr 23, 2013 12:02 pm; edited 1 time in total
Back to top
View user's profile Send private message MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting All times are GMT - 6 Hours
Goto page 1, 2, 3  Next
Page 1 of 3

 
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