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 


Can't find code error

 
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: Wed May 22, 2019 8:14 am    Post subject: Can't find code error Reply with quote

The following codes have an error:
Code:

   self.gm_cb = createCheckBox(self.form);
   self.gm_cb.Caption = 'God Mode';
   self.gm_cb.Height = 20;
   self.gm_cb.Left = 270;
   self.gm_cb.Width = 75;
   self.gm_cb.Top = 7;
   self.gm_cb.onClick =   function (sender)
                           if sender.Checked then
                              self.t.Enabled = true;
                              print("God mode is enabled")
                           else
                              self.t.Enabled = false;
                              print("God mode is not enabled")
                           end--if sender.Checked then
                          end--function (sender)
   self.mm_cb = createCheckBox(self.form);
   self.mm_cb.Caption = 'Constant Magic';
   self.mm_cb.Height = 20;
   self.mm_cb.Left = 270;
   self.mm_cb.Width = 75;
   self.mm_cb.Top = 67;
   self.mm_cb.onClick =   function (sender)
                           if sender.Checked then
                              self.tm.Enabled = true;
                              print("Constant Magic is enabled")
                           else
                              self.tm.Enabled = false;
                              print("Constant Magic is not enabled")
                           end--if sender.Checked then
                          end--function (sender)
   self.mh_cb = createCheckBox(self.form);
   self.mh_cb.Caption = 'Constant Health';
   self.mh_cb.Height = 20;
   self.mh_cb.Left = 270;
   self.mh_cb.Width = 75;
   self.mh_cb.Top = 37;
   self.mh_cb.onClick =   function (sender)
                           if sender.Checked then
                              self.th.Enabled = true;
                              print("Constant Health is enabled")
                           else
                              self.th.Enabled = false;
                              print("Constant Health is not enabled")
                           end--if sender.Checked then
                          end--function (sender)

both th and tm are timers created prior to each check box.
Now the first executes fine, and a check box is created the next two in order of their appearance, but not next to each other are not created, there is an error opening the table with following notion:
Error:"??" is an invalid float.
Now the screwy part, if I select the execute script after receiving the error message, everything opens properly, no further error messages
Back to top
View user's profile Send private message Yahoo Messenger
AylinCE
Grandmaster Cheater Supreme
Reputation: 37

Joined: 16 Feb 2017
Posts: 1533

PostPosted: Wed May 22, 2019 9:10 am    Post subject: Reply with quote

There are no errors after the following fix.
Table opens.

Code:
local self_form = createForm(true)
   self_form.Width = 420;

   local self_gm_cb = createCheckBox(self_form);
   self_gm_cb.Caption = 'God Mode';
   self_gm_cb.Height = 20;
   self_gm_cb.Left = 270;
   self_gm_cb.Width = 75;
   self_gm_cb.Top = 7;
   self_gm_cb.onClick =   function (sender)
                           if sender.Checked then --or if self_gm_cb.Checked==true then
                              self.t.Enabled = true;
                              print("God mode is enabled")
                           else
                              self.t.Enabled = false;
                              print("God mode is not enabled")
                           end--if sender.Checked then
                          end--function (sender)

_________________
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: Wed May 22, 2019 11:34 am    Post subject: Reply with quote

I guess I wasn't concise enough in the OP, the code for the check box you have altered works, the error lies in one or both of the last ones, I believe. The God Mode check box is created and the other two are not when the table opens.

ETA I noticed you alter self.form to self_form, I presume you feel self_form is more correct?
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: Wed May 22, 2019 1:40 pm    Post subject: Reply with quote

This doesn't give any errors. Error must be somewhere else. Are you creating the "self" structure globally, it's really meant to be an object function parameter.

Code:
self = {}
self.form = createForm(true)
   self.form.Width = 420;

 self.gm_cb = createCheckBox(self.form);
   self.gm_cb.Caption = 'God Mode';
   self.gm_cb.Height = 20;
   self.gm_cb.Left = 270;
   self.gm_cb.Width = 75;
   self.gm_cb.Top = 7;
   self.gm_cb.onClick =   function (sender)
                           if sender.Checked then
                              self.t.Enabled = true;
                              print("God mode is enabled")
                           else
                              self.t.Enabled = false;
                              print("God mode is not enabled")
                           end--if sender.Checked then
                          end--function (sender)
   self.mm_cb = createCheckBox(self.form);
   self.mm_cb.Caption = 'Constant Magic';
   self.mm_cb.Height = 20;
   self.mm_cb.Left = 270;
   self.mm_cb.Width = 75;
   self.mm_cb.Top = 67;
   self.mm_cb.onClick =   function (sender)
                           if sender.Checked then
                              self.tm.Enabled = true;
                              print("Constant Magic is enabled")
                           else
                              self.tm.Enabled = false;
                              print("Constant Magic is not enabled")
                           end--if sender.Checked then
                          end--function (sender)
   self.mh_cb = createCheckBox(self.form);
   self.mh_cb.Caption = 'Constant Health';
   self.mh_cb.Height = 20;
   self.mh_cb.Left = 270;
   self.mh_cb.Width = 75;
   self.mh_cb.Top = 37;
   self.mh_cb.onClick =   function (sender)
                           if sender.Checked then
                              self.th.Enabled = true;
                              print("Constant Health is enabled")
                           else
                              self.th.Enabled = false;
                              print("Constant Health is not enabled")
                           end--if sender.Checked then
                          end--function (sender)





