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 


Issue assign values to an object.

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
DaSpamer
Grandmaster Cheater Supreme
Reputation: 52

Joined: 13 Sep 2011
Posts: 1578

PostPosted: Mon Jan 26, 2015 5:11 pm    Post subject: Issue assign values to an object. Reply with quote

I'm trying to assign values to an object, but if I assign number, it'll convert to string, any idea why?

Code:
foo = {foo = {}};
local index = #foo.foo+1
local t = foo.foo;
t[index] = createForm();
t[index].asd = 100;
print(type(t[index].asd)) -- string.
foo.foo[1].bsd = 100;
print(type(foo.foo[1].bsd)) -- string.
print(type(foo.foo[1].height)) -- number.

_________________
HEY Hitler
Do you get lazy when making trainers?
Well no more!
My CETrainer will generate it for you in seconds, so you won't get lazy! Very Happy

http://forum.cheatengine.org/viewtopic.php?t=564919
Back to top
View user's profile Send private message
mgr.inz.Player
I post too much
Reputation: 218

Joined: 07 Nov 2008
Posts: 4438
Location: W kraju nad Wisla. UTC+01:00

PostPosted: Mon Jan 26, 2015 6:30 pm    Post subject: Reply with quote

Form object doesn't have "asd" property.


Solution:
Code:
createRef(...): integer - Returns an integer reference that you can use with getRef. Useful for objects that can only store integers and need to reference lua objects.  (Component.Tag...)
getRef(integer): ... - Returns whatever the reference points out
destroyRef(integer) - Removes the reference



Example:
Code:
foo = {foo = {}}
index = #foo.foo+1
t = foo.foo
t[index] = createForm()
t[index].Tag = createRef( { mytextproperty='yolo', myintegerproperty=15001} )



print(   type(  getRef(foo.foo[1].Tag).mytextproperty  )   ) -- string.
print(   type(  getRef(foo.foo[1].Tag).myintegerproperty  )   ) -- number.



-- add another property
getRef(foo.foo[1].Tag).anotherproperty = 'YES !'


print(   type(  getRef(foo.foo[1].Tag).anotherproperty  )   ) -- string.
print(          getRef(foo.foo[1].Tag).anotherproperty      ) -- YES !.

_________________


Last edited by mgr.inz.Player on Mon Jan 26, 2015 6:58 pm; edited 1 time in total
Back to top
View user's profile Send private message MSN Messenger
Dark Byte
Site Admin
Reputation: 457

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

PostPosted: Mon Jan 26, 2015 6:33 pm    Post subject: Reply with quote

try using tonumber

but keep in mind that these tags won't be part of the object, but only part of the current variable referencing the object. events called by this object will pass it an object without those tags

_________________
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
DaSpamer
Grandmaster Cheater Supreme
Reputation: 52

Joined: 13 Sep 2011
Posts: 1578

PostPosted: Mon Jan 26, 2015 7:47 pm    Post subject: Reply with quote

tonumber converts the values to a number, but those tags remain string.
(must use tonumber for compare).

And yes I know object the tags will not pass with the object (I'm accessing it via table).

But I wonder why number is being converted to string, without any way force it remain as a number.

_________________
HEY Hitler
Do you get lazy when making trainers?
Well no more!
My CETrainer will generate it for you in seconds, so you won't get lazy! Very Happy

http://forum.cheatengine.org/viewtopic.php?t=564919
Back to top
View user's profile Send private message
panraven
Grandmaster Cheater
Reputation: 54

Joined: 01 Oct 2008
Posts: 941

PostPosted: Mon Jan 26, 2015 8:59 pm    Post subject: This post has 1 review(s) Reply with quote

Try wrap the object (eg.control) with a table.
Code:
function wrap(o, ot)
  local w,mt = ot or {},{}
  mt.wrapped = o
  mt.__index = function(t,k)
    local b = mt.wrapped[k]
    if type(b) == 'boolean' or b then return b end
    return rawget(t,k)
  end
  mt.__newindex = function(t,k,v)
    local b = mt.wrapped[k]
    if type(b) == 'boolean' or b then mt.wrapped[k] = v else rawset(t,k,v) end
    return v
  end
  mt.__call = function() return mt.wrapped end -- return original object
  return setmetatable(w,mt)
end

-- test

local t = wrap(createForm(), {1,2,3,5})
t.asd = 111;
print(type(t.asd),t.asd) -- string --> number, 100
print(type(t.Height),t.Height) -- number, 240 - default
t.Height=100
t.Width=100
print(type(t.Height),t.Height) -- number, 100 - new set

for k,v in pairs(t) do print(k,tostring(v)) end -- table only property

local l = getPropertyList(t()) -- t() to get origianl object
if l ~= nil then
  local s = {}
  for i=0,l.Count-1 do s[1+#s]=l[i].."-"..tostring(t[l[i]]) end
  print(table.concat(s,"   \n"))
  l.destroy()
end

print(t.ClassName)
t.destroy()
print(t.asd)
print(t.ClassName, '<-- garbage after destroyed')
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