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 


Button click
Goto page 1, 2  Next
 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
bknight2602
Grandmaster Cheater
Reputation: 0

Joined: 08 Oct 2012
Posts: 586

PostPosted: Fri Feb 25, 2022 11:08 am    Post subject: Button click Reply with quote

I have an editbox and button on a table.
I have entered an button on click function, but it is not working.
Code:

function CEButton1Click(sender)--exp
         if tonumber(CheatPanel_CEEdit1.Text) then
            local value = tonumber(CheatPanel_CEEdit1.Text);
         end
            expvalue = value;
            print("The experience entered " .. expvalue);
end--function CEButton1Click(sender)--exp

I receive an error "Error:attempt to call a nil value"
Is it not possible to call across different objects?
How would I code so that the text can be used in a calculation?
Back to top
View user's profile Send private message Yahoo Messenger
TheyCallMeTim13
Wiki Contributor
Reputation: 51

Joined: 24 Feb 2017
Posts: 976
Location: Pluto

PostPosted: Fri Feb 25, 2022 11:16 am    Post subject: Reply with quote

Does it give a line number, or the name of what you're trying to call? Because the only things you call here are tonumber and print, so unless you have set one of those to nil I don't think the issues is here.
_________________
Back to top
View user's profile Send private message Visit poster's website
bknight2602
Grandmaster Cheater
Reputation: 0

Joined: 08 Oct 2012
Posts: 586

PostPosted: Fri Feb 25, 2022 11:29 am    Post subject: Reply with quote

No line number given. The only output is precisely what I quoted.
"Error:attempt to call a nil value"
Back to top
View user's profile Send private message Yahoo Messenger
AylinCE
Grandmaster Cheater Supreme
Reputation: 37

Joined: 16 Feb 2017
Posts: 1531

PostPosted: Fri Feb 25, 2022 11:37 am    Post subject: Reply with quote

"CheatPanel_CEEdit1" ?
Trainer name: "CheatPanel"
Edit name: "CEEdit1"
Object: "CheatPanel.CEEdit1"

Code:
local expvalue=0 --or string "" --If you want to use the value in a different field, define it outside first.

function CEButton1Click(sender)--exp
         if CheatPanel.CEEdit1.Text~="" then
            expvalue = tonumber(CheatPanel.CEEdit1.Text);
            --expvalue = value;
            print("The experience entered " .. expvalue);
            else
            print("The corresponding box appears empty!");
         end
end

_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
bknight2602
Grandmaster Cheater
Reputation: 0

Joined: 08 Oct 2012
Posts: 586

PostPosted: Fri Feb 25, 2022 12:09 pm    Post subject: Reply with quote

Code:

local expvalue=0 --or string "" --If you want to use the value in a different field, define it outside first.
function CEButton1Click(sender)--exp
         if CheatPanel.CEEdit1.Text~="" then
            expvalue = tonumber(CheatPanel.CEEdit1.Text);
            --expvalue = value;
            print("The experience entered " .. expvalue);
            else
            print("The corresponding box appears empty!");
         end
end--function CEButton1Click(sender)--exp

I don't understand your initial comment "local expvalue=0 --or string "" --If you want to use the value in a different field, define it outside first." The number in the edit box will only be used to determine a value used in a memscan and will then be set to nil. However, this code has the same error listed.
Back to top
View user's profile Send private message Yahoo Messenger
Dark Byte
Site Admin
Reputation: 470

Joined: 09 May 2003
Posts: 25812
Location: The netherlands

PostPosted: Fri Feb 25, 2022 1:04 pm    Post subject: Reply with quote

the error is likely somewhere else
_________________
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
AylinCE
Grandmaster Cheater Supreme
Reputation: 37

Joined: 16 Feb 2017
Posts: 1531

PostPosted: Fri Feb 25, 2022 1:44 pm    Post subject: Reply with quote

If you're not going to use the "expvalue" outside of Button click, of course, the situation changes.
But if the code I suggested still gives an error, try the code below.
If there is no other code in Button1, delete Button1 and Edit1 and try to create it again.

Code:
 CheatPanel.CEButton1.OnClick=function()
         if CheatPanel.CEEdit1.Text~="" then
            print("The experience entered " .. tonumber(CheatPanel.CEEdit1.Text));
            else
            print("The corresponding box appears empty!");
         end
end

_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
bknight2602
Grandmaster Cheater
Reputation: 0

Joined: 08 Oct 2012
Posts: 586

PostPosted: Fri Feb 25, 2022 4:24 pm    Post subject: Reply with quote

it so happens that I do have another pair of them and
Code:

CheatPanel.CEButton2.OnClick=function()
         if CheatPanel.CEEdit2.Text~="" then
            print("The experience entered " .. tonumber(CheatPanel.CEEdit2.Text));
            else
            print("The corresponding box appears empty!");
         end
end

Has the same error message.

I am getting frustrated with this table. Here is almost identical code fom an old table and I don't get errors. Is there a maximum number of records?
Code:

function CEButton1Click(sender)
expvalue = tonumber(control_getCaption(CheatPanel_CEEdit1))
print('Experience = '..expvalue)
  if expvalue ~= nil and goldvalue ~= nil and heroname ~= nil then
    RecalculateAddresses()
  end
end

function CEButton2Click(sender)
goldvalue = tonumber(control_getCaption(CheatPanel_CEEdit2))
print('Gold = '..goldvalue)
  if expvalue ~= nil and goldvalue ~= nil and heroname ~= nil then
    RecalculateAddresses()
  end
end
Back to top
View user's profile Send private message Yahoo Messenger
Dark Byte
Site Admin
Reputation: 470

Joined: 09 May 2003
Posts: 25812
Location: The netherlands