I'd change that "self" to something else so it doesn't conflict with other functions:
Code:
MyTrainer = {}
MyTrainer.form = createForm(true)
   MyTrainer.form.Width = 420;

 MyTrainer.gm_cb = createCheckBox(Trainer.form);
   MyTrainer.gm_cb.Caption = 'God Mode';
   MyTrainer.gm_cb.Height = 20;
   MyTrainer.gm_cb.Left = 270;
   MyTrainer.gm_cb.Width = 75;
   MyTrainer.gm_cb.Top = 7;
   MyTrainer.gm_cb.onClick =   function (sender)
                           if sender.Checked then
                              MyTrainer.t.Enabled = true;
                              print("God mode is enabled")
                           else
                              MyTrainer.t.Enabled = false;
                              print("God mode is not enabled")
                           end--if sender.Checked then
                          end--function (sender)
   MyTrainer.mm_cb = createCheckBox(Trainer.form);
   MyTrainer.mm_cb.Caption = 'Constant Magic';
   MyTrainer.mm_cb.Height = 20;
   MyTrainer.mm_cb.Left = 270;
   MyTrainer.mm_cb.Width = 75;
   MyTrainer.mm_cb.Top = 67;
   MyTrainer.mm_cb.onClick =   function (sender)
                           if sender.Checked then
                              MyTrainer.tm.Enabled = true;
                              print("Constant Magic is enabled")
                           else
                              MyTrainer.tm.Enabled = false;
                              print("Constant Magic is not enabled")
                           end--if sender.Checked then
                          end--function (sender)
   MyTrainer.mh_cb = createCheckBox(Trainer.form);
   MyTrainer.mh_cb.Caption = 'Constant Health';
   MyTrainer.mh_cb.Height = 20;
   MyTrainer.mh_cb.Left = 270;
   MyTrainer.mh_cb.Width = 75;
   MyTrainer.mh_cb.Top = 37;
   MyTrainer.mh_cb.onClick =   function (sender)
                           if sender.Checked then
                              MyTrainer.th.Enabled = true;
                              print("Constant Health is enabled")
                           else
                              MyTrainer.th.Enabled = false;
                              print("Constant Health is not enabled")
                           end--if sender.Checked then
                          end--function (sender)

_________________
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: Wed May 22, 2019 2:00 pm    Post subject: Reply with quote

'self' is Lua object oriented paremeter (OOP).

In Lua, if you have a function as a property of a table, and you use a colon ":" instead of a period "." to reference the function, it will automatically pass the table in as the first argument!

So, self.gm_cb is different with self_gm_cb

See, @TheyCallMeTim, tutorial above.

_________________
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: Wed May 22, 2019 8:19 pm    Post subject: Reply with quote

TheyCallMeTim13 wrote:
This doesn't give any errors. Error must be somewhere else. Are you creating the "self" structure globally, it's really meant to be an object function parameter.

Code:
self = {}
self.form = createForm(true)
   self.form.Width = 420;

 self.gm_cb = createCheckBox(self.form);
   self.gm_cb.Caption = 'God Mode';
   self.gm_cb.Height = 20;
   self.gm_cb.Left = 270;
   self.gm_cb.Width = 75;
   self.gm_cb.Top = 7;
   self.gm_cb.onClick =   function (sender)
                           if sender.Checked then
                              self.t.Enabled = true;
                              print("God mode is enabled")
                           else
                              self.t.Enabled = false;
                              print("God mode is not enabled")
                           end--if sender.Checked then
                          end--function (sender)
   self.mm_cb = createCheckBox(self.form);
   self.mm_cb.Caption = 'Constant Magic';
   self.mm_cb.Height = 20;
   self.mm_cb.Left = 270;
   self.mm_cb.Width = 75;
   self.mm_cb.Top = 67;
   self.mm_cb.onClick =   function (sender)
                           if sender.Checked then
                              self.tm.Enabled = true;
                              print("Constant Magic is enabled")
                           else
                              self.tm.Enabled = false;
                              print("Constant Magic is not enabled")
                           end--if sender.Checked then
                          end--function (sender)
   self.mh_cb = createCheckBox(self.form);
   self.mh_cb.Caption = 'Constant Health';
   self.mh_cb.Height = 20;
   self.mh_cb.Left = 270;
   self.mh_cb.Width = 75;
   self.mh_cb.Top = 37;
   self.mh_cb.onClick =   function (sender)
                           if sender.Checked then
                              self.th.Enabled = true;
                              print("Constant Health is enabled")
                           else
                              self.th.Enabled = false;
                              print("Constant Health is not enabled")
                           end--if sender.Checked then
                          end--function (sender)





