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 


If Statement and Toggleboxes

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

Joined: 02 Oct 2017
Posts: 39

PostPosted: Mon Jan 01, 2018 8:16 pm    Post subject: If Statement and Toggleboxes Reply with quote

Hello guys, and happy new year!
I am working on a trainer, and i just can't figure out how to use an if statement to check if a togglebox is enabled or not.
I have two toggleboxes, and i want to have different scripts enabled, depending on if one of them gets enabled before the other one.
I think you get what i mean.
My code right now looks like this:
Code:
function CEToggleBox14Click(sender)
if CEToggleBox13 == true then
    getAddressList().getMemoryRecordByDescription("hack1").Active = sender.Checked
else
    getAddressList().getMemoryRecordByDescription("hack2").Active = sender.Checked
end
end

I tried to change it to "== Active" aswell, but still nothing. What am i missing?
Thanks!
Back to top
View user's profile Send private message
TheyCallMeTim13
Wiki Contributor
Reputation: 50

Joined: 24 Feb 2017
Posts: 976
Location: Pluto

PostPosted: Mon Jan 01, 2018 9:34 pm    Post subject: Reply with quote

If it's a check box, then "checkbox_getState" will do it.

Code:
checkbox_getState(checkbox) Gets the current state of the checkbox


CheckBox class

_________________
Back to top
View user's profile Send private message Visit poster's website
FreeER
Grandmaster Cheater Supreme
Reputation: 53

Joined: 09 Aug 2013
Posts: 1091

PostPosted: Mon Jan 01, 2018 9:42 pm    Post subject: This post has 1 review(s) Reply with quote

