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 


Error with setting value of custom Lua type.

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine
View previous topic :: View next topic  
Author Message
TheyCallMeTim13
Wiki Contributor
Reputation: 51

Joined: 24 Feb 2017
Posts: 976
Location: Pluto

PostPosted: Sun Mar 25, 2018 9:53 am    Post subject: Error with setting value of custom Lua type. Reply with quote

Using the custom type below I only get an error when I try to set the value. Even after adding in the prints.

Quote:
Error:attempt to call a number value

Code:

local TypeName = 'Military Hours'
local ByteCount = 4
local IsFloat = true

local function bytesToValue( ... )
   local bytes = { ... }
   return ((byteTableToDword({ bytes[1], bytes[2], bytes[3], bytes[4] }) / (60 * 60)) * 100)
end
local function valueToBytes(value)
   ----
   print('valueToBytes')
   print(type(value), tostring(value))
   ----
   local bytes = dwordToByteTable((value * (60 * 60)) / 100)
   return bytes[1], bytes[2], bytes[3], bytes[4]
end

registerCustomTypeLua(TypeName, ByteCount, bytesToValue, valueToBytes, IsFloat)

_________________
Back to top
View user's profile Send private message Visit poster's website
ParkourPenguin
I post too much
Reputation: 150

Joined: 06 Jul 2014
Posts: 4657

PostPosted: Sun Mar 25, 2018 10:45 am    Post subject: Reply with quote

It's a CE bug. DB added an address parameter to valueToBytes and bytesToValue a while ago. In TCustomType.ConvertFloatToDataLua, the pcall to valueToBytes says there's one parameter when there's actually two. Ask DB to fix it.

In the meantime, use assembly.

Also, you're treating a float as an integer (probably not intended), but I'm sure you can figure out how to fix 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
TheyCallMeTim13
Wiki Contributor
Reputation: 51

Joined: 24 Feb 2017
Posts: 976
Location: Pluto

PostPosted: Sun Mar 25, 2018 11:50 am    Post subject: Reply with quote

ParkourPenguin wrote:
It's a CE bug. DB added an address parameter to valueToBytes and bytesToValue a while ago. In TCustomType.ConvertFloatToDataLua, the pcall to valueToBytes says there's one parameter when there's actually two. Ask DB to fix it.

In the meantime, use assembly....


I see. Thank you.

ParkourPenguin wrote:
...
Also, you're treating a float as an integer (probably not intended), but I'm sure you can figure out how to fix that.


It's an integer but I like CE to display it with decimal points (for the seconds), I did try it with the "isFloat" set to false but got the same error.

EDIT:
I guess I DIDN't try it with the "isFloat" set to false because I just tried it again and that works.

_________________
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine 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