I'd change that "self" to something else so it doesn't conflict with other functions:
Code:
MyTrainer = {}
MyTrainer.form = createForm(true)
   MyTrainer.form.Width = 420;

 MyTrainer.gm_cb = createCheckBox(Trainer.form);
   MyTrainer.gm_cb.Caption = 'God Mode';
   MyTrainer.gm_cb.Height = 20;
   MyTrainer.gm_cb.Left = 270;
   MyTrainer.gm_cb.Width = 75;
   MyTrainer.gm_cb.Top = 7;
   MyTrainer.gm_cb.onClick =   function (sender)
                           if sender.Checked then
                              MyTrainer.t.Enabled = true;
                              print("God mode is enabled")
                           else
                              MyTrainer.t.Enabled = false;
                              print("God mode is not enabled")
                           end--if sender.Checked then
                          end--function (sender)
   MyTrainer.mm_cb = createCheckBox(Trainer.form);
   MyTrainer.mm_cb.Caption = 'Constant Magic';
   MyTrainer.mm_cb.Height = 20;
   MyTrainer.mm_cb.Left = 270;
   MyTrainer.mm_cb.Width = 75;
   MyTrainer.mm_cb.Top = 67;
   MyTrainer.mm_cb.onClick =   function (sender)
                           if sender.Checked then
                              MyTrainer.tm.Enabled = true;
                              print("Constant Magic is enabled")
                           else
                              MyTrainer.tm.Enabled = false;
                              print("Constant Magic is not enabled")
                           end--if sender.Checked then
                          end--function (sender)
   MyTrainer.mh_cb = createCheckBox(Trainer.form);
   MyTrainer.mh_cb.Caption = 'Constant Health';
   MyTrainer.mh_cb.Height = 20;
   MyTrainer.mh_cb.Left = 270;
   MyTrainer.mh_cb.Width = 75;
   MyTrainer.mh_cb.Top = 37;
   MyTrainer.mh_cb.onClick =   function (sender)
                           if sender.Checked then
                              MyTrainer.th.Enabled = true;
                              print("Constant Health is enabled")
                           else
                              MyTrainer.th.Enabled = false;
                              print("Constant Health is not enabled")
                           end--if sender.Checked then
                          end--function (sender)


All I can say it used to open with earlier versions, not the most current that I have, 6.6. I would have to change most of the codes to go from self to something else. As for the error, you may be exactly correct, however the self is used on all creations, assigning param. to those creations. And I have stated that after the error when opening, pushing the execute script without changing any code no errors are received. Same code has errors when opening but no errors when executing script? Strange.
Back to top
View user's profile Send private message Yahoo Messenger
bknight2602
Grandmaster Cheater
Reputation: 0

Joined: 08 Oct 2012
Posts: 586

PostPosted: Thu May 23, 2019 8:48 am    Post subject: Reply with quote

I just now opened the table with an earlier version (6.3) and no errors, perhaps this is an issue with 6.6. I guess I'll try 6.7(Cool.
Back to top
View user's profile Send private message Yahoo Messenger
daspamer
Grandmaster Cheater Supreme
Reputation: 54

Joined: 13 Sep 2011
Posts: 1588

PostPosted: Thu May 23, 2019 10:14 am    Post subject: Reply with quote

Add some print to find at which line the error happens, perhaps theres invisible chars.
Also recommend to set self to table at the top of the function (just in case);
Code:
function sometable.init(...)
   self = sometable;
   -- do whatever...
end

other than that we can't really help, as the script you've posted seems correct.

_________________
I'm rusty and getting older, help me re-learn lua.
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: Thu May 23, 2019 8:55 pm    Post subject: Reply with quote

DaSpamer wrote:
Add some print to find at which line the error happens, perhaps theres invisible chars.
Also recommend to set self to table at the top of the function (just in case);
Code:
function sometable.init(...)
   self = sometable;
   -- do whatever...
end

other than that we can't really help, as the script you've posted seems correct.


That is what was weird, the error only happened when opening, not when executing the script.
Code:
   self.form = createForm(false); -- self = trainer since it's a function inside of a table...
   setProperty(self.form , "BiDiMode", "bdLeftToRight");
   self.form.Caption = 'Cheat Panel';
   self.form.Width = 400;
   self.form.Height = 360;
   self.form.Left = 900;
   self.form.Top =5;

Look familiar?
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: Thu May 23, 2019 9:11 pm    Post subject: Reply with quote

The code works for me when opening a saved table.

If the "self" isn't a class you created and this code isn't inside a function, you need to change the naming as it's probably getting changed or a function which uses "self" isn't getting the right object.

That or it's a script in your "autorun" folder.

Maybe posting the full script would help?

_________________
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 May 24, 2019 10:41 am    Post subject: Reply with quote

The full code is about 5K long, and has parts written in the "old" style before the object declarations. Besides the error occurred at initial load.
As I indicated it opened in 6.3 without errors. I downloaded 6.8.3 yesterday and no errors on load, so I suspect an internal issue with 6.6.
Thanks
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
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