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 


Write a float value as integer

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
TPRammus
Advanced Cheater
Reputation: 0

Joined: 05 Jan 2016
Posts: 61
Location: Germany

PostPosted: Sat Jun 18, 2016 12:58 pm    Post subject: Write a float value as integer Reply with quote

Hey!

Can you write the (float) value of an address to a Label as an integer?
My Code is like that:

Code:
  local memrec=addresslist_getMemoryRecordByDescription(getAddressList(), "Time")
  local value=memoryrecord_getValue(memrec)
  control_setCaption(UDF1_CELabel2, value)
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 140

Joined: 06 Jul 2014
Posts: 4289

PostPosted: Sat Jun 18, 2016 1:11 pm    Post subject: Reply with quote

Code:
UDF1.CELabel2.Caption = getAddressList().getMemoryRecordByDescription("Time").Value:match("^%d+") or "0"

_________________
I don't know where I'm going, but I'll figure it out when I get there.
Back to top
View user's profile Send private message
TPRammus
Advanced Cheater
Reputation: 0

Joined: 05 Jan 2016
Posts: 61
Location: Germany

PostPosted: Sat Jun 18, 2016 4:16 pm    Post subject: Reply with quote

ParkourPenguin wrote:
Code:
UDF1.CELabel2.Caption = getAddressList().getMemoryRecordByDescription("Time").Value:match("^%d+") or "0"


Thank you for your answer.
Code:
.Value:match("^%d+")

So this converts a float into an integer?

And could you also do something like this?:
Code:
UDF1.CELabel2.Caption = getAddressList().getMemoryRecordByDescription("Time").Value:match("^%d+") or getAddressList().getMemoryRecordByDescription("TimeNrTwo").Value:match("^%d+")
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 140

Joined: 06 Jul 2014
Posts: 4289

PostPosted: Sat Jun 18, 2016 4:26 pm    Post subject: Reply with quote

No. The string.match function is used for taking one string (the value field) and finding a particular part of it that matches a specified pattern ("^%d+"). The or operator makes it such that if string.match didn't find anything that matches the pattern, it will just return 0. If that's the behavior you want, then go with what you wrote. If not, explain what you want.

Also, I forgot to include negative numbers with that pattern.
Code:
UDF1.CELabel2.Caption = getAddressList().getMemoryRecordByDescription("Time").Value:match("^-?%d+") or "0"
If you want to include NaN or +-Inf, make separate checks for that.
_________________
I don't know where I'm going, but I'll figure it out when I get there.
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