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 


[HELP]How Lua Script Button Function get this GUI At Name
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
acgofficial
Cheater
Reputation: 0

Joined: 14 Aug 2018
Posts: 36

PostPosted: Fri Aug 17, 2018 4:19 am    Post subject: [HELP]How Lua Script Button Function get this GUI At Name Reply with quote

I don't know how to get to the corresponding function of its object name.

I Sorry,My English ability is poor, maybe you can't see me, use the translation. Shocked
Back to top
View user's profile Send private message Send e-mail
Lynxz Gaming
Expert Cheater
Reputation: 4

Joined: 01 Jul 2017
Posts: 208
Location: help

PostPosted: Fri Aug 17, 2018 5:07 am    Post subject: Re: [HELP]How Lua Script Button Function get this GUI At Nam Reply with quote

Go to the button event then click the 3 dots button then you will automaticly at button function

im sorry too if im misunderstanding, my english is poor too xD

_________________
my english is bad
discord : rynx#9828
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
acgofficial
Cheater
Reputation: 0

Joined: 14 Aug 2018
Posts: 36

PostPosted: Fri Aug 17, 2018 8:13 am    Post subject: I have a question Reply with quote

How to use "Lua" link to open a web site.
Back to top
View user's profile Send private message Send e-mail
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1668

PostPosted: Fri Aug 17, 2018 8:28 am    Post subject: Reply with quote

Or Try using lua script :


Code:
--- create a form
MyForm = createForm()

--- create a button (as a object) inside that form
MyButton = createButton(MyForm) -- object name for button = MyButton
MyButton.Left = 10
MyButton.Top = 10
MyButton.Width = 100
MyButton.Height = 40
MyButton.Caption = 'Open Link'  -- Put text on the button

--- create a function which will bne execute by MyButton Click
--- provide a correct web site link
function openWebsite()
 shellExecute('https://forum.cheatengine.org/viewtopic.php?t=608340')
end

--- Execute that function with MyButton Click
MyButton.onClick = openWebsite

--- show MyForm
MyForm.show()

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

Joined: 14 Aug 2018
Posts: 36

PostPosted: Fri Aug 17, 2018 9:28 am    Post subject: I have a problem Reply with quote

Corroder wrote:
Or Try using lua script :


Code:
--- create a form
MyForm = createForm()

--- create a button (as a object) inside that form
MyButton = createButton(MyForm) -- object name for button = MyButton
MyButton.Left = 10
MyButton.Top = 10
MyButton.Width = 100
MyButton.Height = 40
MyButton.Caption = 'Open Link'  -- Put text on the button

--- create a function which will bne execute by MyButton Click
--- provide a correct web site link
function openWebsite()
 shellExecute('https://forum.cheatengine.org/viewtopic.php?t=608340')
end

--- Execute that function with MyButton Click
MyButton.onClick = openWebsite

--- show MyForm
MyForm.show()


Shocked Why can't open the link Write “OpenUrl”或者"LoadUrl"?
How do I get to add the function of "Events"Script "function()"
Read Object their own name?

I want use <Script"switch"> to the analysis, it's so to save time, the code also look clean and tidy.
Back to top
View user's profile Send private message Send e-mail
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1668

PostPosted: Fri Aug 17, 2018 6:46 pm    Post subject: Reply with quote

Event handler, see this :

https://forum.cheatengine.org/viewtopic.php?t=607338&sid=1363b273b26f6c288fd5b6e35a5fdf20

and also this :

https://wiki.cheatengine.org/index.php?title=Tutorial:LuaFormGUI

Generally to open a web site in cheat engine lua, we use :

shellExecute('web site link address')

and to access internet connection, use : getInternet()

Sorry, not sure full understand what you want.

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

Joined: 14 Aug 2018
Posts: 36

PostPosted: Fri Aug 17, 2018 7:27 pm    Post subject: To help me Reply with quote

Corroder wrote:
Event handler, see this :
Sorry, not sure full understand what you want.


I just want to know what method is...Can you look at the code I wrote, you should understand what I mean.

//First of all,Button All Component.
//Look Menu "Events",The onClick Add YouOnClickButton()

