| View previous topic :: View next topic |
| Author |
Message |
Razi Expert Cheater
Reputation: 1
Joined: 17 Jan 2018 Posts: 205
|
Posted: Sun Aug 09, 2020 8:04 am Post subject: Boolean as a value |
|
|
I want to ask 1 question about boolean.
| Code: | if value == 1 then
UDF1.CECheckBox1.Checked = true
elseif value == 0 then
UDF1.CECheckBox1.Checked = false
end |
Is it possible not to use if elseif in the above code, like this: UDF1.CECheckBox1.Checked = value ? (without using the state property of the checkbox)
I want to use something like this: Checked = (value=='1') or Checked = tonumber(value) insted of: true, false
And how to write with checkbox checked property without using if elsif and state property ?:
| Code: | UDF1.CECheckBox1.OnClick = function(sender)
if UDF1.CECheckBox1.Checked == true then
writeBytes(0x9E91B4, 1)
elseif UDF1.CECheckBox1.Checked == false then
writeBytes(0x9E91B4, 0)
end
end |
2-nd question: When the form is created, the form has a KeyPreview property. What is it and how can it be used? Did not found any information about this.
|
|
| Back to top |
|
 |
AylinCE Grandmaster Cheater Supreme
Reputation: 37
Joined: 16 Feb 2017 Posts: 1549
|
Posted: Sun Aug 09, 2020 8:48 am Post subject: |
|
|
| Code: | local value = 0
UDF1.CECheckBox1.OnClick = function(sender)
if value == 1 then
writeBytes (0x9E91B4, 1)
UDF1.CECheckBox1.Checked = true end
if value == 0 then
writeBytes (0x9E91B4, 0)
UDF1.CECheckBox1.Checked = false end
end |
The "KeyPreview" event may be running in VBScript (true, false).
But I am not sure if it is active on CE Lua.
I would like to see this if there is an example.
_________________
|
|
| Back to top |
|
 |
Razi Expert Cheater
Reputation: 1
Joined: 17 Jan 2018 Posts: 205
|
Posted: Sun Aug 09, 2020 10:37 am Post subject: |
|
|
I want to: convert boolean to value and value to boolean:
where, true = 1, false = 0:
| Code: | local value = readBytes(0x9E91B4) --value can be 1 or 0
UDF1.CECheckBox1.Checked = tostring(value)
UDF1.CECheckBox1.OnClick = function(sender)
local value = tonumber(UDF1.CECheckBox1.Checked)
writeBytes(0x9E91B4, value)
end |
but it does not work
|
|
| Back to top |
|
 |
ParkourPenguin I post too much
Reputation: 153
Joined: 06 Jul 2014 Posts: 4734
|
Posted: Sun Aug 09, 2020 10:54 am Post subject: |
|
|
Lua isn't C. It's intended 0 will evaluate to true like any other integer. You need to be explicit about it:
| Code: | something.checked = value ~= 0
value = something.checked and 1 or 0 |
_________________
I don't know where I'm going, but I'll figure it out when I get there. |
|
| Back to top |
|
 |
Razi Expert Cheater
Reputation: 1
Joined: 17 Jan 2018 Posts: 205
|
Posted: Sun Aug 09, 2020 11:52 am Post subject: |
|
|
| ParkourPenguin wrote: | | Code: | something.checked = value ~= 0
value = something.checked and 1 or 0 |
|
Thank you, this is what was needed.
Found three ways to do it:
1)
| Code: | --read
local value1 = readBytes(0x970AF2)
UDF1.CECheckBox1.Checked = value1 ~= 0
--write
UDF1.CECheckBox1.OnClick = function(sender)
local value = UDF1.CECheckBox1.Checked and 1 or 0
writeBytes(0x970AF2, value)
end |
2)
| Code: | function number_to_boolean(value1)
return value1 ~= 0
end
function boolean_to_number(value2)
return value2 and 1 or 0
end
--read
local value1 = readBytes(0x970AF2)
UDF1.CECheckBox1.Checked = number_to_boolean(value1)
--write
UDF1.CECheckBox1.OnClick = function(sender)
local value = boolean_to_number(UDF1.CECheckBox1.Checked)
writeBytes(0x970AF2, value)
end |
3)
| Code: | boolean_to_number_tbl={[true]=1, [false]=0}
number_to_boolean_tbl={[1]=true, [0]=false}
--read
local value1 = readBytes(0x970AF2)
UDF1.CECheckBox1.Checked = number_to_boolean_tbl[value1]
--write
UDF1.CECheckBox1.OnClick = function(sender)
local value = boolean_to_number_tbl[UDF1.CECheckBox1.Checked]
writeBytes(0x970AF2, value) |
|
|
| Back to top |
|
 |
|