View previous topic :: View next topic |
Author |
Message |
bknight2602 Grandmaster Cheater Reputation: 0
Joined: 08 Oct 2012 Posts: 577
|
Posted: Sun Dec 04, 2016 9:52 am Post subject: EditBox syntax |
|
|
I have this code in my table.
Code: |
self.set_exp1_value = createButton(self.form);
self.set_exp1_value.Caption = 'Enter Hero 1 Exp';
self.set_exp1_value.height = 35;
self.set_exp1_value.left = 104;
self.set_exp1_value.top = 7;
self.set_exp1_value.width = 150;
self.set_exp1_value.onClick = function (sender)
local value = self.exp1_value.Text;
if value then
exp1_value = tonumber(value);
print("The experience of the 1st member entered is " .. exp1_value);
if exp1_value and exp2_value then
RecalculateAddresses()
end
end
end
self.set_exp2_value = createButton(self.form);
self.set_exp2_value.Caption = 'Enter Hero 2 Exp';
self.set_exp2_value.height = 35;
self.set_exp2_value.left = 104;
self.set_exp2_value.top = 52;
self.set_exp2_value.width = 150;
self.set_exp2_value.onClick = function (sender)
local value = self.exp2_value.Text;
if value then
exp2_value = tonumber(value);
print("The experience of the 2nd member entered is " .. exp2_value);
if exp1_value and exp2_value then
RecalculateAddresses()
end
end
end
|
And then further down the code in sub RecalculateAddresses()
Code: |
trainer.set_exp1_value.Text = ""
trainer.set_exp2_value.Text = ""
|
Now the edit boxes work and the sub is called and executes. The only procedures that aren't executed are the last two lines listed above.
What is the correct syntax for any of the lines? |
|
Back to top |
|
|
mgr.inz.Player I post too much Reputation: 218
Joined: 07 Nov 2008 Posts: 4438 Location: W kraju nad Wisla. UTC+01:00
|
Posted: Sun Dec 04, 2016 10:13 am Post subject: |
|
|
After quick reading of your code I see that
set_exp1_value is a button
set_exp2_value is a button
exp1_value is an editbox
exp2_value is an editbox
So you should use
Code: | trainer.exp1_value.Text = ""
trainer.exp2_value.Text = "" |
I suggest using better names in the future. Something like:
btnSetExp1 for a button
editboxExp1 for an editbox _________________
|
|
Back to top |
|
|
bknight2602 Grandmaster Cheater Reputation: 0
Joined: 08 Oct 2012 Posts: 577
|
Posted: Sun Dec 04, 2016 10:24 am Post subject: |
|
|
mgr.inz.Player wrote: | After quick reading of your code I see that
set_exp1_value is a button
set_exp2_value is a button
exp1_value is an editbox
exp2_value is an editbox |
Not really The button is beside the edit box and is used to captured the value from the edit box. Quote: |
...
I suggest using better names in the future. Something like:
btnSetExp1 for a button
editboxExp1 for an editbox |
Sounds good I'll put that on the bucket list. |
|
Back to top |
|
|
mgr.inz.Player I post too much Reputation: 218
Joined: 07 Nov 2008 Posts: 4438 Location: W kraju nad Wisla. UTC+01:00
|
Posted: Sun Dec 04, 2016 10:29 am Post subject: |
|
|
bknight2602 wrote: | Not really The button is beside the edit box and is used to captured the value from the edit box. |
Read my post again. Carefully.
Straight from your code:
Code: | self.set_exp1_value = createButton(self.form); |
So, set_exp1_value is a button.
Code: | local value = self.exp1_value.Text |
So, exp1_value is an editbox. _________________
|
|
Back to top |
|
|
bknight2602 Grandmaster Cheater Reputation: 0
Joined: 08 Oct 2012 Posts: 577
|
Posted: Sun Dec 04, 2016 10:46 am Post subject: |
|
|
Maybe the naming is the issue, more towards the beginning.
Code: |
self.exp_value_1st = createEdit(self.value_panel1);
self.exp_value_1st.top = 6;
self.exp_value_1st.left = 6;
self.exp_value_1st.Width = 80;
self.exp_value_1st.Height = 23;
-- The line below this, allows only numbers or the - number to be entered.
setMethodProperty(self.exp_value_1st, "OnKeyPress", function (sender, key) local keynr = string.byte(key); if (keynr~=8) and (keynr~=45) and (keynr~=13) and ((keynr<48) or (keynr>57)) then key=nil; end if (keynr==13 and not(sender.Caption == nil or sender.Caption == '')) then key = nil; self.set_exp_value_1st.onClick(); end return key; end)
--
self.exp_value_2nd = createEdit(self.value_panel2);
self.exp_value_2nd.top = 6;
self.exp_value_2nd.left = 6;
self.exp_value_2nd.Width = 80;
self.exp_value_2nd.Height = 23;
-- The line below this, allows only numbers or the - number to be entered.
setMethodProperty(self.exp_value_2nd, "OnKeyPress", function (sender, key) local keynr = string.byte(key); if (keynr~=8) and (keynr~=45) and (keynr~=13) and ((keynr<48) or (keynr>57)) then key=nil; end if (keynr==13 and not(sender.Caption == nil or sender.Caption == '')) then key = nil; self.set_exp_value_2nd.onClick(); end return key; end) |
These were intended to be the names, however IIRC (maybe over two years ago) I had to use local value = self.exp1_value.Text; to allow the recalculation to be executed. |
|
Back to top |
|
|
mgr.inz.Player I post too much Reputation: 218
Joined: 07 Nov 2008 Posts: 4438 Location: W kraju nad Wisla. UTC+01:00
|
Posted: Sun Dec 04, 2016 11:09 am Post subject: |
|
|
I recommend starting from the scratch. With proper form controls naming. And proper variable naming.
Also, I recommend using "form designer". _________________
|
|
Back to top |
|
|
bknight2602 Grandmaster Cheater Reputation: 0
Joined: 08 Oct 2012 Posts: 577
|
Posted: Mon Dec 05, 2016 4:13 pm Post subject: |
|
|
mgr.inz.Player wrote: | I recommend starting from the scratch. With proper form controls naming. And proper variable naming.
Also, I recommend using "form designer". |
That's a tall order. Where do I locate the "form designer"? |
|
Back to top |
|
|
mgr.inz.Player I post too much Reputation: 218
Joined: 07 Nov 2008 Posts: 4438 Location: W kraju nad Wisla. UTC+01:00
|
|
Back to top |
|
|
bknight2602 Grandmaster Cheater Reputation: 0
Joined: 08 Oct 2012 Posts: 577
|
Posted: Mon Dec 05, 2016 5:11 pm Post subject: |
|
|
Old style coding which you guys have been coaxing me out of. I'm not sure this is the correct forward path for me, but thank for the reply. |
|
Back to top |
|
|
|