//Script
function YouOnClickButton()
switch(this.name)
case "LocalHPButton":
print("Read Button,The self is LocalHPButton")
break;
case "LocalMpButton":
print("Read Button,The self is LocalMpButton")
break;
case "MaxHpButton":
print("Read Button,The self is MaxHpButton")
break;
case "MaxMpButton":
print("Read Button,The self is MaxMpButton")
break;
end


Surprised How can I to judge?
Back to top
View user's profile Send private message Send e-mail
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1668

PostPosted: Sat Aug 18, 2018 7:02 am    Post subject: Reply with quote

Not sure, maybe something lilke this ?

Code:
function YouOnClickButton(sender)
 a = sender.getName()
 if a == 'CEButton1' then
 print(a..' is LocalHPButton')
 end
 if a == 'CEButton2' then
 print(a..' is LocalMpButton')
 end
end

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

Joined: 09 Aug 2013
Posts: 1091

PostPosted: Sat Aug 18, 2018 9:31 am    Post subject: Reply with quote

Code:
function buttonPrintNameHander(button)
  local nameInCode = button.Name
  local textUserSees = button.Caption
  print("Read Button,The self is ", nameInCode, ' / ', textUserSees)
end
-- set all CE buttons that print name to have buttonPrintNameHander as click event

If you wanted each button to open a url then you could do something like
Code:
local urls = {'www.google.com', 'whatever.net'}
function buttonOpenURLHander(button)
  shellExecute(urls[button.Tag])
end
--[[
set all CE buttons that open url to have buttonOpenURLHander as click event
and set the Tag property to be the index into the urls table
]]

If you wanted some to print the name and some to open a url then you could do something like
Code:
local urls = {'www.google.com', 'whatever.net'}
function buttonHander(button)
  if button.name:find('URL') then -- if name contains 'URL'
    -- could also use if button.Tag ~= 0, since no Tag needs to be set if no corresponding URL
    shellExecute(urls[button.Tag])
  else
    print('Clicked on ', button.Caption)
  end
end
--[[
set all CE buttons to have buttonHander as click event
and set the Tag property to be the index into the urls table
]]


It helps greatly if you can explain/show what exactly you want to do. Take a screen shot of your trainer and (if the names aren't unique open it in paint or whatever and give each button a number or something) then write what you want each to do (print a name, open a url, freeze/activate a memory record, etc.).

I rather doubt printing the button's name or caption is actually what you want, but as you can see there are several ways to do it. Check if the name == x and then printing x is a pretty bad way to do it when you could just print the name, similarly checking if the name is x and printing x+1 (eg. if name is Google use www.google.com) doesn't make sense when you could just use eg. 'www.'..name..'.com' or a lookup table to simplify the code.

But if each button is doing completely different things like one's printing the name, another a url, another showing an image, another toggling a mem rec, then you are pretty much reduced to that kind of if x then elseif y then ... checking, unless you create a unique event handler for each button that only handles that one button (which is what I'd personally recommend in that case).

_________________
https://github.com/FreeER/ has a few CE related repos
Back to top
View user's profile Send private message
acgofficial
Cheater
Reputation: 0

Joined: 14 Aug 2018
Posts: 36

PostPosted: Sat Aug 18, 2018 9:34 pm    Post subject: Reply with quote

Corroder wrote:
Not sure, maybe something lilke this ?

Code:
function YouOnClickButton(sender)
 a = sender.getName()
 if a == 'CEButton1' then
 print(a..' is LocalHPButton')
 end
 if a == 'CEButton2' then
 print(a..' is LocalMpButton')
 end
end


Yse,That's what I want to answer.

I don't know where I can find the Function (" sender "), with the help of CheatEngine help manual can't find the "sender" in the parameters of the Function.

The information about the "sender".
Could you please send me the url, I need to learn.

And...I have a question want to ask.
CheatEngine [Ctrl+Alt+S]Save "exe" Build File.exe
I don't know why didn't start it after not reaction.
But,I see Window the background Process "File.exe" presence of.
File.exe the GUI not Show...

And...At this time,I Save CheatEngine the project,In addition, CheatEngine always throws an exception "Division by zero"


