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 


function local value

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
Frouk
Master Cheater
Reputation: 5

Joined: 22 Jun 2021
Posts: 489
Location: mov dword ptr [Ukraine]

PostPosted: Mon Aug 30, 2021 7:07 am    Post subject: function local value Reply with quote

Code:
function new(minValue,maxValue,timer)

end

How to use those local values and set them into a value without calling function like this: function new(10,50)[/code]

_________________
void(__cdecl *Haxing)(HWND hGameWindow)
Back to top
View user's profile Send private message
LeFiXER
Grandmaster Cheater Supreme
Reputation: 20

Joined: 02 Sep 2011
Posts: 1053
Location: 0x90

PostPosted: Mon Aug 30, 2021 10:42 am    Post subject: Reply with quote

In the function declare the base value
Code:

function new(minValue,maxValue,timer)
  local minValue = 10
  local maxValue = 50
  ...
end
Back to top
View user's profile Send private message
Frouk
Master Cheater
Reputation: 5

Joined: 22 Jun 2021
Posts: 489
Location: mov dword ptr [Ukraine]

PostPosted: Mon Aug 30, 2021 10:45 am    Post subject: Reply with quote

can you give me an example of timer? (idk, how to create one if stored in function)
_________________
void(__cdecl *Haxing)(HWND hGameWindow)
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 457

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

PostPosted: Mon Aug 30, 2021 11:03 am    Post subject: This post has 1 review(s) Reply with quote

Code:

function startCounter(init)
  local uniqueToThisScript=init

  local repeatingTimer=createTimer(getApplication())
  repeatingTimer.Interval=10
  repeatingTimer.OnTimer=function(t)
    uniqueToThisScript=uniqueToThisScript+1
  end

  createTimer(2000,function(t)
    repeatingTimer.destroy()
    print("After 2 seconds the value is "..uniqueToThisScript)
  end)
end

startCounter(0)
startCounter(1000)

_________________
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
Frouk
Master Cheater
Reputation: 5

Joined: 22 Jun 2021
Posts: 489
Location: mov dword ptr [Ukraine]

PostPosted: Mon Aug 30, 2021 12:55 pm    Post subject: Reply with quote

Thanks LeFiXER and Dark Byte
_________________
void(__cdecl *Haxing)(HWND hGameWindow)
Back to top
View user's profile Send private message
LeFiXER
Grandmaster Cheater Supreme
Reputation: 20

Joined: 02 Sep 2011
Posts: 1053
Location: 0x90

PostPosted: Mon Aug 30, 2021 2:57 pm    Post subject: Reply with quote

You're welcome but I feel DB is more deserving of your gratitude as he was able to provide a better solution.
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 198

Joined: 25 Jan 2006
Posts: 8516
Location: 127.0.0.1

PostPosted: Tue Aug 31, 2021 1:26 am    Post subject: Reply with quote

If you are looking to do default values based on the params passed, you can do things like this as well:

Code:

local function new(minVal, maxVal, timer)
    minVal = minVal or 10;
    maxVal = maxVal or 50;

    print(string.format('min: %d, max: %d', minVal, maxVal));
end

new(100, 500);
new();

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
LeFiXER
Grandmaster Cheater Supreme
Reputation: 20

Joined: 02 Sep 2011
Posts: 1053
Location: 0x90

PostPosted: Tue Aug 31, 2021 2:54 am    Post subject: Reply with quote

I had not considered using logic to determine whether the values are different from pre-defined values. Thanks for the tip atom0s.
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
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