PostPosted: Fri Feb 25, 2022 5:32 pm    Post subject: Reply with quote

unless print or tonumber have been replaced by nil, that code isn't the cause of the error

this error means that something did a name(xxx) and name is nil

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

Joined: 08 Oct 2012
Posts: 586

PostPosted: Fri Feb 25, 2022 8:04 pm    Post subject: Reply with quote

expvalue = tonumber(CheatPanel.CEEdit1.Text)
expvalue = tonumber(control_getCaption(CheatPanel_CEEdit1))

Neither of these code line sets expvalue but both result in Error:attempt to call a nil value

What should the line be?



2022-02-25_20-03-34.png
 Description:
 Filesize:  44.95 KB
 Viewed:  4749 Time(s)

2022-02-25_20-03-34.png


Back to top
View user's profile Send private message Yahoo Messenger
TheyCallMeTim13
Wiki Contributor
Reputation: 51

Joined: 24 Feb 2017
Posts: 976
Location: Pluto

PostPosted: Fri Feb 25, 2022 9:33 pm    Post subject: Reply with quote

If this is true, then somewhere in your code you have set tonumber to nil; i.e. "tonumber = <something that is nil>". You'll have to find where you're doing that and fix the code.
_________________
Back to top
View user's profile Send private message Visit poster's website
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1668

PostPosted: Fri Feb 25, 2022 10:52 pm    Post subject: Reply with quote

I agree with @TheyCallMeTim13. ...somewhere in your code you have set tonumber to nil; i.e. "tonumber = <something that is nil>" or objects name not identified or defined.

Tried by code not Form Designer, it's work fine

Code:
if f then f.destroy() end
f = createForm()
edt = createEdit(f)
edt.Text = 10
btn = createButton(f)
btn.Top = edt.top + edt.height + 5
btn.left = edt.left
btn.caption = 'click me'

function btnclick()
 local val1 = edt.Text
 local val2  = 10
 if tonumber(val1) == nil then print("ERROR...!!") else  print(val1 + val2) end
end

f.show()
btn.onClick = btnclick

_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
Back to top
View user's profile Send private message
bknight2602
Grandmaster Cheater
Reputation: 0

Joined: 08 Oct 2012
Posts: 586

PostPosted: Sat Feb 26, 2022 9:51 am    Post subject: Reply with quote

TheyCallMeTim13 wrote:
If this is true, then somewhere in your code you have set tonumber to nil; i.e. "tonumber = <something that is nil>". You'll have to find where you're doing that and fix the code.


I would love to find something tonumber<something that is nil>
However in this instance there are exactly four occurrences of tonumber. I won't show the whole code of ~2k lines, but I will list the tonumbers and copy them here not i a code block.

1724:memrec2 = tonumber(memrec1, 16);
1728:memrec4 = tonumber(memrec3, 16);
1797:expvalue = tonumber(control_getCaption(CheatPanel_CEEdit1))-- This is within the CEButtonClick1 currently under discussion.
1805:goldvalue = tonumber(control_getCaption(CheatPanel_CEEdit2)) This is with CEButtonClick2 which has a similar code as 1, but different var. These are the current saved lines but I have varied 1797 to tonumber(CheatPanel.CEEdit1.Text) which has given the same error message.

There are many instances of nil. These are code Ines 1-22
Code:

function FormShow(sender)
form_show(CheatPanel);
t = createTimer(nil, true);
timer_onTimer(t, MaxHP)
timer_setInterval(t, 500)--checks every 500 milliseconds
timer_setEnabled(t, false)
print("God Mode is not enabled")
--
tde = createTimer(nil, true)
timer_onTimer(tde, DisplayEdits)
timer_setInterval(tde, 1000)
timer_setEnabled(tde, false)
--
tstop = createTimer(nil)
tstop.Interval = 1000
tstop.onTimer = function(tstop)
                  if(getOpenedProcessID() ~= 0)
                    and (readInteger("kernel32.dll") == nil) then
                      closeCE()
                  end
                end
tstop.Enabled = true

There are many more, most of which check to see if a var is nil, and a few setting var to nil at the end of several functions.
Back to top
View user's profile Send private message Yahoo Messenger
TheyCallMeTim13
Wiki Contributor
Reputation: 51

Joined: 24 Feb 2017
Posts: 976
Location: Pluto

PostPosted: Sat Feb 26, 2022 10:11 am    Post subject: Reply with quote

Paste this code in the lua engine window, hit execute and see if you get an error.
Code:
expvalue = tonumber(CheatPanel.CEEdit1.Text)

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

Joined: 08 Oct 2012
Posts: 586

PostPosted: Sat Feb 26, 2022 10:47 am    Post subject: Reply with quote

As the output shows nothing but doesn't give an error. The output has an error in the first instance to show the window the other two are hitting the execute button.
Now I show the edit window to display that both edits were created with nothing in the seText box. The image displays 278 in the edit box and 278 in the edit portion of the edit box.


ETA: I added twelve exp addresses to the blank table half moved to a group header the other 6 were stand alone, then I searched for and displayed an address for 1st gold. I saved the table and re-opened.
Code:

function FormShow(sender)
form_show(CheatPanel);
t = createTimer(nil, true);
timer_onTimer(t, MaxHP)
timer_setInterval(t, 500)--checks every 500 milliseconds
timer_setEnabled(t, false)
print("God Mode is not enabled")

ChealPanel was displayed but the print statement wasn't executed. Perhaps the one o the timers does have an error.



2022-02-26_10-38-30.png
 Description:
 Filesize:  380.66 KB
 Viewed:  4676 Time(s)

2022-02-26_10-38-30.png


Back to top
View user's profile Send private message Yahoo 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
Goto page 1, 2  Next
Page 1 of 2

 
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