Surprised I very thank you to help me so far.
And...@FreeER CheatEngine friend, thank you, help me.
Back to top
View user's profile Send private message Send e-mail
Lynxz Gaming
Expert Cheater
Reputation: 4

Joined: 01 Jul 2017
Posts: 208
Location: help

PostPosted: Sat Aug 18, 2018 10:07 pm    Post subject: Reply with quote

add this script at top
formname.visible = true
so its make the form visible

_________________
my english is bad
discord : rynx#9828
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
acgofficial
Cheater
Reputation: 0

Joined: 14 Aug 2018
Posts: 36

PostPosted: Sat Aug 18, 2018 11:05 pm    Post subject: Reply with quote

Lynxz Gaming wrote:
add this script at top
formname.visible = true
so its make the form visible

Shocked Hi,Nice to meet you.
Shocked I Sorry,Before I see you, just can't reply, no permissions.
You said this method I tried, still won't do.


Surprised emmmmm.....

Thanks, successful, saying: why do you want to add this code in the script

I think the Object Inspector Visble manually will be useful...

Why can't manually, no matter, I don't understand
Back to top
View user's profile Send private message Send e-mail
Lynxz Gaming
Expert Cheater
Reputation: 4

Joined: 01 Jul 2017
Posts: 208
Location: help

PostPosted: Sat Aug 18, 2018 11:27 pm    Post subject: Reply with quote

change 'formname' into your real form name

um if you have discord add me Lynxz Gaming#9443

_________________
my english is bad
discord : rynx#9828
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
FreeER
Grandmaster Cheater Supreme
Reputation: 53

Joined: 09 Aug 2013
Posts: 1091

PostPosted: Sun Aug 19, 2018 7:02 am    Post subject: Reply with quote

acgofficial wrote:
I don't know where I can find the Function (" sender "), with the help of CheatEngine help manual can't find the "sender" in the parameters of the Function
sender is just a parameter/argument name, the code that calls the event handler will pass the object it's calling the event for to the function. Eg. if you have the event set on buttons called Button1, Button2, and Button3, when you click on Button1 then Button1 will be passed to the function as sender and when you click on Button2 then that will be passed etc. You can name it whatever you want, the event generator in the object inspector always uses sender but in my previous examples I used eg. function buttonHander(button).

No real ideas about the GUI not appearing...other than what Lynx mentioned, making sure visible is set / calling .show()

_________________
https://github.com/FreeER/ has a few CE related repos
Back to top
View user's profile Send private message
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1668

PostPosted: Sun Aug 19, 2018 6:59 pm    Post subject: Reply with quote

Quote:
CheatEngine [Ctrl+Alt+S]Save "exe" Build File.exe
I don't know why didn't start it after not reaction.
But,I see Window the background Process "File.exe" presence of.
File.exe the GUI not Show...

And...At this time,I Save CheatEngine the project,In addition, CheatEngine always throws an exception "Division by zero"



I am not found problem when save ct file as stand alone exe file. Using CTRL + ALT + S, then save as exe file. I am use CE Version 6.8.1
However, to save a CT Table as an exe file, check and considering some points :

1. Did you really need save your CT Table as an exe file ?
2. Did your codes / script are errors free ?
3. Did you created GUI form and it's components correctly ?
4. etc

Division by zero mean something or variables such as string, number, boelan, etc divide by zero ( 0 or nil ). This is math statement. Everything divide by zero will give resulr as infinity or error.

In case CE error message 'divide by zero' caused by many aspects, such as :

1. execute cheat table made use higher CE version using CE old version
2. Run lua script before editing CE Form
3. Scripts / Codes contain error(s)
4. etc

Try to solve :
go to start->programs->cheat engine 5.4->Reset settings
and then re-start CE

in lua script as example to descript divide by zero will give error, a function to detect zero div :

Code:
function div(a,b)
  quot = a/b
  if quot == 1/0 then error() end
  return quot
end

-- test
a = 10
b = 2
c = div(a,b)
print(c)    ---- result is : 5.0

a = 10
b = 0
c = div(a,b)
print(c)    ---- result is : error message 'undefined lua error'


Anyhow, why you aren't post your script here to show what are you trying to do and then let members on this forum to solve the problem ?.

Cheers

_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
Back to top
View user's profile Send private message
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