CEToggleBox13.Checked is the boolean that represents the checked/unchecked state (there's also State which is cbUnchecked=0, cbChecked=1, cbGrayed=2), it's based on the CheckBox (same functionality, different appearance) hence the name. In this case I'd personally skip the if statement and use

Code:
function CEToggleBox14Click(sender)
  local name = CEToggleBox13.Checked and 'hack1' or 'hack2'
  getAddressList().getMemoryRecordByDescription(name).Active = sender.Checked
end
Back to top
View user's profile Send private message
Gou
Cheater
Reputation: 0

Joined: 02 Oct 2017
Posts: 39

PostPosted: Mon Jan 01, 2018 10:51 pm    Post subject: Reply with quote

Thanks for the replies guys!

@Tim Unfortunately, it's not a checkbox. It's a togglebox.

@FreeER i tried both
Code:
CEToggleBox13.Checked == true
CETogglebox13.State == 1

and also the code that you wrote, but all of them spit the same error on the console when i enable the togglebox
Code:
197: attempt to index a nil value (global 'CEToggleBox13')

I'm sure that i am screwing it up somehow, but it looks fine to me
Back to top
View user's profile Send private message
TheyCallMeTim13
Wiki Contributor
Reputation: 50

Joined: 24 Feb 2017
Posts: 976
Location: Pluto

PostPosted: Mon Jan 01, 2018 11:31 pm    Post subject: This post has 1 review(s) Reply with quote

Looked up the ToggleBox class in the celua.txt file.

Quote:

ToggleBox Class: (Inheritance: CheckBox->ButtonControl->WinControl->Control->Component->Object)
createToggleBox(owner): Creates a ToggleBox class object which belongs to the given owner. Owner can be any object inherited from WinControl


Quote:

CheckBox Class: (Inheritance: ButtonControl->WinControl->Control->Component->Object)
createCheckBox(owner): Creates a CheckBox class object which belongs to the given owner. Owner can be any object inherited from WinControl

properties
Checked: boolean - True if checked
AllowGrayed: boolean - True if it can have 3 states. True/False/None
State: checkboxstate - The state. (cbUnchecked=0, cbChecked=1, cbGrayed=2)
OnChange: function - Function to call when the state it changed

methods
getAllowGrayed()
setAllowGrayed(boolean)
getState(): Returns a state for the checkbox. (cbUnchecked, cbChecked, cbGrayed)
setState(boolean): Sets the state of the checkbox
onChange(function)


But "197: attempt to index a nil value (global 'CEToggleBox13')" tells me that "CEToggleBox13" has not been initialized, or it gets set to nil some where before indexing the ToggleBox.

And the "onChange" my be a better way to go.

_________________
Back to top
View user's profile Send private message Visit poster's website
Gou
Cheater
Reputation: 0

Joined: 02 Oct 2017
Posts: 39

PostPosted: Tue Jan 02, 2018 12:17 am    Post subject: Reply with quote

Well, it is initialized. And it's code is 3 lines above Togglebox14 Very Happy
Tried with onChange, but still no luck.
Anyway. I'll find another way of achieving my goal.
Thanks once again guys, and happy new year!
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: Tue Jan 02, 2018 3:36 am    Post subject: Reply with quote

don't forget to provide the formname.

e.g mytrainerform.cetogglebox1.Checked

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

Joined: 02 Oct 2017
Posts: 39

PostPosted: Tue Jan 02, 2018 4:14 am    Post subject: Reply with quote

Oh god... I can't believe i missed this.
I swear to god man, everytime i get stuck when working on something with cheat engine, its because of a really stupid mistake, like this. Hahaha
Thanks dark byte!
Back to top
View user's profile Send private message
FreeER
Grandmaster Cheater Supreme
Reputation: 53

Joined: 09 Aug 2013
Posts: 1091

PostPosted: Tue Jan 02, 2018 10:12 am    Post subject: Reply with quote

@Gou lol, don't beat yourself up too much about it, I missed it too when I first replied. Admittedly I've played with lua enough that I knew the problem as soon as I saw the error but that just comes with time Smile
Back to top
View user's profile Send private message
TheyCallMeTim13
Wiki Contributor
Reputation: 50

Joined: 24 Feb 2017
Posts: 976
Location: Pluto

PostPosted: Tue Jan 02, 2018 1:01 pm    Post subject: Reply with quote

I missed it too.
_________________
Back to top
View user's profile Send private message Visit poster's website
scarface010305
Newbie cheater
Reputation: 0

Joined: 15 Jun 2017
Posts: 22

PostPosted: Tue Jan 09, 2018 10:54 am    Post subject: Reply with quote

TheyCallMeTim13 wrote:
If it's a check box, then "checkbox_getState" will do it.

Code:
checkbox_getState(checkbox) Gets the current state of the checkbox


CheckBox class


Can anyone tell me the correct syntax for this CheckBox Class Linked Example ? (Please a complete example)

Code:
Example:

local form = createForm( true );

local checkBoxes = {};
checkBoxes[1] = createCheckBox( form );
checkBoxes[2] = createCheckBox( form );
checkBoxes[3] = createCheckBox( form );
checkBoxes[4] = createCheckBox( form );
checkBoxes[5] = createCheckBox( form );

for x = 1, #checkBoxes do
    checkBoxes[x].Caption="This is checkbox " .. tostring( x )
    checkBoxes[x].setPosition(10, x * 20)
end

checkBoxes[1].State=0  -- Sets checkboxes[1] to unchecked state.
checkBoxes[2].State=1  -- Sets checkboxes[2] to checked state.
checkBoxes[3].State=2  -- Sets checkboxes[3] to the gray state

if checkBoxes[4].Checked then  -- if checkboxes[4] is checked then the function returns true otherwise false.
   print "true"
else
   print "false"
end


Ive tried so much, but still no idea ..
Back to top
View user's profile Send private message
FreeER
Grandmaster Cheater Supreme
Reputation: 53

Joined: 09 Aug 2013
Posts: 1091

PostPosted: Tue Jan 09, 2018 11:00 am    Post subject: Reply with quote

The only thing that might be incorrect there is that the if statement runs only once and immediately after they're created..



if you want it to always print the result when it's changed then try something like

Code:
local form = createForm( true );

local checkBoxes = {};
checkBoxes[1] = createCheckBox( form );
checkBoxes[2] = createCheckBox( form );
checkBoxes[3] = createCheckBox( form );
checkBoxes[4] = createCheckBox( form );
checkBoxes[5] = createCheckBox( form );

local OnChange = function(cb)
  print(tostring(cb.Checked))
end

for x = 1, #checkBoxes do
  checkBoxes[x].Caption="This is checkbox " .. tostring( x )
  checkBoxes[x].setPosition(10, x * 20)
  checkBoxes[x].OnChange = OnChange
end

checkBoxes[1].State=0  -- Sets checkboxes[1] to unchecked state.
checkBoxes[2].State=1  -- Sets checkboxes[2] to checked state.
checkBoxes[3].State=2  -- Sets checkboxes[3] to the gray state
Back to top
View user's profile Send private message
scarface010305
Newbie cheater
Reputation: 0

Joined: 15 Jun 2017
Posts: 22

PostPosted: Tue Jan 09, 2018 11:37 am    Post subject: Reply with quote

ty very much.
Quickly and helpful for me.
Very Happy
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