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 


Changing label text on button click

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

Joined: 13 Sep 2010
Posts: 34

PostPosted: Mon Jul 04, 2011 6:53 pm    Post subject: Changing label text on button click Reply with quote

Hey

I want to change a label text when I press a button. I tried the following:

function CEButton2Click(sender)
CELabel2:SetText("text")
end

But this does not work Sad
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 Jul 04, 2011 9:05 pm    Post subject: Reply with quote

this only works if you have a class wrapper and wrapped the CELabel2 into a class object of the same name

usually you just do: control_setCaption(CELabel2, "text")

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

Joined: 13 Sep 2010
Posts: 34

PostPosted: Tue Jul 05, 2011 6:51 am    Post subject: Reply with quote

Hmm its not working atm Sad

1. Does it need to be after :
"--TRAINERGENERATORSTOP--"
It seems to place it there automatically so I presume it has and the first part is a sort of "OnCreate" event ? (Im used to programming delphi, never programmed lua before ...)

2. Is ther any "preview" button that compiles and shows me the trainer without having to manually save and runing the "cetrainer" manually outside the editing CE currently open?

3. The button is not in the same panel as the label but it is on the same form ... so I'm guessing that should be allright ?

My code:



Code:
--TRAINERGENERATORSTART--
--This is autogenerated code. Changing code in this block will
--get erased and rewritten if you regenerate the trainer code

--Uncomment the following line if this is a Cheat Table format trainer and you don't want CE to show (Tip, save as .CETRAINER alternatively)
--hideAllCEWindows()
addresslist=getAddressList()
memrec1=addresslist_getMemoryRecordByID(addresslist,1)

memrec1_hotkey0=memoryrecord_getHotkeyByID(memrec1,0)

function onHotkey0(Hotkey)
  --Executed before the hotkey is handled
  cheatcomponent_setActive(CETrainer_CHEAT0, true, 1500)
  if gBeepOnAction then
    beep()
  end
end

memoryrecordhotkey_onHotkey(memrec1_hotkey0,onHotkey0)
control_setVisible(CETrainer_SEPERATOR, false)

strings_add(getAutoAttachList(), "gameprocess.exe")
gBeepOnAction=false
form_show(CETrainer)
function AboutClick()
  showMessage(gAboutText)
end
gAboutText=[[This trainer was made by Cheat Engine
www.cheatengine.org]]

function CloseClick()
  closeCE()
  return caFree --onClick doesn't care, but onClose would like a result
end

--TRAINERGENERATORSTOP--
function CEButton2Click(sender)
control_setCaption(CELabel2, "text")
end
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: Tue Jul 05, 2011 8:59 am    Post subject: Reply with quote

if it's a label on a designed form then the name of the label is formname_labelname

so CETrainer_CELabel2

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

Joined: 13 Sep 2010
Posts: 34

PostPosted: Tue Jul 05, 2011 9:24 am    Post subject: Reply with quote

Doesn't work Sad

My new block:
function CEButton2Click(sender)
control_setCaption(CETrainer_CELabel2, "text")
end

After another look, nothing works ... its like the code doesn't run on the onclick of the butto nevent ? I tried with just a plain "showmessage" and that doesn't work either ?

To summerize, I got the form "CETrainer", in there a Groupbox, in there a panel and on that panel the label. (if that changes anything)
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: Tue Jul 05, 2011 3:27 pm    Post subject: Reply with quote

have you closed the designer (thats the bar with the components you can select from) when clicking the button?
Events do not get handled as long as the designer mode is active

and of course, have you assigned CEButton2Click to the onClick event handler of the button ?

(also, it's showMessage)

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

Joined: 13 Sep 2010
Posts: 34

PostPosted: Tue Jul 05, 2011 7:16 pm    Post subject: Reply with quote

Hey

With some fiddling I got some stuff to work, I ran into a next probably smaller problem though....

When in design mode I can easily add multilines to a label. However when using the line:

Code:
control_setCaption(CETrainer_INFOLABEL, "This is a test to see if it will automatically break off the sentence and use multiline so it fits in the box")


It just uses one line, doesn't care it runs out of space (it's not autosize as it needs to fit in my panel) and well it cuts off beyond my panel and half the sentence isn't visible anymore. That while it has all the space it wants vertically if it uses multiline.

I know how to do it in designtime.. how can I let the "app" do it auto in runtime ?
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: Tue Jul 05, 2011 8:21 pm    Post subject: Reply with quote

disable autosize on the label or put the label in a panel of a fixed width with no borderstyle and set align to alClient. When you then use setCaption it should be limited to the given height and width and use multilines when needed
_________________
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
DJK
Cheater
Reputation: 0

Joined: 13 Sep 2010
Posts: 34

PostPosted: Thu Jul 07, 2011 6:16 pm    Post subject: Reply with quote

Hey

Well I worked around it with just using two labels Smile Anyway I have a few more questions.

1. How can I use a checkbox to freeze a value ?
2. How can I use a edit box to let me "choose any value' ?

Basically I have 3 elements for every cheat on my form.
checkbox - editbox - button

When I use the checkbox it should freeze or unfreeze the current value.
Changing the editbox doesn't do anything on itself, however
Pressing the button (or hotkey) should change the value to whatever the edit box says (number)


3. How would I read a txt file in a memo using lua ? (in delphi its easy like pie with something like "memo1.lines := loadfromfile('c:\myfile');"
But im sure in lua its a tad different Smile

I'm guessing this is going to be my last questions, can't think of a lot I will still need if I can get these 3 working Smile

Thanks for all the help!
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: Thu Jul 07, 2011 6:32 pm    Post subject: Reply with quote

1:
You place a checkbox and add a onChange event handler. In there you get the state of the checkbox, and then activate or disable the specific cheat (memoryrecord_freeze / memoryrecord_unfreeze)

And then update the gui accordingly. E.g setting the color to red, or flash, or play a sound, etc...

2:
the TCheat component has a haseditbox field that the automated scriptgenerator looks at when generating the script. If it's checked it adds some code that checks what the user has given and then call memoryrecord_setValue when triggered

alternatively, place a editbox, and after using the automated script generator edit the script where the hotkey has been handled. Or register a memoryrecord_onActivate for the cheatentry yourself and in there call memoryrecord_setValue. (only do that when before is false and currentstate is true for best results)

----
Quote:

Basically I have 3 elements for every cheat on my form.
checkbox - editbox - button

sorry, read over that.
Ok, so I assume you have designed your trainer manually. this means you are fully responsible for updating the gui states and dealing with mouseclicks and statechanges.
When the checkbox is clicked (onChange), you must check what the new state of the checkbox is and act accordingly
If the editbox contains data, or is edited (onchange) you will have to deal with that. Get the new text and pass that on to a cheat entry
If the button is clicked, you must handle the onClick, and in there do what you have to. (Get the cheatentry and set it to active, then read the uservalue and set the value in the cheatentry)




3:
you first get the Strings object that belongs to the memo : memo_getLines
and then you use strings_loadFromFile on that strings object to load the text

_________________
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
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