View previous topic :: View next topic |
Author |
Message |
Gou Cheater
Reputation: 0
Joined: 02 Oct 2017 Posts: 39
|
Posted: Mon Jan 01, 2018 8:16 pm Post subject: If Statement and Toggleboxes |
|
|
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 |
|
 |
TheyCallMeTim13 Wiki Contributor
Reputation: 51
Joined: 24 Feb 2017 Posts: 976 Location: Pluto
|
Posted: Mon Jan 01, 2018 9:34 pm Post subject: |
|
|
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 |
|
 |
FreeER Grandmaster Cheater Supreme
Reputation: 53
Joined: 09 Aug 2013 Posts: 1091
|
Posted: Mon Jan 01, 2018 9:42 pm Post subject: |
|
|
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 |
|
 |
Gou Cheater
Reputation: 0
Joined: 02 Oct 2017 Posts: 39
|
Posted: Mon Jan 01, 2018 10:51 pm Post subject: |
|
|
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 |
|
 |
TheyCallMeTim13 Wiki Contributor
Reputation: 51
Joined: 24 Feb 2017 Posts: 976 Location: Pluto
|
Posted: Mon Jan 01, 2018 11:31 pm Post subject: |
|
|
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 |
|
 |
Gou Cheater
Reputation: 0
Joined: 02 Oct 2017 Posts: 39
|
Posted: Tue Jan 02, 2018 12:17 am Post subject: |
|
|
Well, it is initialized. And it's code is 3 lines above Togglebox14
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 |
|
 |
Dark Byte Site Admin
Reputation: 468
Joined: 09 May 2003 Posts: 25706 Location: The netherlands
|
Posted: Tue Jan 02, 2018 3:36 am Post subject: |
|
|
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 |
|
 |
Gou Cheater
Reputation: 0
Joined: 02 Oct 2017 Posts: 39
|
Posted: Tue Jan 02, 2018 4:14 am Post subject: |
|
|
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 |
|
 |
FreeER Grandmaster Cheater Supreme
Reputation: 53
Joined: 09 Aug 2013 Posts: 1091
|
Posted: Tue Jan 02, 2018 10:12 am Post subject: |
|
|
@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
|
|
Back to top |
|
 |
TheyCallMeTim13 Wiki Contributor
Reputation: 51
Joined: 24 Feb 2017 Posts: 976 Location: Pluto
|
Posted: Tue Jan 02, 2018 1:01 pm Post subject: |
|
|
I missed it too.
_________________
|
|
Back to top |
|
 |
scarface010305 Newbie cheater
Reputation: 0
Joined: 15 Jun 2017 Posts: 22
|
Posted: Tue Jan 09, 2018 10:54 am Post subject: |
|
|
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 |
|
 |
FreeER Grandmaster Cheater Supreme
Reputation: 53
Joined: 09 Aug 2013 Posts: 1091
|
Posted: Tue Jan 09, 2018 11:00 am Post subject: |
|
|
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 |
|
 |
scarface010305 Newbie cheater
Reputation: 0
Joined: 15 Jun 2017 Posts: 22
|
Posted: Tue Jan 09, 2018 11:37 am Post subject: |
|
|
ty very much.
Quickly and helpful for me.
|
|
Back to top |
|
 |
|